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 #include <iomanip>      // setw, setprecision, ...
14 
15 #include "lpsrScheme.h"
16 
17 #include "lpsrVarValAssocs.h"
18 
19 
20 using namespace std;
21 
22 namespace MusicXML2
23 {
24 
25 //______________________________________________________________________________
26 string const lpsrSchemeVariable::g_SchemeVariableNoUnit    = "";
27 string const lpsrSchemeVariable::g_SchemeVariableNoComment = "";
28 
create(int inputLineNumber,lpsrCommentedKind commentedKind,string variableName,string value,string comment,lpsrEndlKind endlKind)29 S_lpsrSchemeVariable lpsrSchemeVariable::create (
30   int               inputLineNumber,
31   lpsrCommentedKind commentedKind,
32   string            variableName,
33   string            value,
34   string            comment,
35   lpsrEndlKind      endlKind)
36 {
37   lpsrSchemeVariable* o =
38     new lpsrSchemeVariable (
39       inputLineNumber,
40       commentedKind, variableName, value, comment, endlKind);
41   assert(o!=0);
42   return o;
43 }
44 
lpsrSchemeVariable(int inputLineNumber,lpsrCommentedKind commentedKind,string variableName,string value,string comment,lpsrEndlKind endlKind)45 lpsrSchemeVariable::lpsrSchemeVariable (
46   int               inputLineNumber,
47   lpsrCommentedKind commentedKind,
48   string            variableName,
49   string            value,
50   string            comment,
51   lpsrEndlKind      endlKind)
52     : lpsrElement (inputLineNumber)
53 {
54   fCommentedKind = commentedKind;
55 
56   fVariableName  = variableName;
57   fVariableValue = value;
58 
59   fComment       = comment;
60 
61   fEndlKind      = endlKind;
62 }
63 
~lpsrSchemeVariable()64 lpsrSchemeVariable::~lpsrSchemeVariable ()
65 {}
66 
acceptIn(basevisitor * v)67 void lpsrSchemeVariable::acceptIn (basevisitor* v)
68 {
69 #ifdef TRACE_OAH
70   if (gLpsrOah->fTraceLpsrVisitors) {
71     gLogOstream <<
72       "% ==> lpsrSchemeVariable::acceptIn ()" <<
73       endl;
74   }
75 #endif
76 
77   if (visitor<S_lpsrSchemeVariable>*
78     p =
79       dynamic_cast<visitor<S_lpsrSchemeVariable>*> (v)) {
80         S_lpsrSchemeVariable elem = this;
81 
82 #ifdef TRACE_OAH
83         if (gLpsrOah->fTraceLpsrVisitors) {
84           gLogOstream <<
85             "% ==> Launching lpsrSchemeVariable::visitStart ()" <<
86             endl;
87         }
88 #endif
89         p->visitStart (elem);
90   }
91 }
92 
acceptOut(basevisitor * v)93 void lpsrSchemeVariable::acceptOut (basevisitor* v)
94 {
95 #ifdef TRACE_OAH
96   if (gLpsrOah->fTraceLpsrVisitors) {
97     gLogOstream <<
98       "% ==> lpsrSchemeVariable::acceptOut ()" <<
99       endl;
100   }
101 #endif
102 
103   if (visitor<S_lpsrSchemeVariable>*
104     p =
105       dynamic_cast<visitor<S_lpsrSchemeVariable>*> (v)) {
106         S_lpsrSchemeVariable elem = this;
107 
108 #ifdef TRACE_OAH
109         if (gLpsrOah->fTraceLpsrVisitors) {
110           gLogOstream <<
111             "% ==> Launching lpsrSchemeVariable::visitEnd ()" <<
112             endl;
113         }
114 #endif
115         p->visitEnd (elem);
116   }
117 }
118 
browseData(basevisitor * v)119 void lpsrSchemeVariable::browseData (basevisitor* v)
120 {}
121 
commentedKindAsString(lpsrCommentedKind commentedKind)122 string lpsrSchemeVariable::commentedKindAsString (
123   lpsrCommentedKind commentedKind)
124 {
125   string result;
126 
127   switch (commentedKind) {
128     case lpsrSchemeVariable::kCommentedYes:
129       result = "commentedYes";
130       break;
131     case lpsrSchemeVariable::kCommentedNo:
132       result = "commentedNo";
133       break;
134   } // switch
135 
136   return result;
137 }
138 
endlKindAsString(lpsrEndlKind endlKind)139 string lpsrSchemeVariable::endlKindAsString (
140   lpsrEndlKind endlKind)
141 {
142   string result;
143 
144   switch (endlKind) {
145     case lpsrSchemeVariable::kEndlOnce:
146       result = "endlOnce";
147       break;
148     case lpsrSchemeVariable::kEndlTwice:
149       result = "endlTwice";
150       break;
151     case lpsrSchemeVariable::kEndlNone:
152       result = "endlNone";
153       break;
154   } // switch
155 
156   return result;
157 }
158 
print(ostream & os) const159 void lpsrSchemeVariable::print (ostream& os) const
160 {
161   os <<
162     "SchemeVariable" <<
163     endl;
164 
165   gIndenter++;
166 
167   // escape quotes if any
168   string variableName;
169   string variableValue;
170 
171   for_each (
172     fVariableName.begin (),
173     fVariableName.end (),
174     stringQuoteEscaper (variableName));
175   for_each (
176     fVariableValue.begin (),
177     fVariableValue.end (),
178     stringQuoteEscaper (variableValue));
179 
180   // print resulting strings
181   const int fieldWidth = 15;
182 
183   os << left <<
184     setw (fieldWidth) <<
185     "variableName" <<
186     " : \"" << variableName << "\"" <<
187     endl <<
188     setw (fieldWidth) <<
189     "variableValue" <<
190     " : \"" << variableValue << "\"" <<
191     endl <<
192 
193     setw (fieldWidth) <<
194     "commentedKind" << " : " <<
195     commentedKindAsString (fCommentedKind) <<
196     endl <<
197 
198   // backSlashKindAsString ??? JMI
199   // varValSeparatorKindAsString ??? JMI
200   // quotesKindAsString ??? JMI
201 
202     setw (fieldWidth) <<
203     "endlKind" << " : " <<
204     endlKindAsString (fEndlKind) <<
205     endl;
206 
207   gIndenter--;
208 }
209 
operator <<(ostream & os,const S_lpsrSchemeVariable & assoc)210 ostream& operator<< (ostream& os, const S_lpsrSchemeVariable& assoc)
211 {
212   assoc->print (os);
213   return os;
214 }
215 
216 //______________________________________________________________________________
create(int inputLineNumber,string functionName,string functionDescription,string functionCode)217 S_lpsrSchemeFunction lpsrSchemeFunction::create (
218   int    inputLineNumber,
219   string functionName,
220   string functionDescription,
221   string functionCode)
222 {
223   lpsrSchemeFunction* o =
224     new lpsrSchemeFunction (
225       inputLineNumber,
226       functionName, functionDescription, functionCode);
227   assert(o!=0);
228   return o;
229 }
230 
lpsrSchemeFunction(int inputLineNumber,string functionName,string functionDescription,string functionCode)231 lpsrSchemeFunction::lpsrSchemeFunction (
232   int    inputLineNumber,
233   string functionName,
234   string functionDescription,
235   string functionCode)
236     : lpsrElement (inputLineNumber)
237 {
238   fFunctionName        = functionName;
239   fFunctionDescription = functionDescription;
240   fFunctionCode        = functionCode;
241   }
242 
~lpsrSchemeFunction()243 lpsrSchemeFunction::~lpsrSchemeFunction ()
244 {}
245 
acceptIn(basevisitor * v)246 void lpsrSchemeFunction::acceptIn (basevisitor* v)
247 {
248 #ifdef TRACE_OAH
249   if (gLpsrOah->fTraceLpsrVisitors) {
250     gLogOstream <<
251       "% ==> lpsrSchemeFunction::acceptIn ()" <<
252       endl;
253   }
254 #endif
255 
256   if (visitor<S_lpsrSchemeFunction>*
257     p =
258       dynamic_cast<visitor<S_lpsrSchemeFunction>*> (v)) {
259         S_lpsrSchemeFunction elem = this;
260 
261 #ifdef TRACE_OAH
262         if (gLpsrOah->fTraceLpsrVisitors) {
263           gLogOstream <<
264             "% ==> Launching lpsrSchemeFunction::visitStart ()" <<
265             endl;
266         }
267 #endif
268         p->visitStart (elem);
269   }
270 }
271 
acceptOut(basevisitor * v)272 void lpsrSchemeFunction::acceptOut (basevisitor* v)
273 {
274 #ifdef TRACE_OAH
275   if (gLpsrOah->fTraceLpsrVisitors) {
276     gLogOstream <<
277       "% ==> lpsrSchemeFunction::acceptOut ()" <<
278       endl;
279   }
280 #endif
281 
282   if (visitor<S_lpsrSchemeFunction>*
283     p =
284       dynamic_cast<visitor<S_lpsrSchemeFunction>*> (v)) {
285         S_lpsrSchemeFunction elem = this;
286 
287 #ifdef TRACE_OAH
288         if (gLpsrOah->fTraceLpsrVisitors) {
289           gLogOstream <<
290             "% ==> Launching lpsrSchemeFunction::visitEnd ()" <<
291             endl;
292         }
293 #endif
294         p->visitEnd (elem);
295   }
296 }
297 
browseData(basevisitor * v)298 void lpsrSchemeFunction::browseData (basevisitor* v)
299 {}
300 
print(ostream & os) const301 void lpsrSchemeFunction::print (ostream& os) const
302 {
303   os <<
304     "SchemeFunction" <<
305     endl;
306 
307   gIndenter++;
308 
309   // print resulting strings
310   os <<
311     "function name : \"" << fFunctionName << "\"" <<
312     endl <<
313     "function description: \"" << fFunctionDescription << "\"" <<
314     endl <<
315     "function code: \"" << fFunctionCode << "\"" <<
316     endl;
317 
318   gIndenter--;
319 }
320 
operator <<(ostream & os,const S_lpsrSchemeFunction & assoc)321 ostream& operator<< (ostream& os, const S_lpsrSchemeFunction& assoc)
322 {
323   assoc->print (os);
324   return os;
325 }
326 
327 
328 }
329