Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MynahSA::Archive Class Reference

#include <archive.hpp>

Inheritance diagram for MynahSA::Archive:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 Archive ()
 constructor
 Archive (const Archive &ar)
 copy constructor - copy constructor functions
 Archive (const std::map< std::string, SHARED_PTR< Archive::ArchiveConstructor > > &cons)
 construct with a pre-existing map of constructor functions
virtual ~Archive ()
 virtual destructor
void registerConstructor (const std::string &name, const SHARED_PTR< ArchiveConstructor > &cons)
const std::map< std::string,
SHARED_PTR< ArchiveConstructor > > & 
getConstructors () const
 provide external access to constructor functions
virtual Archiveoperator & (long long &)=0
 archive long long
virtual Archiveoperator & (unsigned long long &)=0
 archive unsigned long long
virtual Archiveoperator & (unsigned int &)=0
 archive unsigned int
virtual Archiveoperator & (int &)=0
 archive int
virtual Archiveoperator & (short &)=0
 archive short
virtual Archiveoperator & (unsigned short &)=0
 archvie ushort
virtual Archiveoperator & (char &)=0
 archive char
virtual Archiveoperator & (unsigned char &)=0
 archive unsigned char
virtual Archiveoperator & (bool &)=0
 archive bool
virtual Archiveoperator & (float &)=0
 archive float
virtual Archiveoperator & (double &)=0
 archive double
virtual Archiveoperator & (std::string &)=0
 archive std::string
template<class T>
Archiveoperator & (std::vector< T > &v)
 archive a std::vector
template<class T>
Archiveoperator & (std::list< T > &l)
 archive a std::list
template<class a_type, class b_type>
Archiveoperator & (std::pair< a_type, b_type > &p)
 Archive a std::pair.
template<class value_type>
Archiveoperator & (std::set< value_type > &s)
 archive a std::map - store indicies and data
template<class index_type, class value_type>
Archiveoperator & (std::map< index_type, value_type > &m)
 archive a std::map - store indicies and data
template<class index_type, class value_type>
Archiveoperator & (std::multimap< index_type, value_type > &m)
 archive a std::map - store indicies and data
template<class T>
Archiveoperator & (SHARED_PTR< T > &ptr)
template<class T>
Archiveoperator & (T &x)
void clearUPR ()
template<class T>
void touchPtr (const SHARED_PTR< T > &ptr)

Protected Types

enum  ArchiveMode

Protected Member Functions

virtual ArchiveMode getArchiveMode () const =0

Classes

class  ArchiveConstructor

Detailed Description

Archive is a pure base for classes IArchive and OArchive for input and output respectively.

Definition at line 43 of file archive.hpp.


Member Function Documentation

void MynahSA::Archive::clearUPR  ) 
 

clearUPR - remove all unique pointer references from the archive, and free any associated memory by removing dangling SHARED_PTRs. This method servers an important purpose: When objects are serialized by SHARED_PTR, Archive holds a copy of the shared pointer. This is necessary s.t. multiple pointers to the same object do not cause multiple object to be transmitted. clearUPR must be called to free all such references.

To make this explicit, here are two code sequences with explaination of what is being transmitted:

    Archive& archive;  // some non-pure derivitive of MynahSA::Archive
    SHARED_PTR<ObjectType> sp1; // a shared pointer to a real instance
    archive << sp1;                 // transmit sp1
    archive << sp1;                 // transmit sp1
  
This sequence causes the following information to be transmitted on the stream: [shared_pointer to ObjectType [(*sp1) details]] [unique pointer reference to sp1] whereas, this code sequence:
    Archive& archive;  // some non-pure derivitive of MynahSA::Archive
    SHARED_PTR<ObjectType> sp1; // a shared pointer to a real instance
    archive << sp1;                 // transmit sp1
    archive.clearUPR();             // remove all unique pointer references
    archive << sp1;                 // transmit sp1
  
caues the following to be emitted on the stream: [shared_pointer to ObjectType [(*sp1) details]] [shared_pointer to ObjectType [(*sp1) details]]

Reimplemented in MynahSA::SSLArchiveStream, and MynahSA::TCPArchiveStream.

virtual ArchiveMode MynahSA::Archive::getArchiveMode  )  const [protected, pure virtual]
 

return the archive mode - reader or writer. This is necessary for archiving certain STL types

Implemented in MynahSA::IArchive< T >, MynahSA::OArchive< T >, MynahSA::IArchive< ISSLStream >, MynahSA::IArchive< ITCPStream >, MynahSA::OArchive< OTCPStream >, and MynahSA::OArchive< OSSLStream >.

Referenced by operator &().

template<class T>
Archive& MynahSA::Archive::operator & T &  x  )  [inline]
 

A template class handler - objects must be either enum type (as identified by is_enum , or provide a serialize method

Note:
archiving of array types is supported on gcc, and Microsoft VC++ 2003+ using the following template:
  ar & arrayType;   // where ar is an archive instance

on SUNpro 5.8 the compiler cannot differentiate the use of operator& and the "address of" operator. Therefore, the following code fragment must be used:

  ar.operator&(arrayType);

Definition at line 344 of file archive.hpp.

00344                              {
00345       // a bit of template meta-programming, 
00346       serializeArray(x, MynahSA::array_t<T>());
00347       return *this;
00348     }

template<class T>
Archive& MynahSA::Archive::operator & SHARED_PTR< T > &  ptr  )  [inline]
 

Archive operator& for shared pointer types. Note that this code path is forked depending on whether or not the type being serialized is a fundamental type (fundamental_t) e.g. int, char, etc... or a complex type. Complex types must derive from class IoBase;

Definition at line 322 of file archive.hpp.

00322                                            { 
00323       return archiveSP(ptr, fundamental_t<T>());
00324     }

void MynahSA::Archive::registerConstructor const std::string &  name,
const SHARED_PTR< ArchiveConstructor > &  cons
[inline]
 

register a constructor object with this iarchive instance - this is necessary for restoration of objects pointed to by shared pointers.

Note: Ownership of the IArchiveConstructor is taken by this class.

Reimplemented in MynahSA::SSLArchiveStream, and MynahSA::TCPArchiveStream.

Definition at line 83 of file archive.hpp.

00083                                                                                                 {
00084       _constructors[name] = cons;
00085     }

template<class T>
void MynahSA::Archive::touchPtr const SHARED_PTR< T > &  ptr  )  [inline]
 

touch a pointer - this indicates to the archiver that it should place a real pointer onto the stream and not a pointer reference.

Definition at line 387 of file archive.hpp.

00387                                             { 
00388       SHARED_PTR<void> value(STATIC_PTR_CAST<void>(ptr)); // fetch pointer value
00389       std::map<SHARED_PTR<void>, unsigned int>::iterator mit = _ptrToUPR.find(value);  // find its universal pointer value
00390       if (mit != _ptrToUPR.end()) { 
00391         unsigned int upr = (*mit).second;
00392         _ptrToUPR.erase(mit);  // get rid of the upr and pointer associated
00393         std::map<unsigned int, SHARED_PTR<void> >::iterator mit2 = _uprToPtr.find(upr);
00394         if (mit2 != _uprToPtr.end()) {
00395           _uprToPtr.erase(mit2);
00396         }
00397       }
00398     }


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