Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using c++ to write c++

Using c++ to write c++

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionxmlhelplounge
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jordan C Atlas
    wrote on last edited by
    #1

    Hello, I'm interested in writing a program that reads an XML input file, and then based on the content of that file, writes another program which is then compiled. I imagine that I'd do this by defining an ofstream and literally writing the new prorgram line by line. The "preprocessing" program would look something like this: ofstream out("program.cpp"); out << "int main()" << endl; out << "{" << endl; out << "return 0;" << endl; out << "}" << endl; Where I'd have to write the relevant functions for my problem. I'd then run the proprocessing program and compile the "new" program using a batch file. My question is this: Is there a name for this type of programming? I'd like to read up about it in general before I dive in but the searches I have done haven't revealed much. Also, does MS VC++ provide any helpful methods for writing such programs? Thanks, --Jordan Atlas

    L B 2 Replies Last reply
    0
    • J Jordan C Atlas

      Hello, I'm interested in writing a program that reads an XML input file, and then based on the content of that file, writes another program which is then compiled. I imagine that I'd do this by defining an ofstream and literally writing the new prorgram line by line. The "preprocessing" program would look something like this: ofstream out("program.cpp"); out << "int main()" << endl; out << "{" << endl; out << "return 0;" << endl; out << "}" << endl; Where I'd have to write the relevant functions for my problem. I'd then run the proprocessing program and compile the "new" program using a batch file. My question is this: Is there a name for this type of programming? I'd like to read up about it in general before I dive in but the searches I have done haven't revealed much. Also, does MS VC++ provide any helpful methods for writing such programs? Thanks, --Jordan Atlas

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Its called code generation and its a pretty complex topic. Lots of high end programming tools do this. Rational Rose for example can generate code from UML models. You could look at using Lex. You could create an object model to represent the C++ entities (classes, function, variables etc etc). A program would be represented by a tree like structure of these objects. Each of these classes could construct itself from the xml and then write iteself to the stream. You could take it a step further and make this object model non language specific then apply formatting objects for the language you want (C++, c#, Java) this would mean however that your xml representation would be limited to features common to these languages.

      1 Reply Last reply
      0
      • J Jordan C Atlas

        Hello, I'm interested in writing a program that reads an XML input file, and then based on the content of that file, writes another program which is then compiled. I imagine that I'd do this by defining an ofstream and literally writing the new prorgram line by line. The "preprocessing" program would look something like this: ofstream out("program.cpp"); out << "int main()" << endl; out << "{" << endl; out << "return 0;" << endl; out << "}" << endl; Where I'd have to write the relevant functions for my problem. I'd then run the proprocessing program and compile the "new" program using a batch file. My question is this: Is there a name for this type of programming? I'd like to read up about it in general before I dive in but the searches I have done haven't revealed much. Also, does MS VC++ provide any helpful methods for writing such programs? Thanks, --Jordan Atlas

        B Offline
        B Offline
        Bob Stanneveld
        wrote on last edited by
        #3

        Hello, Is the XML file a something you can change? I mean, if you can influence the data in the XML file, it may be better to stick to scripts. You'll avoid mass complexity of generating C++ code. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

        J 1 Reply Last reply
        0
        • B Bob Stanneveld

          Hello, Is the XML file a something you can change? I mean, if you can influence the data in the XML file, it may be better to stick to scripts. You'll avoid mass complexity of generating C++ code. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

          J Offline
          J Offline
          Jordan C Atlas
          wrote on last edited by
          #4

          Hi, Thanks for the replies. The XML file is a representation of a model (variables and equations). The program that I'm trying to have it automatically write will solve the system of equations represented in the XML file. I'm trying to do this so that the (compiled) new simulation program will be faster than if I repeatedly sampled information in the XML file... --Jordan

          B 1 Reply Last reply
          0
          • J Jordan C Atlas

            Hi, Thanks for the replies. The XML file is a representation of a model (variables and equations). The program that I'm trying to have it automatically write will solve the system of equations represented in the XML file. I'm trying to do this so that the (compiled) new simulation program will be faster than if I repeatedly sampled information in the XML file... --Jordan

            B Offline
            B Offline
            Bob Stanneveld
            wrote on last edited by
            #5

            So you are doing this for performance reasons. Than scripts are probably too slow for you too. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups