Scopira  20080306
scopira::tool::object Class Reference

#include <object.h>

Inheritance diagram for scopira::tool::object:
scopira::agent::agent_i scopira::agent::agent_task_i scopira::agent::service_registrar scopira::basekit::narray_o< T, DIM > scopira::basekit::stringvector_o scopira::core::basic_loop scopira::core::model_i scopira::core::objecttype scopira::core::sidekick_i scopira::core::sidekick_queue_i scopira::core::view_i scopira::tool::destroy_reactor_i scopira::tool::dll scopira::tool::flow_i scopira::tool::iterator_imp_g< T > scopira::tool::job_i scopira::tool::job_i scopira::tool::nethostrec scopira::tool::objflowloader scopira::tool::property scopira::tool::rename_reactor_i scopira::tool::treenode scopira::tool::udpflow scopira::tool::update_reactor_i scopira::tool::xml_doc

Public Member Functions

virtual ~object ()
 
int add_ref (void) const
 
bool sub_ref (void) const
 
void auto_ref (void) const
 
int current_ref (void) const
 
virtual scopira::tool::oflow_iprint (scopira::tool::oflow_i &o) const
 
virtual bool load (scopira::tool::iobjflow_i &in)
 
virtual void save (scopira::tool::oobjflow_i &out) const
 
bool is_alive_object (void) const
 
bool is_dead_object (void) const
 

Protected Member Functions

 object (void)
 
 object (bool neverusecounter)
 

Detailed Description

Generic base class for many object types. The class is the common base class for many scopira classes. You may also use it for your own classes.

It provides (all optional services):

  • a reference counting mechanism (which you can then use manually, or use scopira::tool::count_ptr
  • a serialization interface
  • a print() function that will be called when the user wants to do human readable printing
  • validity testing with is_alive_object()

The Programmers Guide details information on how reference counting and serialization works.

See also
scopira::tool::count_ptr
Reference counting
Author
Aleksander Demko

Constructor & Destructor Documentation

◆ ~object()

virtual scopira::tool::object::~object ( )
virtual

Destructor

Author
Aleksander Demko

◆ object() [1/2]

scopira::tool::object::object ( void  )
protected

Default constructor

Author
Aleksander Demko

Referenced by is_dead_object().

◆ object() [2/2]

scopira::tool::object::object ( bool  neverusecounter)
explicitprotected

Alternate constructor.

If neverusecounter is true the object will never use the debug ref counting system, even if it's available.

This is primary for static/globabl objects that perhaps can live/die outside of the main()'s life span.

Passing false is the same as the default constructor: use it if it's available.

Author
Aleksander Demko

Member Function Documentation

◆ add_ref()

int scopira::tool::object::add_ref ( void  ) const

Adds a reference.

Returns the current reference count (always >=1, obviously)

Author
Aleksander Demko

Referenced by scopira::tool::objrefcounter::foo().

◆ auto_ref()

void scopira::tool::object::auto_ref ( void  ) const

Declares this object as an automatic (stack) variable and thus immune to the sub_ref induced destruction.

Author
Aleksander Demko

◆ current_ref()

int scopira::tool::object::current_ref ( void  ) const

Returns the current reference count.

Author
Aleksander Demko

◆ is_alive_object()

bool scopira::tool::object::is_alive_object ( void  ) const
inline

Is this object alive and valid? Calling this on a null this object is valid!

Author
Aleksander Demko

◆ is_dead_object()

bool scopira::tool::object::is_dead_object ( void  ) const
inline

Is this object valid but dead?

Author
Aleksander Demko

References object().

◆ load()

virtual bool scopira::tool::object::load ( scopira::tool::iobjflow_i in)
virtual

Serialization loader. Tells the object to load its state information from the given stream. object's load however, should not be called. It will assert failure if it is mistakenly called (which is often the base when one tries to serialize a class which lacks its own load method)

Parameters
inthe stream to load from
Returns
true on success
Author
Aleksander Demko

Reimplemented in scopira::basekit::narray_o< T, DIM >, scopira::core::model_i, scopira::core::project_base, scopira::tool::property_node, scopira::tool::property, and scopira::basekit::stringvector_o.

◆ print()

virtual scopira::tool::oflow_i& scopira::tool::object::print ( scopira::tool::oflow_i o) const
virtual

Pretty ASCII printer. Prints a representation of this object to the given stream.

Parameters
othe stream to write out to
Returns
the same stream
Author
Aleksander Demko

Reimplemented in scopira::tool::property_node, scopira::tool::property, and scopira::basekit::stringvector_o.

Referenced by scopira::tool::count_ptr< process_t >::print(), and scopira::tool::count2_ptr< scopira::tool::otflow_i >::print().

◆ save()

virtual void scopira::tool::object::save ( scopira::tool::oobjflow_i out) const
virtual

Serialization saver. Writes the object's state information to the given stream. object's save however, should not be called. It will assert failure if it is mistakenly called (which is often the base when one tries to serialize a class which lacks its own save method)

Parameters
outthe stream to write to
Author
Aleksander Demko

Reimplemented in scopira::basekit::narray_o< T, DIM >, scopira::core::model_i, scopira::core::project_base, scopira::tool::property_node, scopira::tool::property, and scopira::basekit::stringvector_o.

◆ sub_ref()

bool scopira::tool::object::sub_ref ( void  ) const

Removes a reference and deletes the object if need be.

Never call delete (or otherwise explicitly destruct and reference counted object)

Returns
true if the object was actully deleted from memory, false otherwise.
Author
Aleksander Demko

Referenced by scopira::tool::objrefcounter::foo().


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