IMP  2.2.1
The Integrative Modeling Platform
IMP::base::Object Class Reference

Common base class for heavy weight IMP objects. More...

#include <IMP/base/Object.h>

Inherits IMP::base::NonCopyable.

Inherited by IMP::algebra::DynamicNearestNeighbor3D, IMP::algebra::NearestNeighborD< D >, IMP::algebra::VectorKDMetric, IMP::atom::CHARMMResidueTopologyBase, IMP::atom::CHARMMSegmentTopology, IMP::atom::CHARMMTopology, IMP::atom::ForceFieldParameters, IMP::atom::Mol2Selector, IMP::atom::PDBSelector, IMP::atom::SmoothingFunction, IMP::core::ClosePairsFinder, IMP::core::DataObject< Data >, IMP::display::Geometry, IMP::display::Writer, IMP::domino::AssignmentContainer, IMP::domino::AssignmentsTable, IMP::domino::ParticleStates, IMP::domino::ParticleStatesTable, IMP::domino::RestraintCache, IMP::domino::SubsetFilter, IMP::domino::SubsetFilterTable, IMP::em2d::CollisionCrossSection, IMP::em2d::Image, IMP::em2d::ImageReaderWriter, IMP::em2d::ProjectionFinder, IMP::em2d::ScoreFunction, IMP::em::CoarseCC, IMP::em::DensityMap, IMP::em::EnvelopeScore, IMP::em::MapReaderWriter, IMP::em::PCAAligner, IMP::example::ExampleObject, IMP::isd::BivariateFunction, IMP::isd::CrossLinkData, IMP::isd::CysteineCrossLinkData, IMP::isd::FNormal, IMP::isd::FretData, IMP::isd::GaussianProcessInterpolation, IMP::isd::MultivariateFNormalSufficient, IMP::isd::UnivariateFunction, IMP::isd::vonMises, IMP::isd::vonMisesSufficient, IMP::kernel::Configuration, IMP::kernel::ConfigurationSet, IMP::kernel::Model, IMP::kernel::ModelObject, IMP::kernel::PairModifier, IMP::kernel::PairPredicate, IMP::kernel::PairScore, IMP::kernel::QuadModifier, IMP::kernel::QuadPredicate, IMP::kernel::QuadScore, IMP::kernel::Refiner, IMP::kernel::Sampler, IMP::kernel::SingletonModifier, IMP::kernel::SingletonPredicate, IMP::kernel::SingletonScore, IMP::kernel::TripletModifier, IMP::kernel::TripletPredicate, IMP::kernel::TripletScore, IMP::kernel::UnaryFunction, IMP::kernel::Undecorator, IMP::kinematics::DOF, IMP::kinematics::DOFsSampler, IMP::kinematics::Joint, IMP::kinematics::KinematicForest, IMP::kinematics::LocalPlanner, IMP::kmeans::KMeans, IMP::mpi::ReplicaExchange, IMP::multifit::AssemblyHeader, IMP::multifit::ComponentHeader, IMP::multifit::Ensemble, IMP::multifit::FFTFitting, IMP::multifit::FFTFittingOutput, IMP::multifit::ProbabilisticAnchorGraph, IMP::multifit::ProteomicsData, IMP::multifit::ProteomicsEMAlignmentAtomic, IMP::multifit::SettingsData, IMP::rmf::LoadLink, IMP::rmf::SaveLink, IMP::rotamer::RotamerCalculator, IMP::rotamer::RotamerLibrary, IMP::saxs::DerivativeCalculator, IMP::saxs::Profile, IMP::saxs::ProfileFitter< ScoringFunctionT >, IMP::saxs::RigidBodiesProfileHandler, IMP::statistics::Embedding, IMP::statistics::Metric, IMP::statistics::PartitionalClustering, log.DummyObject, and IMP::saxs::ProfileFitter< ChiScore >.

Public Member Functions

virtual void clear_caches ()
 
virtual void do_destroy ()
 
CheckLevel get_check_level () const
 
LogLevel get_log_level () const
 
virtual VersionInfo get_version_info () const
 Get information about the module and version of the object.
 
