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"
36 #if !defined(IMP_NONE)
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"
46 IMPKERNEL_BEGIN_NAMESPACE
113 boost::scoped_array<char> quoted_name_;
115 static unsigned int live_objects_;
118 #if IMP_HAS_LOG != IMP_NONE
122 #if IMP_HAS_CHECKS >= IMP_USAGE
124 mutable bool was_owned_;
128 #if IMP_HAS_CHECKS >= IMP_INTERNAL
129 static void add_live_object(
Object* o);
130 static void remove_live_object(
Object* o);
133 friend class cereal::access;
135 template<
class Archive>
void serialize(Archive &ar) {
137 #if IMP_HAS_LOG != IMP_NONE
140 #if IMP_HAS_CHECKS >= IMP_USAGE
141 ar(check_level_, was_owned_, check_value_);
143 if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
145 set_name_internal(name_);
149 void set_name_internal(std::string name);
151 void initialize(std::string name);
162 typedef std::function<void(Object *, cereal::BinaryOutputArchive &)> SaveFunc;
163 typedef std::function<Object*(cereal::BinaryInputArchive &)> LoadFunc;
164 struct OutputSerializer {
165 std::string class_name;
169 static std::map<std::string, OutputSerializer> &get_output_serializers();
170 static std::map<std::string, LoadFunc> &get_input_serializers();
217 const std::string& get_name()
const {
return name_; }
218 void set_name(std::string name);
219 virtual std::string get_type_name()
const {
return "unknown object type"; }
227 void set_was_used(
bool tf)
const;
233 std::string get_string()
const {
234 std::ostringstream oss;
240 void ref()
const { ++count_; }
242 void release()
const;
243 const char* get_quoted_name_c_string()
const {
return quoted_name_.get(); }
246 static bool register_serialize(
const std::type_info &t, std::string name,
247 SaveFunc save_func, LoadFunc load_func);
250 void poly_serialize(cereal::BinaryOutputArchive &ar);
253 static Object *poly_unserialize(cereal::BinaryInputArchive &ar);
256 void _on_destruction();
259 bool get_is_valid()
const;
261 unsigned int get_ref_count()
const {
return count_; }
263 static unsigned int get_number_of_live_objects() {
return live_objects_; }
264 bool get_is_shared()
const {
return count_ > 1; }
265 #endif // IMP_DOXYGEN
277 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
279 IMP_CHECK_VARIABLE(l);
280 #if IMP_HAS_CHECKS != IMP_NONE
286 #if IMP_HAS_LOG == IMP_SILENT
293 #if IMP_HAS_CHECKS == IMP_NONE
300 inline void Object::set_was_used(
bool tf)
const {
301 IMP_CHECK_VARIABLE(tf);
302 #if IMP_HAS_CHECKS >= IMP_USAGE
307 inline bool Object::get_is_valid()
const {
308 #if IMP_HAS_CHECKS == IMP_NONE
311 return static_cast<int>(check_value_) == 111111111;
316 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
322 ShowFull(Object* o) {
323 std::ostringstream oss;
327 const std::string& get_string()
const {
return showed_; }
329 inline std::ostream& operator<<(std::ostream& o,
const ShowFull& sf) {
330 o << sf.get_string();
334 IMPKERNEL_END_NAMESPACE
Macros to help with reference counting.
CheckLevel get_check_level()
Get the current audit mode.
Base class for all objects that cannot be copied.
#define IMP_HASHABLE_INLINE(name, hashret)
Helper functions for implementing hashes.
LogLevel
The log levels supported by IMP.
#define IMP_SHOWABLE(Name)
virtual void clear_caches()
Exception definitions and assertions.
LogLevel get_log_level()
Get the currently active global log level.
Base class for all objects that cannot be copied.
virtual void do_destroy()
Common base class for heavy weight IMP objects.
Macros to control compiler warnings.
Helper macros for implementing hashable classes.
Various general useful macros for IMP.
Version and module information for Objects.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Basic enumeration types used by IMP.
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
void set_log_level(LogLevel l)
Set the current global log level.
CheckLevel
Specify the level of runtime checks performed.
virtual VersionInfo get_version_info() const
Get information about the module and version of the object.
Version and authorship of IMP objects.
Macros to help with objects that can be printed to a stream.
void set_check_level(CheckLevel tf)
Control runtime checks in the code.