home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / src / Util / TemplateTranslator.h < prev   
C/C++ Source or Header  |  2000-06-07  |  2KB  |  80 lines

  1. //
  2. //  $Id: TemplateTranslator.h,v 1.2 2000/06/07 06:53:30 sergey Exp $
  3. //
  4.  
  5. #ifndef _TemplateTranslator_h_
  6. #define _TemplateTranslator_h_
  7.  
  8. namespace Util
  9. {
  10.     class InputStream;
  11.     class OutputStream;
  12.  
  13.  
  14.     //
  15.     // Simple translator for template files.
  16.     // All found keyword placeholders will be replaced by concrete values.
  17.     // Placeholders are the words inside the brackets like this:
  18.     //  ${ keyword }$.
  19.     //
  20.     class TemplateTranslator
  21.     {
  22.     public:
  23.         class TranslationTable;
  24.  
  25.         // Constructs object and stores reference on the translation table.
  26.         // Translator doesn't takes responsibility about the table.
  27.         TemplateTranslator(const TranslationTable& table);
  28.  
  29.         ~TemplateTranslator();
  30.  
  31.         // TemplateTranslator(const TemplateTranslator&);
  32.         // TemplateTranslator& operator =(const TemplateTranslator&);
  33.  
  34.     // operations
  35.  
  36.         void translate(const char* in, OutputStream& out) const;
  37.  
  38.     // implementation
  39.     private:
  40.         // Copies line into the output stream. Replaces eny found keyword placeholders by concrete values.
  41.         void processLine(const char* line, OutputStream& out) const;
  42.  
  43.         // Returns offset to the first found placeholder or -1 otherwise.
  44.         int findPlaceholder(const char* line) const;
  45.  
  46.         // Translates placeholder using the translation table to get concrete value.
  47.         // Returns actual len of the whole placeholder string.
  48.         int translatePlaceholder(const char* placeholder, OutputStream& out) const;
  49.  
  50.         // Extracts the keyword from the placeholder line.
  51.         // Returns actual length of the whole placeholder string.
  52.         int getKeyword(const char* placeholder, char* result, int maxResultLen) const;
  53.  
  54.         void copyKeyword(const char* keyword, int keywordLen, char* result, int maxResultLen) const;
  55.  
  56.     // data members
  57.     private:
  58.         const TranslationTable& _translationTable;
  59.     };
  60.  
  61.  
  62.     //
  63.     // Interface class which offers the keyword search and replace service for the
  64.     // translator.
  65.     //
  66.     class TemplateTranslator::TranslationTable
  67.     {
  68.     protected:
  69.         TranslationTable() {}
  70.         virtual ~TranslationTable() {}
  71.  
  72.     public:
  73.         // Returns value of the queried keyword or null if such keyword does not exists.
  74.         virtual const char* get(const char* keyword) const = 0;
  75.     };
  76. }
  77. // namespace Util
  78.  
  79. #endif  // _TemplateTranslator_h_
  80.