BEAST/BSE - Better Audio System and Sound Engine  0.8.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
sfidl-generator.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __SFIDL_GENERATOR_H__
00003 #define __SFIDL_GENERATOR_H__
00004 
00005 #include <map>
00006 #include <iostream>
00007 #include <algorithm>
00008 #include "sfidl-utils.hh"
00009 #include "sfidl-namespace.hh"
00010 #include "sfidl-options.hh"
00011 #include "sfidl-parser.hh"
00012 #include "sfiparams.hh" /* scatId (SFI_SCAT_*) */
00013 
00014 namespace Sfidl {
00015 
00016   class CodeGenerator {
00017   protected:
00018     const Parser& parser;
00019     const Options& options;
00020 
00021     bool generateHeader;
00022     bool generateSource;
00023     bool generateIdlLineNumbers;
00024 
00025     std::vector<String> splitName (const String& name);
00026     String makeLowerName (const String& name, char seperator = '_');
00027     String makeUpperName (const String& name);
00028     String makeMixedName (const String& name);
00029     String makeLMixedName (const String& name);
00030 
00031     enum WordCase {
00032       lower,
00033       Capitalized,
00034       semiCapitalized,
00035       UPPER
00036     };
00037 
00038     /*
00039      * translates a word into a given word case
00040      * i.e. toWordCase ("Hello", UPPER) == "HELLO"
00041      */
00042     String toWordCase (const String& word, WordCase wc);
00043     String joinName (const std::vector<String>& name, const String& seperator, WordCase wc);
00044 
00045     enum NamespaceType {
00046       NONE,     /* no namespace */
00047       ABSOLUTE, /* in C++ means :: prefix */
00048       /* RELATIVE indicated by NamespaceHelper instead */
00049     };
00050 
00051     /*
00052      * rename is a function for renaming types according to rules
00053      * 
00054      * name: the name to be renamed
00055      * namespace_wc: the desired case for the namespace
00056      * namespace_join: how to join the namespace - note that if namespace_join
00057      *   is "::", then "::" will also be prefixed to the result, whereas if
00058      *   namespace_join is "_", it will only be used to seperate the namespaces
00059      *   (this is required/useful for C++)
00060      * namespace_append: words to append to the namespace
00061      * typename_wc: the desired case for the typename
00062      * typename_join: how to join the typename
00063      */
00064     String
00065     rename (NamespaceType namespace_type, const String& name, WordCase namespace_wc,
00066             const String &namespace_join, const std::vector<String> &namespace_append,
00067             WordCase typename_wc, const String &typename_join);
00068 
00069     /*
00070      * rename is a function for renaming types according to rules
00071      * 
00072      * nsh: namespace helper indicates which namespace to be relative to
00073      * namespace_wc: the desired case for the namespace
00074      * namespace_join: how to join the namespace
00075      * namespace_append: words to append to the namespace
00076      * typename_wc: the desired case for the typename
00077      * typename_join: how to join the typename
00078      */
00079     String
00080     rename (NamespaceHelper& nsh, const String& name, WordCase namespace_wc,
00081             const String& namespace_join, const std::vector<String>& namespace_append,
00082             WordCase typename_wc, const String& typename_join);
00083 
00084     CodeGenerator(const Parser& parser)
00085       : parser (parser), options (*Options::the()),
00086         generateHeader (true), generateSource (false),
00087         generateIdlLineNumbers (true)
00088     {
00089     }
00090 
00091   public:
00092     /*
00093      * returns the options supported by this code generator (used by the option parser)
00094      * the first element of the pair is the option (i.e. "--source")
00095      * the second element of the pair is true when the option should be followed by a
00096      *   user argument (as in "--prefix beast"), false otherwise (i.e. "--source")
00097      */
00098     virtual OptionVector getOptions();
00099 
00100     /*
00101      * called by the option parser when an option is set
00102      * option is the option (i.e. "--prefix")
00103      * value is the value (i.e. "beast"), and "1" for options without user argument
00104      */
00105     virtual void setOption (const String& option, const String& value);
00106 
00107     /*
00108      * prints help for the options supported by this code generator
00109      */
00110     virtual void help();
00111 
00112     /*
00113      * run generates the code, and should return true if successful, false otherwise
00114      * (for instance if inconsistent options were given to the code generator)
00115      */
00116     virtual bool run () = 0;
00117     virtual ~CodeGenerator() {
00118     }
00119   };
00120 
00121 };
00122 
00123 #endif  /* __SFIDL_GENERATOR_H__ */
00124 
00125 /* vim:set ts=8 sts=2 sw=2: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines