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 #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);
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();
219 const std::string& get_name()
const {
return name_; }
220 void set_name(std::string name);
221 virtual std::string get_type_name()
const {
return "unknown object type"; }
229 void set_was_used(
bool tf)
const;
235 std::string get_string()
const {
236 std::ostringstream oss;
242 void ref()
const { ++count_; }
244 void release()
const;
245 #if IMP_KERNEL_HAS_LOG4CXX
246 const char* get_quoted_name_c_string()
const {
return quoted_name_.get(); }
250 static bool register_serialize(
const std::type_info &t, std::string name,
251 SaveFunc save_func, LoadFunc load_func);
254 void poly_serialize(cereal::BinaryOutputArchive &ar);
257 static Object *poly_unserialize(cereal::BinaryInputArchive &ar);
260 void _on_destruction();
263 bool get_is_valid()
const;
265 unsigned int get_ref_count()
const {
return count_; }
267 static unsigned int get_number_of_live_objects() {
return live_objects_; }
268 bool get_is_shared()
const {
return count_ > 1; }
269 #endif // IMP_DOXYGEN
281 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
283 IMP_CHECK_VARIABLE(l);
284 #if IMP_HAS_CHECKS != IMP_NONE
290 #if IMP_HAS_LOG == IMP_SILENT
297 #if IMP_HAS_CHECKS == IMP_NONE
304 inline void Object::set_was_used(
bool tf)
const {
305 IMP_CHECK_VARIABLE(tf);
306 #if IMP_HAS_CHECKS >= IMP_USAGE
311 inline bool Object::get_is_valid()
const {
312 #if IMP_HAS_CHECKS == IMP_NONE
315 return static_cast<int>(check_value_) == 111111111;
320 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
326 ShowFull(Object* o) {
327 std::ostringstream oss;
331 const std::string& get_string()
const {
return showed_; }
333 inline std::ostream& operator<<(std::ostream& o,
const ShowFull& sf) {
334 o << sf.get_string();
338 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.