GIS.h
gehe zur Dokumentation dieser Datei
00001 
00023 
00024 // header file of GIS (GMN Intern Structur)
00025 // ##################################################################
00026 
00027 #ifndef GIS_H
00028 #define GIS_H
00029 
00030 #include "Defs.h"
00031 
00032 // Stream und cout unterdrücken
00033 #define FOR_MUTWIN
00034 
00035 #ifndef FOR_MUTWIN
00036 #include <iostream.h>
00037 #endif
00038 
00039 #include <string.h>
00040 #include <stdlib.h>
00041 #include "Frac.h"
00042 
00043 
00044 #ifdef WX
00045 #define CHECKDUP(target, source) target = source;
00046 #else
00047 #define CHECKDUP(target, source) \
00048   if ( source )                \
00049          target = mutStrdup(source);     \
00050   else                           \
00051          target = 0
00052 
00053 #endif
00054 
00055 // regisered tags ---------------------------------------------------
00056 
00057 #define NTAGS 52
00058 #define NTAGSHORTS 6
00059 
00060 extern const mutChar * Tags[NTAGS];
00061 
00062 extern const mutChar * TagShorts[NTAGSHORTS];
00063 
00064 #define TTintens   1
00065 #define TTslur     2
00066 #define TTtempo   12
00067 #define TTinstr   19
00068 #define TTtie     20
00069 #define TTstacc   21
00070 #define TTaccent  22
00071 #define TTten     23
00072 #define TTkey     36
00073 #define TToct     37
00074 #define TTalter   50
00075 #define TTmutabor 51
00076 
00077 // ------------------------------------------------------------------0
00078 
00079 #define NO_KEY -32000
00080 
00081 // ------------------------------------------------------------------
00082 
00083 int GetTagId(const mutString &name, mutString &registered);
00084 
00085 // ##################################################################
00086 // GIS types
00087 
00088 enum GisType
00089 {
00090         GTNull,
00091         GTUnknown,  // 1
00092         GTSequenz,  // 2
00093         GTSegment,
00094         GTTag,
00095         GTTagBegin, // 5
00096         GTTagEnd,
00097         GTNote,     // 7
00098         GTParaInt,
00099         GTParaReal,
00100         GTParaStr,  // 10
00101         GTComma
00102 };
00103 
00104 // basic type -------------------------------------------------------
00105 
00106 class GisToken
00107 {
00108 
00109 public:
00110         GisToken *Next;
00111         mutString Sep;
00112 
00113         GisToken(const mutString &sep = mutEmptyString, GisToken *next = 0)
00114         {
00115                 CHECKDUP(Sep, sep);
00116                 DEBUGLOG(other, _T("New Token: %s (was %s)"),Sep.c_str(),sep.c_str());
00117                 Next = next;
00118         }
00119 
00120         virtual ~GisToken()
00121 
00122         {
00123                 mutFreeString(Sep);
00124 
00125                 if ( Next ) delete Next;
00126         }
00127 
00128         virtual GisType Type() const
00129         {
00130                 return GTUnknown;
00131         }
00132 
00133         virtual GisToken *Copy()
00134 
00135         {
00136                 return new GisToken(Sep, 0);
00137         }
00138 
00139 #ifndef FOR_MUTWIN
00140         virtual void Stream(ostream &out, char sep);
00141         virtual void Echo()
00142         {
00143                 cout << "?? ";
00144         }
00145 
00146 #endif
00147 #ifdef WX
00148         operator wxString()
00149         {
00150                 if (Next)
00151                         return ToString() + ((wxString) *Next);
00152                 else
00153                         return ToString();
00154         }
00155 
00156         virtual wxString ToString()
00157         {
00158                 return _T("GisToken: { Sep: '") + Sep + _T("' }\n");
00159         }
00160 
00161 #endif
00162 };
00163 
00164 GisToken *CopyPara(GisToken *para);
00165 
00166 // sequenz
00167 
00168 class GisSequenz : public GisToken
00169 {
00170 
00171 public:
00172         mutString Sep2;
00173         GisToken *Contents;
00174 
00175         GisSequenz(GisToken *contents = 0, const mutString sep = mutEmptyString, GisToken *next = 0) :
00176                         GisToken(sep, next)
00177         {
00178                 Contents = contents;
00179                 Sep2 = mutEmptyString;
00180         }
00181 
00182         ~GisSequenz()
00183 
00184         {
00185                 mutFreeString(Sep2);
00186 
00187                 if ( Contents ) delete Contents;
00188         }
00189 
00190         GisType Type() const
00191         {
00192                 return GTSequenz;
00193         }
00194 
00195 #ifndef FOR_MUTWIN
00196         virtual void Stream(ostream &out, char sep);
00197 
00198         virtual void Echo()
00199         {
00200                 cout << "[ ";
00201         }
00202 
00203 #endif
00204 #ifdef WX
00205         virtual wxString ToString()
00206         {
00207                 return _T("GisSequenz: {\n") + GisToken::ToString() +
00208                        _T("Sep2: '") + Sep2 + _T("'; Contents: {\n") +
00209                        (Contents?((wxString) *Contents):wxString(_T(""))) + _T("}\n}\n");
00210         }
00211 
00212 #endif
00213 };
00214 
00215 // segment
00216 
00217 class GisSegment : public GisToken
00218 {
00219 
00220 public:
00221         mutString Sep2;
00222 
00223         GisToken *Contents;
00224 
00225         GisSegment(GisToken *contents = 0, const mutString sep = mutEmptyString, GisToken *next = 0) :
00226                         GisToken(sep, next)
00227         {
00228                 Contents = contents;
00229                 Sep2 = mutEmptyString;
00230         }
00231 
00232         ~GisSegment()
00233 
00234         {
00235                 mutFreeString(Sep2);
00236 
00237                 if ( Contents ) delete Contents;
00238         }
00239 
00240         virtual GisType Type() const
00241         {
00242                 return GTSegment;
00243         }
00244 
00245 #ifndef FOR_MUTWIN
00246         virtual void Stream(ostream &out, char sep);
00247 
00248         virtual void Echo()
00249         {
00250                 cout << "{ ";
00251         }
00252 
00253 #endif
00254 #ifdef WX
00255         virtual wxString ToString()
00256         {
00257                 return _T("GisSegment: {\n") + GisToken::ToString() +
00258                        _T("Sep2: '") + Sep2 + _T("'; Contents: {\n") +
00259                        (Contents?((wxString) *Contents):wxString(_T(""))) + _T("}\n}\n");
00260         }
00261 
00262 #endif
00263 };
00264 
00265 // tag --------------------------------------------------------------
00266 
00267 class GisTag : public GisToken
00268 {
00269 
00270 public:
00271         int Id;     // 0 ... no registered id
00272         mutString Name;
00273         GisToken *Para;
00274 
00275         GisTag(mutString name = mutEmptyString, GisToken *para = 0,
00276                mutString sep = mutEmptyString, GisToken *next = 0)
00277                         : GisToken(sep, next)
00278         {
00279                 DEBUGLOG(other, _T("name.len %d"),name.Len());
00280                 Id = GetTagId(name, Name);
00281 
00282                 if ( Id == -1 ) {
00283                         Id = 0;
00284                         CHECKDUP(Name, name);
00285                 }
00286 
00287                 Para = para;
00288         }
00289 
00290         GisTag(int id, char shortForm, GisToken *para = 0, mutString sep = mutEmptyString, GisToken *next = 0)
00291                         : GisToken(sep, next)
00292         {
00293                 Id = id;
00294 
00295                 if ( shortForm )
00296                         Name = TagShorts[Id];
00297                 else
00298                         Name = Tags[Id];
00299 
00300                 Para = para;
00301         }
00302 
00303         ~GisTag()
00304         {
00305                 if ( !Id && Name.size() ) mutFreeString(Name);
00306 
00307                 if ( Para ) delete Para;
00308         }
00309 
00310         virtual GisType Type() const
00311         {
00312                 return GTTag;
00313         }
00314 
00315         virtual GisToken *Copy()
00316 
00317         {
00318                 return new GisTag(Name, CopyPara(Para), Sep, 0);
00319         }
00320 
00321         GisType GetParaType(int nr);  // counting from 1
00322         GisToken *GetPara(int nr);
00323 #ifndef FOR_MUTWIN
00324         virtual void Stream(ostream &out, char sep);
00325         virtual void Echo()
00326         {
00327                 cout << "Tag: " << Name <<" ";
00328         }
00329 
00330 #endif
00331 #ifdef WX
00332         virtual wxString ToString()
00333         {
00334                 return _T("GisTag: {\n") + GisToken::ToString() +
00335                        wxString::Format(_T("Id: %d\nName: '"),Id) + Name + _T("'; Para: {\n") +
00336                        (Para?((wxString) *Para):wxString(_T(""))) + _T("}\n}\n");
00337         }
00338 
00339 #endif
00340 };
00341 
00342 // begin ranged tag -------------------------------------------------
00343 
00344 class GisTagBegin : public GisTag
00345 {
00346 
00347 public:
00348         GisToken *End;
00349 
00350         GisTagBegin(mutString name = mutEmptyString, GisToken *para = 0,
00351                     mutString sep = mutEmptyString, GisToken *next = 0)
00352                         : GisTag(name, para, sep, next)
00353         {
00354                 End = 0;
00355         }
00356 
00357         GisTagBegin(int id, char shortForm, GisToken *para = 0,
00358                     mutString sep = mutEmptyString, GisToken *next = 0)
00359                         : GisTag(id, shortForm, para, sep, next)
00360         {
00361                 End = 0;
00362         }
00363 
00364         virtual GisType Type() const
00365         {
00366                 return GTTagBegin;
00367         }
00368 
00369         virtual GisToken *Copy()
00370 
00371         {
00372                 return new GisTagBegin(Name, CopyPara(Para), Sep, 0);
00373         }
00374 
00375 #ifndef FOR_MUTWIN
00376         virtual void Stream(ostream &out, char sep);
00377         virtual void Echo()
00378         {
00379                 cout << "Tag: " << Name << "( ";
00380         }
00381 
00382 #endif
00383 #ifdef WX
00384         virtual wxString ToString()
00385         {
00386                 return _T("GisTagBegin: {\n") + GisTag::ToString() +
00387                        wxString::Format(_T("End: %p\n}\n"),End);
00388         }
00389 
00390 #endif
00391 };
00392 
00393 // end ranged tag ---------------------------------------------------
00394 
00395 class GisTagEnd : public GisToken
00396 {
00397 
00398 public:
00399         GisTagBegin *Begin;
00400         GisTagEnd(GisTagBegin *begin = 0, mutString sep = mutEmptyString, GisToken *next = 0)
00401                         : GisToken(sep, next)
00402         {
00403                 Begin = begin;
00404         }
00405 
00406         virtual GisType Type() const
00407         {
00408                 return GTTagEnd;
00409         }
00410 
00411 #ifndef FOR_MUTWIN
00412         virtual void Stream(ostream &out, char sep);
00413 
00414         virtual void Echo()
00415         {
00416                 cout << ") ";
00417         }
00418 
00419 #endif
00420 #ifdef WX
00421         virtual wxString ToString()
00422         {
00423                 return _T("GisTagEnd: {\n") + GisToken::ToString() +
00424                        wxString::Format(_T("Begin: %p\n}\n"),Begin);
00425         }
00426 
00427 #endif
00428 };
00429 
00430 // note -------------------------------------------------------------
00431 
00432 class GisNote : public GisToken
00433 {
00434 
00435 public:
00436         mutString Name;
00437         mutString Accedentials;
00438         int Octave;
00439         frac Duration;
00440 
00441         GisNote(const mutString &name = mutEmptyString, const mutString &accedentials = mutEmptyString, int octave = 0,
00442                 frac duration = frac(1,4), const mutString &sep = mutEmptyString, GisToken *next = 0)
00443                         : GisToken(sep, next),Name(name),Accedentials(accedentials)
00444         {
00445                 CHECKDUP(Name, name);
00446                 CHECKDUP(Accedentials, accedentials);
00447                 Octave = octave;
00448                 Duration = duration;
00449         }
00450 
00451         GisNote(int key, int octave, int acc, const mutString sep = mutEmptyString, GisToken *next = 0);
00452 
00453         int GetKey();
00454 
00455         virtual GisType Type() const
00456         {
00457                 return GTNote;
00458         }
00459 
00460 #ifndef FOR_MUTWIN
00461         virtual void Stream(ostream &out, mutChar sep);
00462 
00463         virtual void Echo()
00464         {
00465                 cout << "Note: " << Name << Accedentials << Octave <<" ";
00466         }
00467 
00468 #endif
00469 #ifdef WX
00470         virtual wxString ToString()
00471         {
00472                 return _T("GisNote: {\n") + GisToken::ToString() +
00473                        wxString::Format(_T("Name: '%s'; Accedentials: '%s'; Octave: %d; Duration: "),
00474                                         Name.c_str(),Accedentials.c_str(),Octave) +
00475                        (TowxString(Duration)) + _T("\n}\n");
00476         }
00477 
00478 #endif
00479 };
00480 
00481 // integer parameter ------------------------------------------------
00482 
00483 class GisParaInt : public GisToken
00484 {
00485 
00486 public:
00487         int i;
00488 
00489         GisParaInt(int value = 0, mutString sep = mutEmptyString, GisToken *next = 0)
00490                         : GisToken(sep, next)
00491         {
00492                 i = value;
00493         }
00494 
00495         virtual GisType Type() const
00496         {
00497                 return GTParaInt;
00498         }
00499 
00500         virtual GisToken *Copy()
00501 
00502         {
00503                 return new GisParaInt(i, Sep, 0);
00504         }
00505 
00506 #ifndef FOR_MUTWIN
00507         virtual void Stream(ostream &out, mutChar sep);
00508 #endif
00509 #ifdef WX
00510         virtual wxString ToString()
00511         {
00512                 return _T("GisParaInt: { ") + GisToken::ToString() +
00513                        wxString::Format(_T("i: %d }\n"),i);
00514         }
00515 
00516 #endif
00517 };
00518 
00519 // real parameter ---------------------------------------------------
00520 
00521 class GisParaReal : public GisToken
00522 {
00523 
00524 public:
00525         double x;
00526 
00527         GisParaReal(double value = 0, mutString sep = mutEmptyString, GisToken *next = 0)
00528                         : GisToken(sep, next)
00529         {
00530                 x = value;
00531         }
00532 
00533         virtual GisType Type() const
00534         {
00535                 return GTParaReal;
00536         }
00537 
00538         virtual GisToken *Copy()
00539 
00540         {
00541                 return new GisParaReal(x, Sep, 0);
00542         }
00543 
00544 #ifndef FOR_MUTWIN
00545         virtual void Stream(ostream &out, char sep);
00546 #endif
00547 #ifdef WX
00548         virtual wxString ToString()
00549         {
00550                 return _T("GisParaReal: { ") + GisToken::ToString() +
00551                        wxString::Format(_T("x: %g }\n"),x);
00552         }
00553 
00554 #endif
00555 };
00556 
00557 // string parameter -------------------------------------------------
00558 
00559 class GisParaStr : public GisToken
00560 {
00561 
00562 public:
00563         mutString s;
00564 
00565         GisParaStr(const mutString value = mutEmptyString, mutString sep = mutEmptyString, GisToken *next = 0)
00566                         : GisToken(sep, next)
00567         {
00568                 CHECKDUP(s, value);
00569         }
00570 
00571         ~GisParaStr()
00572 
00573         {
00574 #ifdef WX
00575 #else
00576 
00577                 if ( s ) delete s;
00578 
00579 #endif
00580         }
00581 
00582         virtual GisType Type() const
00583         {
00584                 return GTParaStr;
00585         }
00586 
00587         virtual GisToken *Copy()
00588 
00589         {
00590                 return new GisParaStr(s, Sep, 0);
00591         }
00592 
00593 #ifndef FOR_MUTWIN
00594         virtual void Stream(ostream &out, mutChar sep);
00595 #endif
00596 #ifdef WX
00597         virtual wxString ToString()
00598         {
00599                 return _T("GisParaStr: { ") + GisToken::ToString() +
00600                        wxString::Format(_T("s: '%s' }\n"),s.c_str());
00601         }
00602 
00603 #endif
00604 };
00605 
00606 // comma (in chord as separator) ------------------------------------
00607 
00608 class GisComma : public GisToken
00609 {
00610 
00611 public:
00612 
00613         GisComma(const mutString sep = mutEmptyString, GisToken *next = 0)
00614                         : GisToken(sep, next)
00615         { };
00616 
00617         virtual GisType Type() const
00618         {
00619                 return GTComma;
00620         }
00621 
00622 #ifndef FOR_MUTWIN
00623         virtual void Stream(ostream &out, mutChar sep);
00624 
00625         virtual void Echo()
00626         {
00627                 cout << ", ";
00628         }
00629 
00630 #endif
00631 #ifdef WX
00632         virtual wxString ToString()
00633         {
00634                 return _T("GisComma: { ") + GisToken::ToString() +
00635                        _T(" }\n");
00636         }
00637 
00638 #endif
00639 };
00640 
00641 // ##################################################################
00642 // functions
00643 
00644 GisType GetGisType(GisToken* token);
00645 
00646 GisToken *GisParse(const mutString FileName);
00647 
00648 extern int StartSep();  // at the beginning, to get comments infront of the first token
00649 
00650 extern int BeginSegment();
00651 
00652 extern int EndSegment();
00653 
00654 extern int BeginSequenz();
00655 
00656 extern int EndSequenz();
00657 
00658 extern int BeginParameter();
00659 
00660 extern int EndParameter();
00661 
00662 extern int BeginRange();
00663 
00664 extern int EndRange();
00665 
00666 extern int NextSequenz();
00667 
00668 extern int Tag(mutString tagName);
00669 
00670 extern int TagParaInt(long i);
00671 
00672 extern int TagParaReal(double x);
00673 
00674 extern int TagParaStr(mutString s);
00675 
00676 extern int Comma();
00677 
00678 int Note(const mutString name, const mutString accedentials, int octave, frac duration);
00679 
00680 #ifdef WX
00681 wxString GISPrettyPrint(wxString s);
00682 
00683 #endif
00684 
00685 
00686 #endif
00687 
00688 

Erzeugt am Sun Aug 21 2011 10:51:53 für Mutabor von doxygen 1.7.4