Message_AMOS.hh

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #ifndef __Message_AMOS_HH
00012 #define __Message_AMOS_HH 1
00013 
00014 #include "utility_AMOS.hh"
00015 #include <string>
00016 #include <vector>
00017 #include <iostream>
00018 
00019 // Use a macro because OS X doesn't like/allow static members initialized
00020 // with actual code.
00021 #define AMOS_ENCODE(a,b,c) ((((c << CHAR_BIT) | b) << CHAR_BIT) | a)
00022 
00023 namespace AMOS {
00024 
00025 const char      E_ADD          = 'A';
00026 const char      E_DELETE       = 'D';
00027 const char      E_REPLACE      = 'R';
00028 const NCode_t   F_NULL         = AMOS_ENCODE ('n','u','l');
00029 const NCode_t   F_AHANG        = AMOS_ENCODE ('a','h','g');
00030 const NCode_t   F_ACTION       = AMOS_ENCODE ('a','c','t');
00031 const NCode_t   F_ADJACENCY    = AMOS_ENCODE ('a','d','j');
00032 const NCode_t   F_BASEPOSITION = AMOS_ENCODE ('b','c','p');
00033 const NCode_t   F_BHANG        = AMOS_ENCODE ('b','h','g');
00034 const NCode_t   F_BID          = AMOS_ENCODE ('b','i','d');
00035 const NCode_t   F_CLEAR        = AMOS_ENCODE ('c','l','r');
00036 const NCode_t   F_COMMENT      = AMOS_ENCODE ('c','o','m');
00037 const NCode_t   F_COUNT        = AMOS_ENCODE ('c','n','t');
00038 const NCode_t   F_EID          = AMOS_ENCODE ('e','i','d');
00039 const NCode_t   F_EDGE         = AMOS_ENCODE ('e','d','g');
00040 const NCode_t   F_FLAG         = AMOS_ENCODE ('f','l','g');
00041 const NCode_t   F_FRAGMENT     = AMOS_ENCODE ('f','r','g');
00042 const NCode_t   F_GAPS         = AMOS_ENCODE ('g','a','p');
00043 const NCode_t   F_IID          = AMOS_ENCODE ('i','i','d');
00044 const NCode_t   F_LIBRARY      = AMOS_ENCODE ('l','i','b');
00045 const NCode_t   F_LINK         = AMOS_ENCODE ('l','n','k');
00046 const NCode_t   F_MAP          = AMOS_ENCODE ('m','a','p');
00047 const NCode_t   F_MEAN         = AMOS_ENCODE ('m','e','a');
00048 const NCode_t   F_MEMBER       = AMOS_ENCODE ('m','b','r');
00049 const NCode_t   F_NODES        = AMOS_ENCODE ('n','d','s');
00050 const NCode_t   F_OBJECT       = AMOS_ENCODE ('o','b','j');
00051 const NCode_t   F_OFFSET       = AMOS_ENCODE ('o','f','f');
00052 const NCode_t   F_POSITION     = AMOS_ENCODE ('p','o','s');
00053 const NCode_t   F_QUALITY      = AMOS_ENCODE ('q','l','t');
00054 const NCode_t   F_QUALITYCLEAR = AMOS_ENCODE ('q','c','r');
00055 const NCode_t   F_READS        = AMOS_ENCODE ('r','d','s');
00056 const NCode_t   F_SCORE        = AMOS_ENCODE ('s','c','r');
00057 const NCode_t   F_SEQUENCE     = AMOS_ENCODE ('s','e','q');
00058 const NCode_t   F_SD           = AMOS_ENCODE ('s','t','d');
00059 const NCode_t   F_SIZE         = AMOS_ENCODE ('s','z','e');
00060 const NCode_t   F_SOURCE       = AMOS_ENCODE ('s','r','c');
00061 const NCode_t   F_STATUS       = AMOS_ENCODE ('s','t','s');
00062 const NCode_t   F_TYPE         = AMOS_ENCODE ('t','y','p');
00063 const NCode_t   F_VECTORCLEAR  = AMOS_ENCODE ('v','c','r');
00064 const NCode_t   M_NULL         = AMOS_ENCODE ('N','U','L');
00065 const NCode_t   M_UNIVERSAL    = AMOS_ENCODE ('U','N','V');
00066 const NCode_t   M_CONTIG       = AMOS_ENCODE ('C','T','G');
00067 const NCode_t   M_CONTIGEDGE   = AMOS_ENCODE ('C','T','E');
00068 const NCode_t   M_CONTIGLINK   = AMOS_ENCODE ('C','T','L');
00069 const NCode_t   M_DISTRIBUTION = AMOS_ENCODE ('D','S','T');
00070 const NCode_t   M_EDGE         = AMOS_ENCODE ('E','D','G');
00071 const NCode_t   M_FEATURE      = AMOS_ENCODE ('F','E','A');
00072 const NCode_t   M_FRAGMENT     = AMOS_ENCODE ('F','R','G');
00073 const NCode_t   M_GROUP        = AMOS_ENCODE ('G','R','P');
00074 const NCode_t   M_KMER         = AMOS_ENCODE ('K','M','R');
00075 const NCode_t   M_LAYOUT       = AMOS_ENCODE ('L','A','Y');
00076 const NCode_t   M_LIBRARY      = AMOS_ENCODE ('L','I','B');
00077 const NCode_t   M_LINK         = AMOS_ENCODE ('L','N','K');
00078 const NCode_t   M_IDMAP        = AMOS_ENCODE ('M','A','P');
00079 const NCode_t   M_INDEX        = AMOS_ENCODE ('I','D','X');
00080 const NCode_t   M_OVERLAP      = AMOS_ENCODE ('O','V','L');
00081 const NCode_t   M_READ         = AMOS_ENCODE ('R','E','D');
00082 const NCode_t   M_SCAFFOLD     = AMOS_ENCODE ('S','C','F');
00083 const NCode_t   M_SCAFFOLDEDGE = AMOS_ENCODE ('S','C','E');
00084 const NCode_t   M_SCAFFOLDLINK = AMOS_ENCODE ('S','C','L');
00085 const NCode_t   M_SEQUENCE     = AMOS_ENCODE ('S','E','Q');
00086 const NCode_t   M_TILE         = AMOS_ENCODE ('T','L','E');
00087 
00088 
00089 //================================================ Message_t ===================
00099 //==============================================================================
00100 class Message_t
00101 {
00102 
00103 private:
00104 
00105   NCode_t mcode_m;                            
00106   std::vector<Message_t> subs_m;              
00107   HASHMAP::hash_map<NCode_t,std::string> fields_m;     
00108 
00109 
00110 public:
00111 
00112   typedef HASHMAP::hash_map<NCode_t,std::string>::const_iterator const_iterator;
00113 
00114 
00115   //--------------------------------------------------- Message_t --------------
00118   Message_t ( )
00119   {
00120     mcode_m = M_NULL;
00121   }
00122 
00123 
00124   //--------------------------------------------------- ~Message_t -------------
00127   ~Message_t ( )
00128   {
00129 
00130   }
00131 
00132 
00133   //--------------------------------------------------- begin ------------------
00141   const_iterator begin ( ) const
00142   {
00143     return fields_m . begin( );
00144   }
00145 
00146 
00147   //--------------------------------------------------- end --------------------
00155   const_iterator end ( ) const
00156   {
00157     return fields_m . end( );
00158   }
00159 
00160 
00161   //--------------------------------------------------- clear ------------------
00166   void clear ( )
00167   {
00168     mcode_m = M_NULL;
00169     fields_m . clear( );
00170     subs_m . clear( );
00171   }
00172 
00173 
00174   //--------------------------------------------------- countFields ------------
00179   Size_t countFields ( ) const
00180   {
00181     return fields_m . size( );
00182   }
00183 
00184 
00185   //--------------------------------------------------- countSubMessages -------
00190   Size_t countSubMessages ( ) const
00191   {
00192     return subs_m . size( );
00193   }
00194 
00195 
00196   //--------------------------------------------------- empty ------------------
00201   bool empty ( ) const
00202   {
00203     return (fields_m . empty( ) && subs_m . empty( ));
00204   }
00205 
00206 
00207   //--------------------------------------------------- exists -----------------
00213   bool exists (NCode_t fcode) const
00214   {
00215     return fields_m . find (fcode) == fields_m . end( ) ? false : true;
00216   }
00217 
00218 
00219   //--------------------------------------------------- exists -----------------
00225   bool exists (const std::string & fname) const
00226   {
00227     return exists (Encode (fname));
00228   }
00229 
00230 
00231   //--------------------------------------------------- getField ---------------
00242   const std::string & getField (NCode_t fcode) const
00243   {
00244     HASHMAP::hash_map<NCode_t,std::string>::const_iterator
00245       mi = fields_m . find (fcode);
00246     if ( mi == fields_m . end( ) )
00247       AMOS_THROW_ARGUMENT
00248         ("Cannot retrieve absent field '" + Decode (fcode) + "'");
00249     return mi -> second;
00250   }
00251 
00252 
00253   //--------------------------------------------------- getField ---------------
00264   const std::string & getField (const std::string & fname) const
00265   {
00266     return getField (Encode (fname));
00267   }
00268 
00269 
00270   //--------------------------------------------------- getSubMessages ---------
00275   const std::vector<Message_t> & getSubMessages ( ) const
00276   {
00277     return subs_m;
00278   }
00279 
00280 
00281   //--------------------------------------------------- getSubMessages ---------
00286   std::vector<Message_t> & getSubMessages ( )
00287   {
00288     return subs_m;
00289   }
00290 
00291 
00292   //--------------------------------------------------- getMessageCode ---------
00300   NCode_t getMessageCode ( ) const
00301   {
00302     return mcode_m;
00303   }
00304 
00305 
00306   //--------------------------------------------------- operator[] -------------
00309   const std::string & operator[] (NCode_t fcode) const
00310   {
00311     return getField (fcode);
00312   }
00313 
00314   const std::string & operator[] (const std::string & fname) const
00315   {
00316     return getField (fname);
00317   }
00318   
00319 
00320   //--------------------------------------------------- read -------------------
00332   bool read (std::istream & in);
00333 
00334 
00335   //--------------------------------------------------- removeField ------------
00344   void removeField (NCode_t fcode)
00345   {
00346     fields_m . erase (fcode);
00347   }
00348 
00349 
00350   //--------------------------------------------------- removeField ------------
00359   void removeField (const std::string & fname)
00360   {
00361     removeField (Encode (fname));
00362   }
00363 
00364 
00365   //--------------------------------------------------- setSubMessages ---------
00371   void setSubMessages (const std::vector<Message_t> & subs)
00372   {
00373     subs_m = subs;
00374   }
00375 
00376 
00377   //--------------------------------------------------- setField ---------------
00391   void setField (NCode_t fcode, const std::string & data);
00392 
00393 
00394   //--------------------------------------------------- setField ---------------
00409   void setField (const std::string & fname, const std::string & data)
00410   {
00411     setField (Encode (fname), data);
00412   }
00413 
00414 
00415   //--------------------------------------------------- setMessageCode ---------
00421   void setMessageCode (NCode_t mcode)
00422   {
00423     mcode_m = mcode;
00424   }
00425 
00426 
00427   //--------------------------------------------------- setMessageCode ---------
00437   void setMessageCode (const std::string & mname)
00438   {
00439     setMessageCode (Encode (mname));
00440   }
00441 
00442 
00443   //--------------------------------------------------- skip -------------------
00458   static NCode_t skip (std::istream & in); // const
00459 
00460 
00461   //--------------------------------------------------- write ------------------
00473   void write (std::ostream & out) const;
00474 
00475 };
00476 
00477 
00478 
00479 
00480 
00481 //================================================ IMessagable_t ===============
00488 //==============================================================================
00489 class IMessagable_t
00490 {
00491 
00492 public:
00493 
00494   //--------------------------------------------------- IMessagable_t ----------
00497   IMessagable_t ( )
00498   {
00499 
00500   }
00501 
00502 
00503   //--------------------------------------------------- ~IMessagable_t ---------
00506   virtual ~IMessagable_t ( )
00507   {
00508 
00509   }
00510 
00511 
00512   //--------------------------------------------------- getNCode ---------------
00517   virtual NCode_t getNCode ( ) const = 0;
00518 
00519 
00520   //--------------------------------------------------- readMessage ------------
00533   virtual void readMessage (const Message_t & msg) = 0;
00534 
00535 
00536   //--------------------------------------------------- writeMessage -----------
00545   virtual void writeMessage (Message_t & msg) const = 0;
00546 
00547 };
00548 
00549 } // namespace AMOS
00550 
00551 #endif // #ifndef __Message_AMOS_HH

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