00001
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
00060 expandable<strtype> Expje;
00061
00062
00063 strtype d;
00064
00065
00066 expandable<strtype>::FVarMapType vars;
00067
00068
00069 expandresults results;
00070
00071
00072 LARGE_INTEGER start, end, freq;
00073
00074
00075
00076
00077
00078 Expje.set_expstr(_T("#if(${title};${album}\\\\\\\\${artist} - #fpad(${tracknumber};2;0) - ${title};${path} - ${filename})"));
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
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
00095 vars[_T("tracknumber")]=new EVNum(2);
00096 vars[_T("artist")]=new EVText(_T("Andrew Lloyd Webber"));
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 cout << _T("Original: ") << endl;
00116 cout << Expje.get_expstr() << endl;
00117 cout << endl;
00118
00119
00120 QueryPerformanceCounter(&start);
00121
00122 {
00123 for(int t=0; t<NUMITERATIONS; ++t) {
00124 d=_T("");
00125 results.Reset();
00126 Expje.expandto(d,vars,results);
00127 }
00128 }
00129
00130
00131 QueryPerformanceCounter(&end);
00132 QueryPerformanceFrequency(&freq);
00133
00134
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
00145 for(expandable<strtype>::FVarMapType::iterator it=vars.begin(); it!=vars.end(); ++it) {
00146 delete (*it).second;
00147 }
00148
00149
00150
00151
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
00163 QueryPerformanceCounter(&start);
00164
00165 {
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
00173 QueryPerformanceCounter(&end);
00174 QueryPerformanceFrequency(&freq);
00175
00176
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 }