void set_check_level (CheckLevel l)
 
void set_log_level (LogLevel l)
 Set the logging level used in this object. More...
 
void set_was_used (bool tf) const
 
void show (std::ostream &out=std::cout) const
 

Protected Member Functions

 Object (std::string name)
 Construct an object with the given name. More...
 

Names

All objects have names to aid in debugging and inspection of the state of the system. These names are not necessarily unique and should not be used to store data or as keys into a table. Use the address of the object instead since objects cannot be copied.

const std::string & get_name () const
 
void set_name (std::string name)
 
virtual std::string get_type_name () const
 

Detailed Description

The base class for non value-type classes in IMP. Anything inheriting from Object has the following properties:

  • has embedded information about the module and version which can be accessed using Object::get_version_info(). This information can be used to log what version of software is used to compute a result.
  • it has a local logging level which can override the global one allowing fine grained logging control.
  • in python, there is a method Class::get_from(Object *o) that attempts to case o to an object of type Class and throws and exception if it fails.
  • the object keeps track of whether it has been been used. See the Object::set_was_used() method for an explanation.
  • It is reference counted

Types inheriting from Object should always be created using new in C++ and passed using pointers and stored using Pointer objects. Note that you have to be careful of cycles and so must use WeakPointer objects to break cycles. IMP_NEW() can help shorten creating a ref counted pointer. See Pointer for more information.

See example::ExampleObject for a simple example.

Reference counting is a technique for managing memory and automatically freeing memory (destroying objects) when it is no longer needed. In reference counting, each object has a reference count, which tracks how many different places are using the object. When this count goes to 0, the object is freed.

Python internally refence counts everything. C++, on the other hand, requires extra steps be taken to ensure that objects are reference counted properly.

In IMP, reference counting is done through the Pointer, PointerMember and Object classes. The former should be used instead of a raw C++ pointer when storing a pointer to any object inheriting from Object.

Any time one is using reference counting, one needs to be aware of cycles, since if, for example, object A contains an IMP::Pointer to object B and object B contains an Pointer to object A, their reference counts will never go to 0 even if both A and B are no longer used. To avoid this, use an WeakPointer in one of A or B.

Functions that create new objects should follow the following pattern

  ObjectType *create_object(arguments) {
     IMP_NEW(ObjectType, ret, (args));
     do_stuff;
     return ret.release();
   }

using Pointer::release() to safely return the new object without freeing it.

Definition at line 106 of file base/Object.h.

Constructor & Destructor Documentation

IMP::base::Object::Object ( std::string  name)
protected

An instance of "%1%" in the string will be replaced by a unique index.

Member Function Documentation

virtual void IMP::base::Object::clear_caches ( )
virtual

Objects can have internal caches. This method resets them returning the object to its just-initialized state.

Reimplemented in IMP::core::ExcludedVolumeRestraint, and IMP::core::MinimumRestraint.

Definition at line 227 of file base/Object.h.

virtual void IMP::base::Object::do_destroy ( )
virtual

Overide this method to take action on destruction.

Reimplemented in IMP::display::PymolWriter, and IMP::display::ChimeraWriter.

Definition at line 230 of file base/Object.h.

void IMP::base::Object::set_check_level ( CheckLevel  l)

Each object can be assigned a different check level too.

void IMP::base::Object::set_log_level ( LogLevel  l)

Each object can be assigned a different log level in order to, for example, suppress messages for verbose and uninteresting objects. If set to DEFAULT, the global level as returned by IMP::get_log_level() is used, otherwise the local one is used. Methods in classes inheriting from Object should start with IMP_OBJECT_LOG to change the log level to the local one for this object and increase the current indent.

See Also
IMP::base::set_log_level()
IMP::base::get_log_level()
void IMP::base::Object::set_was_used ( bool  tf) const

IMP provides warnings when objects are never used before they are destroyed. Examples of use include adding an IMP::Restraint to an IMP::kernel::Model. If an object is not properly marked as used, or your code is the one using it, call set_was_used(true) on the object.


The documentation for this class was generated from the following file: