put include dependencies into seperate file (one file per command group). simplifies...
authorJens Thiele <jens.thiele@intra2net.com>
Tue, 28 Nov 2006 10:30:59 +0000 (10:30 +0000)
committerJens Thiele <jens.thiele@intra2net.com>
Tue, 28 Nov 2006 10:30:59 +0000 (10:30 +0000)
codegen/main.cpp
example-codegen/Makefile.am
example-codegen/default.cpp
example-codegen/default.hxx [new file with mode: 0644]
example-codegen/other-1.cpp
example-codegen/other-2.cpp
example-codegen/other.cpp
example-codegen/other.hxx [new file with mode: 0644]

index ee70fb1..85c56eb 100644 (file)
@@ -496,62 +496,21 @@ struct cpp_file : public std::ofstream
      }
 };
 
-std::list<std::string>
-get_includes(const std::string &fname)
-{
-     // grep "#include" fname
-     std::ifstream in(fname.c_str());
-     std::string line;
-     std::list<std::string> ret;
-     while (std::getline(in,line)) {
-         if (line.find("#include")!=std::string::npos)
-              ret.push_back(line);
-     }
-     return ret;
-}
-
-void
-paste_includes(std::ostream &o, std::list<std::string> &i)
-{
-     o << std::endl
-       << "// copied includes begin" << std::endl;
-     for (std::list<std::string>::const_iterator it=i.begin(); it!=i.end(); ++it)
-         o << *it << std::endl;
-     o << "// copied includes end" << std::endl
-       << std::endl;
-}
-
-struct RemoveGenerated
-{
-     RemoveGenerated(const std::string &_prefix) : prefix(_prefix) {}
-     bool operator()(const std::string &s) const {
-         return (s.find(prefix+"common.hxx")!=std::string::npos);
-     }
-     const std::string &prefix;
-};
-
 int
 main(int argc, char* argv[])
 {
-     if (argc < 4) {
-         std::cerr << "Usage: " << argv[0] << " export-file default-group gccxml-file1 gccxml-file2 ... " << std::endl;
+     if (argc < 3) {
+         std::cerr << "Usage: " << argv[0] << "default-group gccxml-file1 gccxml-file2 ... " << std::endl;
          return 1;
      }
 
      try{
-         std::string exportfile(argv[1]);
-         std::string group(argv[2]);
+         std::string group(argv[1]);
          std::list<std::string> xmlfiles;
-         for (unsigned i=3;i<argc;++i)
+         for (int i=2;i<argc;++i)
            xmlfiles.push_back(argv[i]);
 
          std::string prefix=group+"_";
-         std::list<std::string> includes(get_includes(exportfile));
-         remove_if(includes.begin(), includes.end(), RemoveGenerated(prefix));
-         includes.erase(remove_if(includes.begin(), includes.end(), RemoveGenerated(prefix)), includes.end());
-
-         //paste_includes(std::cerr, includes);
-  
          std::list<t2n_procedure> procedures;
          for (std::list<std::string>::iterator it=xmlfiles.begin();it!=xmlfiles.end();++it) {
            Parser parser(*it, group);
@@ -577,9 +536,9 @@ main(int argc, char* argv[])
 
          header_file common_hpp(common_hpp_fname.c_str());
          common_hpp << "// boost serialization is picky about order of include files => we have to include this one first\n"
-                    << "#include \"codegen-stubhead.hxx\"\n";
-         paste_includes(common_hpp, includes);
-              
+                    << "#include \"codegen-stubhead.hxx\"\n"
+                    << "#include \"" << group << ".hxx\"\n";
+
          output_common_hpp(common_hpp, procedures);
 
          cpp_file common_cpp(common_cpp_fname.c_str());
@@ -587,8 +546,8 @@ main(int argc, char* argv[])
 
          header_file client_hpp(client_hpp_fname.c_str());
          client_hpp << "// boost serialization is picky about order of include files => we have to include this one first\n"
-                    << "#include \"codegen-stubhead.hxx\"\n";
-         paste_includes(client_hpp, includes);
+                    << "#include \"codegen-stubhead.hxx\"\n"
+                    << "#include \"" << group << ".hxx\"\n";
          output_client_hpp(client_hpp, procedures);
 
          cpp_file client_cpp(client_cpp_fname.c_str());
index d4dae59..db45e0c 100644 (file)
@@ -45,7 +45,7 @@ GROUPDEP_FILES =  $(foreach i, $(CMDGROUPS), .deps/group_$(i).P)
        for i in $($*_GROUP); do \
                gccxml $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $${i} -fxml=$${i%*.cpp}.xml; \
        done; \
-       $(top_builddir)/codegen/codegen $*.cpp $* $($*_GROUP:.cpp=.xml) && touch $@
+       $(top_builddir)/codegen/codegen $* $($*_GROUP:.cpp=.xml) && touch $@
 
 # assuming we have gnu make?
 BUILT_SOURCES = $(foreach i, $(CMDGROUPS), $(foreach j, _common.hxx _common.cpp _client.hxx _client.cpp _server.hxx _server.cpp, $(i)$(j)) )
index 38b936b..7cc63b7 100644 (file)
@@ -1,14 +1,4 @@
-#include <string>
-// serialization of string
-#include <boost/serialization/string.hpp>
-// serialization of pair
-#include <boost/serialization/utility.hpp>
-
-// std::vector
-#include <vector>
-#include <boost/serialization/vector.hpp>
-
-#include "default_common.hxx"
+#include "default.hxx"
 
 //! test pass by copy
 LIBT2N_EXPORT std::string testfunc(std::string str) 
diff --git a/example-codegen/default.hxx b/example-codegen/default.hxx
new file mode 100644 (file)
index 0000000..34e71a5
--- /dev/null
@@ -0,0 +1,11 @@
+#include <string>
+// serialization of string
+#include <boost/serialization/string.hpp>
+// serialization of pair
+#include <boost/serialization/utility.hpp>
+
+// std::vector
+#include <vector>
+#include <boost/serialization/vector.hpp>
+
+#include "default_common.hxx"
index 568082d..3d50946 100644 (file)
@@ -1,17 +1,4 @@
-#include <string>
-// serialization of string
-#include <boost/serialization/string.hpp>
-// serialization of pair
-#include <boost/serialization/utility.hpp>
-
-// std::vector
-#include <vector>
-#include <boost/serialization/vector.hpp>
-
-#include "foo.hxx"
-
-#include "other_common.hxx"
-
+#include "other.hxx"
 using namespace std;
 
 //! test function overload
index 05ccc4b..f67f0b8 100644 (file)
@@ -1,18 +1,4 @@
-#include <string>
-// serialization of string
-#include <boost/serialization/string.hpp>
-// serialization of pair
-#include <boost/serialization/utility.hpp>
-
-// std::vector
-#include <vector>
-#include <boost/serialization/vector.hpp>
-
-#include "foo.hxx"
-
-#include "other_common.hxx"
-
-using namespace std;
+#include "other.hxx"
 
 //! test own type
 LIBT2N_EXPORT bool t3(const Foo &foo)
index 4121f04..e69de29 100644 (file)
@@ -1,13 +0,0 @@
-#include <string>
-// serialization of string
-#include <boost/serialization/string.hpp>
-// serialization of pair
-#include <boost/serialization/utility.hpp>
-
-// std::vector
-#include <vector>
-#include <boost/serialization/vector.hpp>
-
-#include "foo.hxx"
-
-#include "other_common.hxx"
diff --git a/example-codegen/other.hxx b/example-codegen/other.hxx
new file mode 100644 (file)
index 0000000..4121f04
--- /dev/null
@@ -0,0 +1,13 @@
+#include <string>
+// serialization of string
+#include <boost/serialization/string.hpp>
+// serialization of pair
+#include <boost/serialization/utility.hpp>
+
+// std::vector
+#include <vector>
+#include <boost/serialization/vector.hpp>
+
+#include "foo.hxx"
+
+#include "other_common.hxx"