BEAST/BSE - Better Audio System and Sound Engine  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sfidl-generator.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __SFIDL_GENERATOR_H__
3 #define __SFIDL_GENERATOR_H__
4 
5 #include <map>
6 #include <iostream>
7 #include <algorithm>
8 #include "sfidl-utils.hh"
9 #include "sfidl-namespace.hh"
10 #include "sfidl-options.hh"
11 #include "sfidl-parser.hh"
12 #include "sfiparams.hh" /* scatId (SFI_SCAT_*) */
13 
14 namespace Sfidl {
15 
16  class CodeGenerator {
17  protected:
18  const Parser& parser;
19  const Options& options;
20 
21  bool generateHeader;
22  bool generateSource;
23  bool generateIdlLineNumbers;
24 
25  std::vector<String> splitName (const String& name);
26  String makeLowerName (const String& name, char seperator = '_');
27  String makeUpperName (const String& name);
28  String makeMixedName (const String& name);
29  String makeLMixedName (const String& name);
30 
31  enum WordCase {
32  lower,
33  Capitalized,
34  semiCapitalized,
35  UPPER
36  };
37 
38  /*
39  * translates a word into a given word case
40  * i.e. toWordCase ("Hello", UPPER) == "HELLO"
41  */
42  String toWordCase (const String& word, WordCase wc);
43  String joinName (const std::vector<String>& name, const String& seperator, WordCase wc);
44 
45  enum NamespaceType {
46  NONE, /* no namespace */
47  ABSOLUTE, /* in C++ means :: prefix */
48  /* RELATIVE indicated by NamespaceHelper instead */
49  };
50 
51  /*
52  * rename is a function for renaming types according to rules
53  *
54  * name: the name to be renamed
55  * namespace_wc: the desired case for the namespace
56  * namespace_join: how to join the namespace - note that if namespace_join
57  * is "::", then "::" will also be prefixed to the result, whereas if
58  * namespace_join is "_", it will only be used to seperate the namespaces
59  * (this is required/useful for C++)
60  * namespace_append: words to append to the namespace
61  * typename_wc: the desired case for the typename
62  * typename_join: how to join the typename
63  */
64  String
65  rename (NamespaceType namespace_type, const String& name, WordCase namespace_wc,
66  const String &namespace_join, const std::vector<String> &namespace_append,
67  WordCase typename_wc, const String &typename_join);
68 
69  /*
70  * rename is a function for renaming types according to rules
71  *
72  * nsh: namespace helper indicates which namespace to be relative to
73  * namespace_wc: the desired case for the namespace
74  * namespace_join: how to join the namespace
75  * namespace_append: words to append to the namespace
76  * typename_wc: the desired case for the typename
77  * typename_join: how to join the typename
78  */
79  String
80  rename (NamespaceHelper& nsh, const String& name, WordCase namespace_wc,
81  const String& namespace_join, const std::vector<String>& namespace_append,
82  WordCase typename_wc, const String& typename_join);
83 
84  CodeGenerator(const Parser& parser)
85  : parser (parser), options (*Options::the()),
86  generateHeader (true), generateSource (false),
87  generateIdlLineNumbers (true)
88  {
89  }
90 
91  public:
92  /*
93  * returns the options supported by this code generator (used by the option parser)
94  * the first element of the pair is the option (i.e. "--source")
95  * the second element of the pair is true when the option should be followed by a
96  * user argument (as in "--prefix beast"), false otherwise (i.e. "--source")
97  */
98  virtual OptionVector getOptions();
99 
100  /*
101  * called by the option parser when an option is set
102  * option is the option (i.e. "--prefix")
103  * value is the value (i.e. "beast"), and "1" for options without user argument
104  */
105  virtual void setOption (const String& option, const String& value);
106 
107  /*
108  * prints help for the options supported by this code generator
109  */
110  virtual void help();
111 
112  /*
113  * run generates the code, and should return true if successful, false otherwise
114  * (for instance if inconsistent options were given to the code generator)
115  */
116  virtual bool run () = 0;
117  virtual ~CodeGenerator() {
118  }
119  };
120 
121 };
122 
123 #endif /* __SFIDL_GENERATOR_H__ */
124 
125 /* vim:set ts=8 sts=2 sw=2: */
Definition: sfidl-generator.hh:16
Definition: sfidl-options.hh:16
Definition: sfidl-namespace.hh:14
Definition: sfidl-parser.hh:231
std::string String