///////////////////////////////////////////////////////////////////////// // GenProj.cpp - demonstrates how to build project file from template // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2012 // // - Starts with a template project which is a copy of an appropriate // project generated by visual studio, with all of the compiled and // included files replaced with a single dummy placeholder for each // // - This demo then replaces the place holder with an element for a // cpp file and an element for an h file, just to demonstrate how to // do that. At that place you need to insert your code to save // elements for all your cpp files and elements for all your h files. #include #include #include #include "XmlReader.h" #include "XmlWriter.h" //----< read all text from the in stream into a returned string >-------- std::string ReadToEnd(std::ifstream& in) { std::string temp; while(in.good()) { temp += in.get(); } return temp; } //----< process template file to generate new project file >------------- int main() { // the template is a copy of GenProj.vcxproj with all the cpp files // and h files replaced with dummy elements const std::string testfile = "template.vcxproj"; std::ifstream in(testfile); if(!in.good()) { std::cout << "\n could not open file \"" << testfile << "\"\n\n"; return 1; } std::string xmlStr = ReadToEnd(in); XmlReader rdr(xmlStr); // - find template's element // and replace with elements // - find template's element // and replace with elements // // - in this demo we will only do one substition for each while(rdr.next()) { if(rdr.tag() == "ClCompile") { // does this element have "Include" attribute size_t start = rdr.position() - 1; if((rdr.attributes().size() == 0) || (rdr.attributes()[0].first != "Include")) continue; size_t end = xmlStr.find("/>",start) + 2; rdr.position(start); // here's where you insert your cpp files std::string dummyCpp = ""; xmlStr = xmlStr.replace(start,end-start,dummyCpp.c_str()); //std::cout << "\n" << xmlStr.c_str() << "\n\n"; //return 1; rdr.next(); } else if(rdr.tag() == "ClInclude") { // does this element have "Include" attribute size_t start = rdr.position() - 1; if((rdr.attributes().size() == 0) || (rdr.attributes()[0].first != "Include")) continue; size_t end = xmlStr.find("/>",start) + 2; rdr.position(start); // here's where you insert your h files std::string dummyCpp = ""; xmlStr = xmlStr.replace(start,end-start,dummyCpp.c_str()); //std::cout << "\n" << xmlStr.c_str() << "\n\n"; //return 1; rdr.next(); } } // Here, you should open an output file, and write xmlStr into it // to create your new project file. std::cout << "\n" << xmlStr.c_str() << "\n\n"; }