LibMusicXML  3.18
oahElements.h
1 /*
2  MusicXML Library
3  Copyright (C) Grame 2006-2013
4 
5  This Source Code Form is subject to the terms of the Mozilla Public
6  License, v. 2.0. If a copy of the MPL was not distributed with this
7  file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9  Grame Research Laboratory, 11, cours de Verdun Gensoul 69002 Lyon - France
10  research@grame.fr
11 */
12 
13 #ifndef ___optionsElements___
14 #define ___optionsElements___
15 
16 using namespace std;
17 
18 namespace MusicXML2
19 {
20 
21 // layout settings
22 //______________________________________________________________________________
23 const int K_OAH_ELEMENTS_INDENTER_OFFSET = 3;
24  // indent a bit more for readability
25 
26 const int K_OAH_FIELD_WIDTH = 40;
27 
28 // PRE-declarations for class dependencies
29 //______________________________________________________________________________
30 class oahElement;
31 typedef SMARTP<oahElement> S_oahElement;
32 
33 class oahValuedAtom;
34 typedef SMARTP<oahValuedAtom> S_oahValuedAtom;
35 
36 class EXP oahHandler;
37 typedef SMARTP<oahHandler> S_oahHandler;
38 
39 // data types
40 // ------------------------------------------------------
41 
42 enum oahElementVisibilityKind {
43  kElementVisibilityAlways,
44  kElementVisibilityHiddenByDefault };
45 
46 string optionVisibilityKindAsString (
47  oahElementVisibilityKind optionVisibilityKind);
48 
49 //______________________________________________________________________________
50 class oahElement : public smartable
51 {
52  public:
53 
54  // creation
55  // ------------------------------------------------------
56 
57  static SMARTP<oahElement> create (
58  string shortName,
59  string longName,
60  string description,
61  oahElementVisibilityKind optionVisibilityKind);
62 
63  protected:
64 
65  // constructors/destructor
66  // ------------------------------------------------------
67 
68  oahElement (
69  string shortName,
70  string longName,
71  string description,
72  oahElementVisibilityKind optionVisibilityKind);
73 
74  virtual ~oahElement ();
75 
76  public:
77 
78  // set and get
79  // ------------------------------------------------------
80 
81  // uplink
82  void setHandlerUpLink (
83  S_oahHandler handlerUpLink)
84  { fHandlerUpLink = handlerUpLink; }
85 
86  S_oahHandler getHandlerUpLink () const
87  { return fHandlerUpLink; }
88 
89  string getShortName () const
90  { return fShortName; }
91 
92  string getLongName () const
93  { return fLongName; }
94 
95  string getDescription () const
96  { return fDescription; }
97 
98  oahElementVisibilityKind
99  getElementVisibilityKind () const
100  { return fElementVisibilityKind; }
101 
102  void setIsHidden ()
103  { fIsHidden = true; }
104 
105  bool getIsHidden () const
106  { return fIsHidden; }
107 
108  void setMultipleOccurrencesAllowed ()
109  { fMultipleOccurrencesAllowed = true; }
110 
111  bool getMultipleOccurrencesAllowed () const
112  { return fMultipleOccurrencesAllowed; }
113 
114  public:
115 
116  // services
117  // ------------------------------------------------------
118 
119  string fetchNames () const;
120  string fetchNamesInColumns (
121  int subGroupsShortNameFieldWidth) const;
122 
123  string fetchNamesBetweenParentheses () const;
124  string fetchNamesInColumnsBetweenParentheses (
125  int subGroupsShortNameFieldWidth) const;
126 
127  virtual int fetchVariableNameLength () const
128  { return 0; }
129 
130  S_oahElement fetchOptionByName (
131  string name);
132 
133  virtual S_oahValuedAtom
134  handleOptionUnderName (
135  string optionName,
136  ostream& os);
137 
138  public:
139 
140  // visitors
141  // ------------------------------------------------------
142 
143  virtual void acceptIn (basevisitor* v);
144  virtual void acceptOut (basevisitor* v);
145 
146  virtual void browseData (basevisitor* v);
147 
148  public:
149 
150  // print
151  // ------------------------------------------------------
152 
153  virtual string asShortNamedOptionString () const;
154  virtual string asActualLongNamedOptionString () const;
155 
156  string asLongNamedOptionString () const
157  {
158  if (fLongName.size ()) {
159  return asActualLongNamedOptionString ();
160  }
161  else {
162  return asShortNamedOptionString ();
163  }
164  }
165 
166  string asString () const;
167 
168  virtual void printOptionHeader (ostream& os) const; // virtual ??? JMI
169 
170  virtual void printOptionEssentials (
171  ostream& os,
172  int fieldWidth) const;
173 
174  virtual void print (ostream& os) const;
175 
176  virtual void printHelp (ostream& os);
177 
178  protected:
179 
180  // fields
181  // ------------------------------------------------------
182 
183  // uplink
184  S_oahHandler fHandlerUpLink;
185 
186  string fShortName;
187  string fLongName;
188  string fDescription;
189 
190  oahElementVisibilityKind
191  fElementVisibilityKind;
192 
193  bool fIsHidden;
194 
195  bool fMultipleOccurrencesAllowed;
196 };
198 EXP ostream& operator<< (ostream& os, const S_oahElement& elt);
199 
200 /*
201 Because the set needs a comparison functor to work with. If you don't specify one, it will make a default-constructed one. In this case, since you're using a function-pointer type, the default-constructed one will be a null pointer, which can't be called; so instead, you have to provide the correct function pointer at run time.
202 
203 A better approach might be to use a function class type (a.k.a. functor type); then the function call can be resolved at compile time, and a default-constructed object will do the right thing.
204 */
206  bool operator() (
207  const S_oahElement firstElement,
208  const S_oahElement secondElement) const;
209 };
210 
211 /* JMI
212 //______________________________________________________________________________
213 template <typename T> class oahBrowser : public browser<T>
214 {
215  protected:
216 
217  basevisitor* fVisitor;
218 
219  virtual void enter (T& t) { t.acceptIn (fVisitor); }
220  virtual void leave (T& t) { t.acceptOut (fVisitor); }
221 
222  public:
223 
224  oahBrowser (basevisitor* v) : fVisitor (v)
225  {}
226 
227  virtual ~oahBrowser ()
228  {}
229 
230  virtual void set (basevisitor* v)
231  { fVisitor = v; }
232 
233  virtual void browse (T& t)
234  {
235  enter (t);
236 
237  t.browseData (fVisitor);
238 
239  leave (t);
240  }
241 };
242 */
243 
244 template <typename T> class oahBrowser : public browser <T>
245 {
246  public:
247 
248  oahBrowser (basevisitor* v) : fVisitor (v) {}
249 
250  virtual ~oahBrowser () {}
251 
252  public:
253 
254  virtual void set (basevisitor* v) { fVisitor = v; }
255 
256  virtual void browse (T& t) {
257 #ifdef TRACE_OAH
258  // if (gOahOah->fTraceOahVisitors) {
259  cout <<
260  endl <<
261  ".\\\" --> browse()" <<
262  endl;
263  // }
264 #endif
265 
266  enter (t);
267 
268  t.browseData (fVisitor);
269 
270  leave (t);
271  }
272 
273  protected:
274 
275  basevisitor* fVisitor;
276 
277  virtual void enter (T& t) {
278 #ifdef TRACE_OAH
279  // if (gOahOah->fTraceOahVisitors) {
280  cout <<
281  endl <<
282  ".\\\" --> enter()" <<
283  endl;
284  // }
285 #endif
286 
287  t.acceptIn (fVisitor);
288  }
289  virtual void leave (T& t) {
290 #ifdef TRACE_OAH
291  // if (gOahOah->fTraceOahVisitors) {
292  cout <<
293  endl <<
294  ".\\\" --> leave()" <<
295  endl;
296  // }
297 #endif
298 
299  t.acceptOut (fVisitor);
300  }
301 };
302 
303 
304 }
305 
306 
307 #endif
the smart pointer implementation
Definition: smartpointer.h:58
Definition: basevisitor.h:25
Definition: browser.h:22
Definition: oahElements.h:245
Definition: oahElements.h:51
the base class for smart pointers implementation
Definition: smartpointer.h:29
Definition: oahElements.h:205