Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Expander.cpp

Go to the documentation of this file.
00001 // Expander.cpp : Defines the entry point for the application.
00002 //
00003 
00008 #pragma warning(disable: 4786)
00009 
00010 #include "expandlib/expandlib-expandable.h"
00011 
00012 #include "expandlib/expandlib-vartype-bool.h"
00013 #include "expandlib/expandlib-vartype-numeric.h"
00014 #include "expandlib/expandlib-vartype-text.h"
00015 #include "expandlib/expandlib-vartype-time.h"
00016 #include "expandlib/expandlib-vartype-date.h"
00017 #include "expandlib/expandlib-vartype-list.h"
00018 
00019 #include <iostream>
00020 
00021 using namespace std;
00022 using namespace expander;
00023 
00024 #include <windows.h>
00025 #include <tchar.h>
00026 
00028 const int NUMITERATIONS=1000;
00029 
00030 #ifdef _UNICODE
00031 
00032   typedef wstring strtype;
00033 # define cout wcout
00034 #else
00035   typedef string strtype;
00036 #endif
00037 
00042 typedef expvartype_text<strtype> EVText;
00043 typedef expvartype_bool<strtype> EVBool;
00044 typedef expvartype_numeric<strtype> EVNum;
00045 typedef expvartype_time<strtype> EVTime;
00046 typedef expvartype_date<strtype> EVDate;
00047 typedef expvartype_list<strtype> EVTextList;
00049 
00050 #include "tagz.h"
00051 
00052 map<string,string> tagz_vars;
00053 
00054 const T_CHAR* my_TAGFUNC(const T_CHAR * tag,void * p);
00055 
00057 int main()
00058 {
00059     // The "expandable", class containing the "to be expanded" string (the source string), as well as a map containing commands
00060     expandable<strtype> Expje;
00061 
00062     // Destination string
00063     strtype d;
00064 
00065     // Map containing the different vars
00066     expandable<strtype>::FVarMapType vars;
00067 
00068     // Results of the expand
00069     expandresults results;
00070 
00071     // Some vars to measure the performance (not needed)
00072     LARGE_INTEGER start, end, freq;
00073 
00074     // Some example strings to play with (you need a source and destination string, these are source strings)
00075 //  Expje.set_expstr(_T("${sdate} at ${stime} - This (#if(${muted};==;true;Damn, it's muted;Luckily this isn't muted)) #if(Hallo;==;hallo;gelijk;ongelijk) is:%20100\\% music, at \\$${srate}Hz on my ${dev} in #if(${nchannels};==!;2;#if(${msg};${msg}, this is a test, ;)Stereo, yeah, that's right;#if(${nchannels};==!;1;#if(${msg};${msg} ;)Mono;#if(${nchannels};>!;2;#ltrim(${nchannels};0) channels;zero channels)))!"));
00076 //  Expje.set_expstr(_T("#if(${nchannels}==2;Stereo;Mono)"));
00077 //  Expje.set_expstr(_T("${title}"));
00078     Expje.set_expstr(_T("#if(${title};${album}\\\\\\\\${artist} - #fpad(${tracknumber};2;0) - ${title};${path} - ${filename})"));
00079 
00080     // The set of variables that is used by the first two source strings above (you need to fill the vars map)
00081 /*  vars[_T("srate")]=new EVText(_T("44100"));
00082     vars[_T("nchannels")]=new EVText(_T("2"));
00083     vars[_T("dev")]=new EVText(_T("EWS88MT"));
00084     vars[_T("msg")]=new EVText(_T(""));
00085     vars[_T("muted")]=new EVBool(_T("yes"));
00086     vars[_T("stime")]=new EVTime(_T("04:1"));
00087     vars[_T("sdate")]=new EVDate(_T("2002-07-31"));
00088 */
00089     // The set of variables that is used by the last source string above (you need to fill the vars map)
00090     vars[_T("filename")]=new EVText(_T("02 - Requiem For Evita.ape"));
00091     vars[_T("path")]=new EVText(_T("I:\\Audio\\Andrew Lloyd Webber\\Evita (Disc 1)"));
00092     vars[_T("title")]=new EVText(_T("Requiem For Evita"));
00093     vars[_T("album")]=new EVText(_T("Evita (Disc 1)"));
00094 //  vars[_T("tracknumber")]=new EVText(_T("2"));
00095     vars[_T("tracknumber")]=new EVNum(2);
00096     vars[_T("artist")]=new EVText(_T("Andrew Lloyd Webber"));
00097     // Some examples of how to use the text list type (btw, I have nothing to do with this song :)
00098 /*
00099     {
00100         vector<string> art;
00101         art.push_back(_T("Andrew Lloyd Webber"));
00102         art.push_back(_T("Jasper van de Gronde"));
00103         vars[_T("artist")]=new EVTextList(art.begin(), art.end());
00104     }
00105 *//*
00106     {
00107         _TCHAR * artists[]={_T("Andrew Lloyd Webber"),_T("Jasper van de Gronde")};
00108         vars[_T("artist")]=new EVTextList(artists, artists+(sizeof(artists)/sizeof(artists[0])));
00109     }
00110 *//*
00111     vars[_T("artist")]=new EVTextList(5,_T("Hello"));
00112 */
00113 
00114     // Just letting the user know what those ugly, escaped strings above look like in real life
00115     cout << _T("Original: ") << endl;
00116     cout << Expje.get_expstr() << endl;
00117     cout << endl;
00118 
00119     // Get the start time
00120     QueryPerformanceCounter(&start);
00121 
00122     {   // Perform some expands (at least one expand would be recommended :)
00123         for(int t=0; t<NUMITERATIONS; ++t) {
00124             d=_T("");
00125             results.Reset();
00126             Expje.expandto(d,vars,results);
00127         }
00128     }
00129 
00130     // Get the end time, as well as the frequency
00131     QueryPerformanceCounter(&end);
00132     QueryPerformanceFrequency(&freq);
00133 
00134     // Produce the output as well as some statistics (these do not count the calls made by, for example, knownvars)
00135     cout << _T("After parsing: ") << endl;
00136     cout << d << endl;
00137     cout << endl;
00138     cout << _T("Variables processed: ") << results.TotalVars() << endl;
00139     cout << _T("Variables found:     ") << results.FoundVars() << endl;
00140     cout << _T("Total duration:      ") << (double(end.QuadPart-start.QuadPart) / double(freq.QuadPart)) << endl;
00141     cout << _T("Duration per expand: ") << (double(end.QuadPart-start.QuadPart) / double(freq.QuadPart)) / double(NUMITERATIONS) << endl;
00142     cout << endl;
00143 
00144     // Don't forget to clean up!
00145     for(expandable<strtype>::FVarMapType::iterator it=vars.begin(); it!=vars.end(); ++it) {
00146         delete (*it).second;
00147     }
00148 
00149 
00150 
00151     // Now test TAGZ
00152 
00153     char * temp=NULL;
00154 
00155     tagz_vars[_T("filename")]=_T("02 - Requiem For Evita.ape");
00156     tagz_vars[_T("path")]=_T("I:\\Audio\\Andrew Lloyd Webber\\Evita (Disc 1)");
00157     tagz_vars[_T("title")]=_T("Requiem For Evita");
00158     tagz_vars[_T("album")]=_T("Evita (Disc 1)");
00159     tagz_vars[_T("tracknumber")]="2";
00160     tagz_vars[_T("artist")]=_T("Andrew Lloyd Webber");
00161 
00162     // Get the start time
00163     QueryPerformanceCounter(&start);
00164 
00165     {   // Perform some expands (at least one expand would be recommended :)
00166         for(int t=0; t<NUMITERATIONS; ++t) {
00167             if ( temp ) free(temp);
00168             temp=tagz_format_r("$if(%title%,%album%\\\\\\\\%artist% - $num(%tracknumber%,2) - %title%,%path% - %filename%)",my_TAGFUNC,NULL,NULL);
00169         }
00170     }
00171 
00172     // Get the end time, as well as the frequency
00173     QueryPerformanceCounter(&end);
00174     QueryPerformanceFrequency(&freq);
00175 
00176     // Produce the output as well as some statistics (these do not count the calls made by, for example, knownvars)
00177     cout << _T("After parsing: ") << endl;
00178     cout << temp << endl;
00179     cout << endl;
00180     cout << _T("Total duration:      ") << (double(end.QuadPart-start.QuadPart) / double(freq.QuadPart)) << endl;
00181     cout << _T("Duration per expand: ") << (double(end.QuadPart-start.QuadPart) / double(freq.QuadPart)) / double(NUMITERATIONS) << endl;
00182     cout << endl;
00183 
00184     free(temp);
00185 
00186 
00187     return 0;
00188 }
00189 
00190 
00191 const T_CHAR* my_TAGFUNC(const T_CHAR * tag,void * p)
00192 {
00193     return tagz_vars[tag].c_str();
00194 }

Generated on Tue Feb 4 17:24:13 2003 for ExpandLib by doxygen1.3-rc2