Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

generateFactory.cpp

Go to the documentation of this file.
00001 
00023 #include <fstream.h>
00024 #include <iostream.h>
00025 #include <string.h>
00026 #include "vuString.h"
00027 #include "vuDVector.h"
00028 
00029 typedef vuDVector<vuString> StringList;
00030 
00031 //The following write different parts of the vuUtilityFactory.cpp file
00032 
00034 void writeComment(ofstream &fout,const StringList &list);
00036 void writeIncludes(ofstream &fout,const StringList &list);
00038 void writeCreate(ofstream &fout,const StringList &list);
00040 void writeIsAvailable(ofstream &fout,const StringList &list);
00042 void writeListAvailable(ofstream &fout,const StringList &list);
00044 vuString stripExt(const char *name);
00046 const char *stripPath(const char *name);
00047 
00048 //----------------------------------------------------------------------------
00049 //------------------------- The main program ---------------------------------
00050 //----------------------------------------------------------------------------
00051 
00052 int main(int argc, char* argv[])
00053 {
00054         //Make sure that command line parameters were passed
00055     if (argc == 1)
00056     {
00057         cout << "Error: No output file specified.  vuUtilityFactory.cpp not created.\n";
00058         return -1;
00059     }
00060     else if (argc == 2)
00061     {
00062         cout << "Error: No utilities were listed.  vuUtilityFactory.cpp not created.\n";
00063         return -1;
00064     }
00065 
00066     //Open the output file, truncating/replacing it if it exists
00067     ofstream fout(argv[1]);
00068     
00069     //Make a string list out of the arguments
00070     StringList list;    
00071     for (int i=2;i< argc;i++)
00072         list.add(stripExt(argv[i]));
00073     
00074     //Now write the class file
00075     writeComment(fout,list);
00076     writeIncludes(fout,list);
00077     writeCreate(fout,list);
00078     writeIsAvailable(fout,list);
00079     writeListAvailable(fout,list);
00080     
00081     fout.close();
00082     cout.flush();
00083     return 0;
00084 };
00085 
00086 
00087 //----------------------------------------------------------------------------
00088 //------------------------- void writeComment() ------------------------------
00089 //----------------------------------------------------------------------------
00090 
00091 void writeComment(ofstream &fout,const StringList &list)
00093 {
00094     fout << "//This implementation file was generated by the GenerateFactory utility.\n\n";
00095     fout << "//The utilities supported by this implementation are:\n";
00096     for (dword i=0; i < list.getLength() ;i++)
00097         fout << "//    " << list[i] << "\n";
00098     fout << "\n";
00099 }
00100 
00101 //----------------------------------------------------------------------------
00102 //------------------------- void writeIncludes() -----------------------------
00103 //----------------------------------------------------------------------------
00104 
00105 void writeIncludes(ofstream &fout,const StringList &list)
00107     //The command line parameters are passed to the function and list the utilities
00108     //that the class will create.
00109 {
00110     fout << "#include \"vuUtilityFactory.h\"\n";
00111     for (dword i = 0; i < list.getLength(); i++)
00112         fout << "#include \"wxUtilities/" << list[i] << "/" << list[i] << ".h\"\n";
00113     fout << "\n";
00114 }
00115 
00116 //----------------------------------------------------------------------------
00117 //------------------------- void writeCreate() -------------------------------
00118 //----------------------------------------------------------------------------
00119 
00120 void writeCreate(ofstream &fout,const StringList &list)
00122     //The command line parameters are passed to the function and list the 
00123     //utilities that the class will create.
00124 {
00125     fout << "vuUtilityWindow *vuUtilityFactory::create(const char *name)\n";
00126     fout << "{\n";
00127     fout << "    vuUtilityWindow *window=0;\n\n";
00128 
00129     for (dword i = 0; i < list.getLength() ; i++)
00130     {
00131         if (i == 0)
00132             fout << "    if ";
00133         else
00134             fout << "    else if ";
00135         fout << "(strcmp(name,\"" << stripPath(list[i]) << "\")==0)\n"
00136              << "        window = new " << stripPath(list[i]) << "();\n";
00137     };
00138     fout << "\n    return window;\n}\n\n";
00139 };
00140 
00141 //----------------------------------------------------------------------------
00142 //------------------------- void writeIsAvailable() --------------------------
00143 //----------------------------------------------------------------------------
00144 
00145 void writeIsAvailable(ofstream &fout,const StringList &list)
00147     //The command line parameters are passed to the function and list the 
00148     //utilities that the class can create.
00149 {
00150     fout << "bool vuUtilityFactory::isAvailable(const char *name)\n";
00151     fout << "{\n";
00152 
00153     for (dword i = 0; i < list.getLength(); i++)
00154     {
00155         if (i == 0)
00156             fout << "    if ";
00157         else
00158             fout << "    else if ";
00159         fout << "(strcmp(name,\"" << stripPath(list[i]) << "\")==0)\n";
00160         fout << "        return true;\n";
00161     };
00162     fout << "    else\n        return false;\n}\n\n";
00163 };
00164 
00165 //----------------------------------------------------------------------------
00166 //------------------------- void writeListAvailable() ------------------------
00167 //----------------------------------------------------------------------------
00168 
00169 void writeListAvailable(ofstream &fout,const StringList &list)
00171     //The command line parameters are passed to the function and list the 
00172     //utilities that the class can create.
00173 {
00174     fout << "wxStringList vuUtilityFactory::listAvailable(const char* FileType)\n{\n";
00175     fout << "    wxStringList utilities;\n\n";
00176     for (dword i = 0; i < list.getLength(); i++)
00177         fout << "    if (strcmp(" << stripPath(list[i]) << "::getFileType(),FileType)==0)\n"
00178              << "        utilities.Add(\"" << stripPath(list[i]) << "\");\n";
00179 
00180     fout << "\n    return utilities;\n}\n\n";
00181 };
00182 
00183 //----------------------------------------------------------------------------
00184 //------------------------- vuString stripExt() -------------------------------
00185 //----------------------------------------------------------------------------
00186 
00187 vuString stripExt(const char *name)
00189 {
00190     vuString Name = name;
00191     dword length = Name.getLength();
00192     if ((name[length-2]=='.') && (name[length-1]=='o'))
00193         return Name.substr(0,length-3);
00194     else
00195         return Name;
00196 };
00197 
00198 //----------------------------------------------------------------------------
00199 //------------------------- vuString stripPath() -------------------------------
00200 //----------------------------------------------------------------------------
00201 
00202 const char* stripPath(const char *file)
00204 {
00205     const char *name=strrchr(file,'\\');
00206     if (name==NULL) name = strrchr(file,'/');
00207     if (name==NULL) name = file;
00208     else name++;
00209     return name;
00210 };

Generated on Wed Dec 15 21:20:28 2004 for vuVolume by  doxygen 1.3.9.1