Universal_AMOS.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 #include "Universal_AMOS.hh"
00011 using namespace AMOS;
00012 using namespace std;
00013 
00014 
00015 
00016 
00017 //================================================ Universal_t =================
00018 const NCode_t Universal_t::NCODE = M_UNIVERSAL;
00019 
00020 
00021 //----------------------------------------------------- readMessage ------------
00022 void Universal_t::readMessage (const Message_t & msg)
00023 {
00024   clear( ); // virtual func, will call child clear( )
00025 
00026   try {
00027     istringstream ss;
00028 
00029     if ( msg . exists (F_IID) )
00030       {
00031         ss . str (msg . getField (F_IID));
00032         ss >> iid_m;
00033         if ( !ss )
00034           AMOS_THROW_ARGUMENT ("Invalid iid format");
00035         ss . clear( );
00036       }
00037 
00038     if ( msg . exists (F_EID) )
00039       eid_m = msg . getField (F_EID);
00040 
00041     if ( msg . exists (F_STATUS) )
00042       {
00043         ss . str (msg . getField (F_STATUS));
00044         setStatus (ss . get( ));
00045         ss . clear( );
00046       }
00047 
00048     if ( msg . exists (F_COMMENT) )
00049       comment_m = msg . getField (F_COMMENT);
00050 
00051     if ( msg . exists (F_FLAG) )
00052       {
00053         char fA, fB;
00054         ss . str (msg . getField (F_FLAG));
00055         ss >> fA >> fB;
00056         setFlagA ( fA == '1' );
00057         setFlagB ( fB == '1' );
00058         if ( !ss )
00059           AMOS_THROW_ARGUMENT ("Invalid flag format");
00060         ss . clear( );
00061       }
00062   }
00063   catch (ArgumentException_t) {
00064     
00065     clear( );
00066     throw;
00067   }
00068 }
00069 
00070 
00071 //----------------------------------------------------- writeMessage -----------
00072 void Universal_t::writeMessage (Message_t & msg) const
00073 {
00074   msg . clear( );
00075 
00076   try {
00077     ostringstream ss;
00078 
00079     msg . setMessageCode (Universal_t::NCODE);
00080 
00081     if ( iid_m != NULL_ID )
00082       {
00083         ss << iid_m;
00084         msg . setField (F_IID, ss . str( ));
00085         ss . str (NULL_STRING);
00086       }
00087 
00088     if ( !eid_m . empty( ) )
00089       msg . setField (F_EID, eid_m);
00090 
00091     if ( status_m != NULL_STATUS )
00092       {
00093         ss << status_m;
00094         msg . setField (F_STATUS, ss . str( ));
00095         ss . str (NULL_STRING);
00096       }
00097 
00098     if ( !comment_m . empty( ) )
00099       msg . setField (F_COMMENT, comment_m);
00100 
00101     if ( isFlagA( )  ||  isFlagB( ) )
00102       {
00103         ss << isFlagA( ) << isFlagB( );
00104         msg . setField (F_FLAG, ss . str( ));
00105         ss . str (NULL_STRING);
00106       }
00107   }
00108   catch (ArgumentException_t) {
00109 
00110     msg . clear( );
00111     throw;
00112   }
00113 }

Generated on Mon Feb 22 17:36:27 2010 for libAMOS by  doxygen 1.4.7