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

componentfile_preprocess.h

Go to the documentation of this file.
00001 /*
00002         ClanGUI, copyrights by various people. Have a look in the CREDITS file.
00003         
00004         This sourcecode is distributed using the Library GNU Public Licence,
00005         version 2 or (at your option) any later version. Please read LICENSE
00006         for details.
00007 */
00008 
00009 #ifndef header_componentfile_preprocess
00010 #define header_componentfile_preprocess
00011 
00012 #include <string>
00013 #include <map>
00014 #include <list>
00015 #include <vector>
00016 
00017 /*
00018         Preprocessor functionality:
00019 
00020         Implements template support, by preprocessing the component script file,
00021         expanding template instantiations with template bodies, and removing template
00022         definition bodies. Example;
00023 
00024 File before:    template <X, Y, TEXT>
00025                                 label std_label
00026                                 {
00027                                         x = X;
00028                                         y = Y;
00029                                         text = TEXT;
00030                                 }
00031 
00032                                 template <X, Y, TEXT>
00033                                 frame my_frame
00034                                 {
00035                                         x = X;
00036                                         y = Y;
00037 
00038                                         label1 = std_label<X, Y, TEXT>;
00039                                 }
00040 
00041                                 my_thing = my_frame<10, 10, testing>;
00042 
00043 <============================================================>
00044 
00045 File after:             frame my_thing
00046                                 {
00047                                         x = 10;
00048                                         y = 10;
00049 
00050                                         label label1
00051                                         {
00052                                                 x = 10;
00053                                                 y = 10;
00054                                                 text = testing;
00055                                         }
00056                                 }
00057 */
00058 
00059 class CL_Componentfile_Preprocess
00060 {
00061 public:
00062         CL_Componentfile_Preprocess(const std::string &data, const std::string &filename);
00063 
00064         operator const std::string &() { return data; }
00065 private:
00066         std::string data;
00067 
00068         enum EParseState
00069         {
00070                 PARSE_GLOBAL,
00071                 PARSE_TEMPLATE,
00072                 PARSE_TEMPLATE_ARG,
00073                 PARSE_TEMPLATE_NAMEDEF,
00074                 PARSE_TEMPLATE_BODY,
00075                 PARSE_TEMPLATE_INSTANTIATION,
00076                 PARSE_TEMPLATE_INSTANTIATION_ARG
00077         };
00078 
00079         struct TemplateDefinition
00080         {
00081                 int file_offset;
00082                 int name_offset;
00083                 int definition_copy_offset;
00084                 std::string definition;
00085                 typedef std::map<std::string, std::pair<int, std::list<int> > > CONV_MAP;
00086                 CONV_MAP conversions;
00087         };
00088 
00089         struct TemplateReplacement
00090         {
00091                 int offset;
00092                 std::string new_text;
00093                 int erase_length;
00094         };
00095 
00096         class SortTemplateDefinitionByLocationDescending
00097         {
00098         public:
00099                 bool operator()(TemplateDefinition *x, TemplateDefinition *y) const
00100                 {
00101                         return x->file_offset > y->file_offset;
00102                 }
00103         };
00104         void perform_replacements(std::string &s, std::vector<TemplateReplacement> &replacements, int global_offset);
00105 
00106         class SortTemplateReplacementByLocationDescending
00107         {
00108         public:
00109                 bool operator()(const TemplateReplacement &x, const TemplateReplacement &y) const
00110                 {
00111                         return x.offset > y.offset;
00112                 }
00113         };
00114 };
00115 
00116 #endif

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001