9#ifndef IMPKERNEL_OBJECT_H
10#define IMPKERNEL_OBJECT_H
12#include <IMP/kernel_config.h>
13#include <IMP/kernel_config.h>
26#include <boost/scoped_array.hpp>
27#include <cereal/access.hpp>
31#include <cereal/archives/binary.hpp>
33#if !defined(IMP_HAS_CHECKS)
34#error "IMP_HAS_CHECKS not defined, something is broken"
37#error "IMP_NONE not defined, something is broken"
39#if !defined(IMP_HAS_LOG)
40#error "IMP_HAS_LOG not defined, something is broken"
42#if !defined(IMP_SILENT)
43#error "IMP_SILENT not defined, something is broken"
46IMPKERNEL_BEGIN_NAMESPACE
111class IMPKERNELEXPORT
Object :
public NonCopyable {
113#if IMP_KERNEL_HAS_LOG4CXX
114 boost::scoped_array<char> quoted_name_;
117 static unsigned int live_objects_;
120#if IMP_HAS_LOG != IMP_NONE
124#if IMP_HAS_CHECKS >= IMP_USAGE
126 mutable bool was_owned_;
130#if IMP_HAS_CHECKS >= IMP_INTERNAL
131 static void add_live_object(
Object* o);
132 static void remove_live_object(
Object* o);
135 friend class cereal::access;
137 template<
class Archive>
void serialize(Archive &ar) {
139#if IMP_HAS_LOG != IMP_NONE
142#if IMP_HAS_CHECKS >= IMP_USAGE
143 ar(check_level_, was_owned_, check_value_);
145 if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
147 set_name_internal(name_);
151 void set_name_internal(std::string name);
153 void initialize(std::string name);
155 int compare(
const Object& o)
const {
164 typedef std::function<void(
Object *, cereal::BinaryOutputArchive &)> SaveFunc;
165 typedef std::function<
Object*(cereal::BinaryInputArchive &)> LoadFunc;
166 struct OutputSerializer {
167 std::string class_name;
171 static std::map<std::string, OutputSerializer> &get_output_serializers();
172 static std::map<std::string, LoadFunc> &get_input_serializers();
220 const std::string&
get_name()
const {
return name_; }
221 void set_name(std::string name);
222 virtual std::string get_type_name()
const {
return "unknown object type"; }
236 std::string get_string()
const {
237 std::ostringstream oss;
243 void ref()
const { ++count_; }
245 void release()
const;
246#if IMP_KERNEL_HAS_LOG4CXX
247 const char* get_quoted_name_c_string()
const {
return quoted_name_.get(); }
251 static bool register_serialize(
const std::type_info &t, std::string name,
252 SaveFunc save_func, LoadFunc load_func);
255 void poly_serialize(cereal::BinaryOutputArchive &ar);
258 static Object *poly_unserialize(cereal::BinaryInputArchive &ar);
261 void _on_destruction();
264 bool get_is_valid()
const;
266 unsigned int get_ref_count()
const {
return count_; }
268 static unsigned int get_number_of_live_objects() {
return live_objects_; }
269 bool get_is_shared()
const {
return count_ > 1; }
282#if !defined(SWIG) && !defined(IMP_DOXYGEN)
283inline void Object::set_check_level(CheckLevel l) {
284 IMP_CHECK_VARIABLE(l);
285#if IMP_HAS_CHECKS != IMP_NONE
290inline LogLevel Object::get_log_level()
const {
291#if IMP_HAS_LOG == IMP_SILENT
297inline CheckLevel Object::get_check_level()
const {
298#if IMP_HAS_CHECKS == IMP_NONE
305inline void Object::set_was_used(
bool tf)
const {
306 IMP_CHECK_VARIABLE(tf);
307#if IMP_HAS_CHECKS >= IMP_USAGE
312inline bool Object::get_is_valid()
const {
313#if IMP_HAS_CHECKS == IMP_NONE
316 return static_cast<int>(check_value_) == 111111111;
321#if !defined(IMP_DOXYGEN) && !defined(SWIG)
327 ShowFull(Object* o) {
328 std::ostringstream oss;
332 const std::string& get_string()
const {
return showed_; }
334inline std::ostream& operator<<(std::ostream& o,
const ShowFull& sf) {
335 o << sf.get_string();
339IMPKERNEL_END_NAMESPACE
Base class for all objects that cannot be copied.
Version and authorship of IMP objects.
virtual VersionInfo get_version_info() const
Get information about the module and version of the object.
void set_log_level(LogLevel l)
Set the logging level used in this object.
Object(std::string name)
Construct an object with the given name.
void set_check_level(CheckLevel l)
virtual void do_destroy()
const std::string & get_name() const
Get the (not necessarily unique) name of this object.
void set_was_used(bool tf) const
virtual void clear_caches()
Version and module information for Objects.
VersionInfo(std::string module, std::string version)
Create a VersionInfo object with the given module and version.
Basic enumeration types used by IMP.
Exception definitions and assertions.
Helper functions for implementing hashes.
Helper macros for implementing hashable classes.
#define IMP_HASHABLE_INLINE(name, hashret)
CheckLevel
Specify the level of runtime checks performed.
LogLevel
The log levels supported by IMP.
@ SILENT
Do not output any text.
Macros to help with reference counting.
Macros to help with objects that can be printed to a stream.
#define IMP_SHOWABLE(Name)
Various general useful macros for IMP.
Macros to control compiler warnings.