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

# Tools/Streams/StreamHandler.cpp

Go to the documentation of this file.

    00001 #include "Tools/Streams/StreamHandler.h"
    00002
    00003 using namespace std;
    00004
    00005
    00006 #include "Tools/Process.h"
    00007
    00008 void StreamHandler::startRegistration(const char* name, bool registerWithExternalOperator)
    00009 {
    00010   if(registeringBase)
    00011   {
    00012     currentRegisteringEntryStack.top().second.baseClass = true;
    00013   }
    00014   else
    00015   {
    00016     hash_map<const char*, std::vector<std::pair< std::string, const char*> > >::iterator currentlyRegisteringEntry;
    00017     currentlyRegisteringEntry = specification.find( name);
    00018     if(currentlyRegisteringEntry == specification.end())
    00019     {
    00020        specification[name];
    00021        RegisteringAttributes attr;
    00022        attr.registering = true;
    00023        attr.baseClass = false;
    00024        attr.externalOperator = registerWithExternalOperator;
    00025        std::pair< hash_map<const char*, std::vector<std::pair< std::string, const char*> > >::iterator, RegisteringAttributes> stackEntry(specification.find( name), attr);
    00026        currentRegisteringEntryStack.push( stackEntry);
    00027        registering = true;
    00028     }
    00029     else
    00030     {
    00031       RegisteringAttributes attr;
    00032       attr.registering = false;
    00033        attr.baseClass = false;
    00034        attr.externalOperator = registerWithExternalOperator;
    00035       std::pair< hash_map<const char*, std::vector<std::pair< std::string, const char*> > >::iterator, RegisteringAttributes> stackEntry(currentlyRegisteringEntry, attr);
    00036       currentRegisteringEntryStack.push( stackEntry);
    00037       registering = false;
    00038     }
    00039   }
    00040   registeringBase = false;
    00041 }
    00042
    00043 Out& operator<<(Out& out, const StreamHandler& streamHandler)
    00044 {
    00045   // basic types
    00046   out << streamHandler.basicTypeSpecification.size();;
    00047   hash_map<const char*, const char*>::const_iterator basicTypeIter = streamHandler.basicTypeSpecification.begin();
    00048   for ( ; basicTypeIter != streamHandler.basicTypeSpecification.end(); ++basicTypeIter )
    00049   {
    00050     out << basicTypeIter->first;
    00051     out << basicTypeIter->second;
    00052
    00053   }
    00054
    00055   // specification
    00056   out << streamHandler.specification.size();;
    00057   hash_map<const char*, std::vector<std::pair< std::string, const char*> > >::const_iterator specificationIter = streamHandler.specification.begin();
    00058   for ( ; specificationIter != streamHandler.specification.end(); ++specificationIter)
    00059   {
    00060     out << specificationIter->first;
    00061     out << specificationIter->second.size();
    00062
    00063     std::vector<std::pair< std::string, const char*> >::const_iterator typeNamePairIter = specificationIter->second.begin();
    00064     for(; typeNamePairIter != specificationIter->second.end(); ++ typeNamePairIter)
    00065     {
    00066       out << typeNamePairIter->first.c_str();
    00067       out << typeNamePairIter->second;
    00068     }
    00069   }
    00070
    00071   // enum specification
    00072   out << streamHandler.enumSpecification.size();;
    00073   hash_map<const char*, std::vector<const char*> >::const_iterator enumSpecificationIter = streamHandler.enumSpecification.begin();
    00074   for ( ; enumSpecificationIter != streamHandler.enumSpecification.end(); ++enumSpecificationIter)
    00075   {
    00076     out << enumSpecificationIter->first;
    00077     out << enumSpecificationIter->second.size();
    00078
    00079     std::vector<const char*>::const_iterator enumElementsIter = enumSpecificationIter->second.begin();
    00080     for(; enumElementsIter != enumSpecificationIter->second.end(); ++ enumElementsIter)
    00081     {
    00082       out << *enumElementsIter;
    00083     }
    00084   }
    00085
    00086   return out;
    00087 }
    00088
    00089 /** references to StreamHandler */
    00090 GT_GLOBAL StreamHandler* streamHandler;
    00091 void initStreamHandler(StreamHandler* streamHandlerPtr)
    00092 {
    00093   streamHandler = streamHandlerPtr;
    00094 }
    00095
    00096 StreamHandler& getStreamHandler()
    00097 {
    00098   return *streamHandler;
    00099 }
    00100
    00101 In& operator>>(In& in, bool& inBool)
    00102 {
    00103   int temp;
    00104   in >> temp;
    00105   inBool = (temp != 0);
    00106   return in;
    00107 }
    00108
    00109 Out& operator<<(Out& out, bool& outBool)
    00110 {
    00111     out << (int)outBool;
    00112     return out;
    00113 }
    00114
    00115