FONTAINE
1.0
|
00001 // 00002 // The Fontaine Font Analysis Project 00003 // 00004 // Copyright (c) 2009 by Edward H. Trager 00005 // All Rights Reserved 00006 // 00007 // Released under the GNU GPL version 2.0 or later. 00008 // 00009 00010 00011 // 00012 // MLR.h 00013 // 00014 // Markup Language Report base class 00015 // 00016 00017 #ifndef MLR_INCLUDED 00018 #define MLR_INCLUDED 00019 00020 #include <string> 00021 #include <vector> 00022 #include <sstream> 00023 #include <stack> 00024 00025 class MLRItem { 00026 00027 private: 00028 00029 std::string _key; 00030 unsigned _children; 00031 bool _isAListContainer; 00032 00033 public: 00034 00035 MLRItem(const std::string &key); 00036 00037 void incrementChildren(); 00038 void operator++(); 00039 void setAsListContainer(); 00040 00041 std::string getKey() const { return _key; }; 00042 unsigned getNumberOfChildren() const { return _children; }; 00043 bool isAListContainer() const; 00044 }; 00045 00046 // 00047 // Markup Language Report base class 00048 // 00049 class MLR { 00050 00051 private: 00052 00053 MLRItem *_item; 00054 00055 00056 protected: 00057 00058 std::string _rootTag; 00059 00060 std::string _indentationString; 00061 std::stack<MLRItem *> _stack; 00062 std::ostringstream _ss; 00063 00064 void _start(const std::string &key); 00065 void _end(const std::string &key); 00066 00067 void _incrementChildren(); 00068 unsigned _getNumberOfChildren(); 00069 00070 void _indent(void); 00071 00072 void _setAsListContainer(void); 00073 bool _isAListContainer(void); 00074 00075 public: 00076 00077 MLR(); 00078 virtual ~MLR(){}; 00079 00080 void setRootTag(const std::string &tag); 00081 void setRootTag(const char *tag); 00082 00083 // 00084 // Virtuals and Pure Virtuals for defining in sub classes: 00085 // 00086 00087 virtual void startRoot(void)=0; 00088 virtual void endRoot(void)=0; 00089 00090 virtual void startList(const std::string &key)=0; 00091 virtual void addKeyValuePairToList(const std::string &key,const std::string &value)=0; 00092 virtual void endList(const std::string &key)=0; 00093 virtual void start(const std::string &key)=0; 00094 virtual void addKeyValuePair(const std::string &key,const std::string &value)=0; 00095 virtual void end(const std::string &key)=0; 00096 00097 virtual void startList(const char *key)=0; 00098 virtual void addKeyValuePairToList(const char *key,const char *value)=0; 00099 virtual void endList(const char *key)=0; 00100 virtual void start(const char *key)=0; 00101 virtual void addKeyValuePair(const char *key,const char *value)=0; 00102 virtual void end(const char *key)=0; 00103 00104 void setIndentationString(const std::string &indent); 00105 00106 virtual std::string getReport() const; 00107 00108 }; 00109 00110 #endif