Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

NML.h

Go to the documentation of this file.
00001 /* 
00002  *
00003  * This file is part of the 'NewsService Journaline(R) Decoder'
00004  * 
00005  * Copyright (c) 2003, 2004 by Fraunhofer IIS, Erlangen, Germany
00006  * 
00007  * --------------------------------------------------------------------
00008  * 
00009  * For NON-COMMERCIAL USE,
00010  * the 'NewsService Journaline(R) Decoder' is free software;
00011  * you can redistribute it and/or modify it under the terms of
00012  * the GNU General Public License as published by the
00013  * Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  * 
00016  * The 'NewsService Journaline(R) Decoder' is distributed in the hope
00017  * that it will be useful, but WITHOUT ANY WARRANTY;
00018  * without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  * 
00022  * You should have received a copy of the GNU General Public License
00023  * along with the 'NewsService Journaline(R) Decoder';
00024  * if not, write to the Free Software Foundation, Inc.,
00025  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  * 
00027  * 
00028  * If you use this software in a project with user interaction, please
00029  * provide the following text to the user in an appropriate place:
00030  * "Features NewsService Journaline(R) decoder technology by
00031  * Fraunhofer IIS, Erlangen, Germany.
00032  * For more information visit http://www.iis.fhg.de/dab"
00033  * 
00034  * --------------------------------------------------------------------
00035  * 
00036  * To use the 'NewsService Journaline(R) Decoder' software for
00037  * COMMERCIAL purposes, please contact Fraunhofer IIS for a
00038  * commercial license (see below for contact information)!
00039  * 
00040  * --------------------------------------------------------------------
00041  * 
00042  * Contact:
00043  *   Fraunhofer IIS, Department 'Broadcast Applications'
00044  *   Am Wolfsmantel 33, 91058 Erlangen, Germany
00045  *   http://www.iis.fraunhofer.de/dab
00046  *   mailto:bc-info@iis.fraunhofer.de
00047  * 
00048  */
00049 
00068 
00069 
00070 #ifndef _NML_H_
00071 #define _NML_H_
00072 
00073 
00074 #ifdef WIN32
00075 #pragma warning(push,3)
00076 #pragma warning(disable:4018)
00077 #pragma warning(disable:4100)
00078 #pragma warning(disable:4514)
00079 #pragma warning(disable:4786)
00080 #endif
00081 
00082 #include <string>
00083 #include <vector>
00084 #include <ios>
00085 
00086 #ifdef WIN32
00087 #pragma warning(pop)
00088 #pragma warning(disable:4786)
00089 #pragma warning(disable:4514)
00090 #endif
00091 
00092 // utility functions
00093 std::string HexDump(const unsigned char *p,
00094                     unsigned int len,
00095                     unsigned int bytes_per_line = 16);
00096 std::string HexDump(const char *p,
00097                     unsigned int len,
00098                     unsigned int bytes_per_line = 16);
00099 
00100 
00101 
00103 class NMLEscapeCodeHandler
00104 {
00105  public:
00106   virtual bool Convert(std::string & dest,
00107                        const std::string & src) const = 0;
00108 };
00109 
00110 
00112 class RemoveNMLEscapeSequences : public NMLEscapeCodeHandler
00113 {
00114  public:
00115   RemoveNMLEscapeSequences();
00116   virtual ~RemoveNMLEscapeSequences();
00117 
00118   bool Convert(std::string & dest,
00119                const std::string & src) const;
00120 };
00121 
00122 
00124 class NMLEscapeSequences2HTML : public NMLEscapeCodeHandler
00125 {
00126  public:
00127   NMLEscapeSequences2HTML();
00128   virtual ~NMLEscapeSequences2HTML();
00129 
00130   bool Convert(std::string & dest,
00131                const std::string & src) const;
00132 };
00133 
00134 
00135 
00137 class NML
00138 {
00139   friend class NMLFactory;
00140 
00141  public:
00142   //-------------------- constants --------------------
00143   static const unsigned int NML_MAX_LEN;
00144   static const unsigned int NML_MAX_NR_OF_LEVELS;
00145   static const unsigned int NML_MAX_NR_OF_MENU_ITEMS;
00146   static const unsigned int MAX_NR_OF_WATCHES;
00147   static const unsigned int NML_MIN_NR_OF_ITEM_BYTES;
00148   static const unsigned int NML_NR_OF_HEADER_BYTES;
00149   static const unsigned short ROOT_OBJECT_ID;
00150   static const char *ObjectTypeString[];
00151 
00152   //-------------------- types ------------------------
00153 
00155   typedef enum {INVALID, MENU, PLAIN, TITLE, LIST} object_type_t;
00156 
00158   typedef unsigned short NewsObjectId_t;
00159 
00161   typedef struct
00162   {
00163     unsigned short nml_len;             
00164     unsigned short extended_header_len; 
00165     unsigned char nml[2048];            
00166   } RawNewsObject_t;
00167 
00169   typedef struct
00170   {
00171     std::string text;       
00172     unsigned short link_id; 
00173     bool link_id_available; 
00174   } Item_t;
00175 
00177   typedef struct
00178   {
00179     NewsObjectId_t object_id;     
00180     object_type_t object_type;    
00181     bool static_flag;             
00182     unsigned char revision_index; 
00183     std::string extended_header;  
00184     std::string title;            
00185     std::vector<Item_t> item;     
00186   } News_t;
00187 
00188   //-------------------- lifetime --------------------
00189   NML();
00190   NML(const NML & prototype);
00191   ~NML();
00192 
00193   //-------------------- operators --------------------
00194   const NML & operator=(const NML & prototype);
00195   bool operator==(const NML & prototype) const;
00196   std::ostream & operator<<(std::ostream & os) const;
00197 
00198   //-------------------- inquiry methods --------------
00199   std::string Dump(void) const;
00200 
00203   inline bool           isValid(void) const
00204   {
00205     return _valid;
00206   }
00207 
00210   inline bool           isRootObject(void) const
00211   {
00212     return (GetObjectId()==ROOT_OBJECT_ID);
00213   }
00214 
00217   inline bool           isMenu(void) const
00218   {
00219     return (GetObjectType()==MENU);
00220   }
00221 
00224   inline bool           isStatic(void) const
00225   {
00226     return _news.static_flag;
00227   }
00228 
00231   inline object_type_t  GetObjectType(void) const
00232   {
00233     return _news.object_type;
00234   }
00235 
00238   inline const char *GetObjectTypeString(void) const
00239   {
00240     if (_news.object_type<=LIST)
00241     {
00242       return NML::ObjectTypeString[_news.object_type];
00243     }
00244     else
00245     {
00246       return "illegal";
00247     }
00248   }
00249 
00252   inline NewsObjectId_t GetObjectId(void) const
00253   {
00254     return _news.object_id;
00255   }
00256 
00259   inline unsigned char  GetRevisionIndex(void) const
00260   {
00261     return _news.revision_index;
00262   }
00263   
00266   inline std::string    GetExtendedHeader(void) const
00267   {
00268     return _news.extended_header;
00269   }
00270 
00273   inline std::string    GetTitle(void) const
00274   {
00275     return _news.title;
00276   }
00277 
00280   inline unsigned int   GetNrOfItems(void) const
00281   {
00282     return _news.item.size();
00283   }
00284 
00287   inline const std::vector<Item_t> & GetItems(void) const
00288   {
00289     return _news.item;
00290   }
00291 
00294   inline std::string     GetItemText(unsigned int i) const
00295   {
00296     return (i<GetNrOfItems())?_news.item[i].text:""; 
00297   }
00298 
00304   inline NewsObjectId_t  GetLinkId(unsigned int i) const
00305   {
00306     if (i>=GetNrOfItems()) return 0x0815;
00307     return _news.item[i].link_id;
00308   }
00309 
00313   inline bool            isLinkIdAvailable(unsigned int i) const
00314   {
00315     return (i<GetNrOfItems()) ? _news.item[i].link_id_available : false;
00316   }
00317 
00318   //-------------------- modifier methods -------------
00319 
00322   inline void SetObjectId(NewsObjectId_t oid)
00323   {
00324     _news.object_id = oid;
00325   }
00326 
00330   inline void SetLinkAvailability(unsigned int i, bool f)
00331   {
00332     if (isMenu() && (i<GetNrOfItems()))
00333       _news.item[i].link_id_available = f;
00334   }
00335 
00336   void SetError(NewsObjectId_t oid, const char *title);
00337   void SetErrorDump(NewsObjectId_t oid,
00338                     const RawNewsObject_t & rno,
00339                     const char *error_msg);
00340 
00341  private:
00342   bool _valid;
00343   News_t _news;
00344   NMLEscapeCodeHandler *_EscapeCodeHandler;
00345 };
00346 
00347 bool operator==(const NML::Item_t &, const NML::Item_t &);
00348 std::string DumpRaw(const NML::RawNewsObject_t & rno);
00349 
00350 
00351 
00352 // factory class for NML objects
00353 class NMLFactory
00354 {
00355  public:
00356   static NMLFactory *Instance(void);
00357   static void ExitInstance(void);
00358 
00359   NML *CreateNML(const NML::RawNewsObject_t & rno,
00360                  const NMLEscapeCodeHandler *EscapeCodeHandler);
00361   NML *CreateError(NML::NewsObjectId_t oid,
00362                    const char *title);
00363   NML *CreateErrorDump(NML::NewsObjectId_t oid,
00364                        const NML::RawNewsObject_t & rno,
00365                        const char *error_msg);
00366 
00367  private:
00368   static NMLFactory *_instance;
00369   NMLFactory();
00370   ~NMLFactory();
00371   NMLFactory & operator=(const NMLFactory &);
00372   NMLFactory(const NMLFactory &);
00373 };
00374 
00375 
00376 #endif

Generated on Thu Mar 18 13:10:33 2004 for journaline_demo by doxygen1.2.17