home *** CD-ROM | disk | FTP | other *** search
- //
- // $Id: TemplateTranslator.h,v 1.2 2000/06/07 06:53:30 sergey Exp $
- //
-
- #ifndef _TemplateTranslator_h_
- #define _TemplateTranslator_h_
-
- namespace Util
- {
- class InputStream;
- class OutputStream;
-
-
- //
- // Simple translator for template files.
- // All found keyword placeholders will be replaced by concrete values.
- // Placeholders are the words inside the brackets like this:
- // ${ keyword }$.
- //
- class TemplateTranslator
- {
- public:
- class TranslationTable;
-
- // Constructs object and stores reference on the translation table.
- // Translator doesn't takes responsibility about the table.
- TemplateTranslator(const TranslationTable& table);
-
- ~TemplateTranslator();
-
- // TemplateTranslator(const TemplateTranslator&);
- // TemplateTranslator& operator =(const TemplateTranslator&);
-
- // operations
-
- void translate(const char* in, OutputStream& out) const;
-
- // implementation
- private:
- // Copies line into the output stream. Replaces eny found keyword placeholders by concrete values.
- void processLine(const char* line, OutputStream& out) const;
-
- // Returns offset to the first found placeholder or -1 otherwise.
- int findPlaceholder(const char* line) const;
-
- // Translates placeholder using the translation table to get concrete value.
- // Returns actual len of the whole placeholder string.
- int translatePlaceholder(const char* placeholder, OutputStream& out) const;
-
- // Extracts the keyword from the placeholder line.
- // Returns actual length of the whole placeholder string.
- int getKeyword(const char* placeholder, char* result, int maxResultLen) const;
-
- void copyKeyword(const char* keyword, int keywordLen, char* result, int maxResultLen) const;
-
- // data members
- private:
- const TranslationTable& _translationTable;
- };
-
-
- //
- // Interface class which offers the keyword search and replace service for the
- // translator.
- //
- class TemplateTranslator::TranslationTable
- {
- protected:
- TranslationTable() {}
- virtual ~TranslationTable() {}
-
- public:
- // Returns value of the queried keyword or null if such keyword does not exists.
- virtual const char* get(const char* keyword) const = 0;
- };
- }
- // namespace Util
-
- #endif // _TemplateTranslator_h_
-