From: Jens Thiele Date: Mon, 27 Nov 2006 11:59:29 +0000 (+0000) Subject: use seperate file for group X-Git-Tag: v0.2~97 X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=commitdiff_plain;h=a96ab6288873059274d783980f70899e24bb46ce use seperate file for group --- diff --git a/codegen/main.cpp b/codegen/main.cpp index a8580ba..517d14f 100644 --- a/codegen/main.cpp +++ b/codegen/main.cpp @@ -219,7 +219,7 @@ std::ostream &operator<<(std::ostream &o, const t2n_procedure &f) { class Parser { public: - Parser(const std::string &fname) : m_fname(fname) {} + Parser(const std::string &fname, const std::string &group) : m_fname(fname), m_group(group) {} std::list get_procedures() { xmlpp::DomParser parser; @@ -238,6 +238,7 @@ public: } protected: std::string m_fname; + std::string m_group; std::list m_procedures; void parse_function(const xmlpp::Element* root, const xmlpp::Node* node) { @@ -257,7 +258,7 @@ protected: f.group=extract_group(attributes->get_value()); if (f.group.empty()) return; // todo: handle default group - if (f.group=="default") f.group=get_default_group(root); + if (f.group=="default") f.group=m_group; // we need the return type f.ret_type=get_type(root, returns->get_value()); @@ -473,6 +474,14 @@ void output_client_cpp(std::ostream &o, const std::list &procs, c o << "#include \"" << common_cpp << "\"\n"; } +void output_server_hpp(std::ostream &o, const std::list &procs, const std::string &common_hpp) { + o << "#include \"" << common_hpp << "\"\n"; + + // output function declarations + for (std::list::const_iterator it=procs.begin();it!=procs.end();++it) + o << *it << ";\n"; +} + void output_server_cpp(std::ostream &o, const std::list &procs, const std::string &common_hpp, const std::string &common_cpp) { o << "#include \"" << common_hpp << "\"\n"; @@ -548,21 +557,22 @@ int main(int argc, char* argv[]) { if (argc != 4) { - std::cerr << "Usage: " << argv[0] << " header-file gccxml-file outputprefix" << std::endl; + std::cerr << "Usage: " << argv[0] << " header-file gccxml-file group" << std::endl; return 1; } try{ std::string headerfile(argv[1]); std::string xmlfile(argv[2]); - std::string prefix(argv[3]); + std::string group(argv[3]); + std::string prefix=group+"_"; std::list includes(get_includes(headerfile)); 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); - Parser parser(xmlfile); + Parser parser(xmlfile, group); std::list procedures(parser.get_procedures()); std::cerr << "Procedures:" << std::endl; @@ -578,6 +588,7 @@ main(int argc, char* argv[]) std::string common_cpp_fname(prefix+"common.cpp"); std::string client_hpp_fname(prefix+"client.hxx"); std::string client_cpp_fname(prefix+"client.cpp"); + std::string server_hpp_fname(prefix+"server.hxx"); std::string server_cpp_fname(prefix+"server.cpp"); header_file common_hpp(common_hpp_fname.c_str()); @@ -599,6 +610,9 @@ main(int argc, char* argv[]) cpp_file client_cpp(client_cpp_fname.c_str()); output_client_cpp(client_cpp, procedures, common_hpp_fname, common_cpp_fname, client_hpp_fname); + header_file server_hpp(server_hpp_fname.c_str()); + output_server_hpp(server_hpp, procedures, common_hpp_fname); + cpp_file server_cpp(server_cpp_fname.c_str()); output_server_cpp(server_cpp, procedures, common_hpp_fname, common_cpp_fname); }catch(const parse_error &e){ diff --git a/example-codegen/Makefile.am b/example-codegen/Makefile.am index 5deff2e..b11e881 100644 --- a/example-codegen/Makefile.am +++ b/example-codegen/Makefile.am @@ -2,23 +2,30 @@ INCLUDES = -I$(top_srcdir)/src @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@ -I$(top_srcdir) LDADD = $(top_builddir)/src/libt2n.la @BOOST_SERIALIZATION_LIB@ @BOOST_LDFLAGS@ -libclient_la_SOURCES = codegen_client.cpp -noinst_LTLIBRARIES = libclient.la +libdefault_la_SOURCES = default_client.cpp +libother_la_SOURCES = other_client.cpp +noinst_LTLIBRARIES = libdefault.la libother.la client_SOURCES = client.cpp -client_LDADD = $(LDADD) libclient.la +client_LDADD = $(LDADD) libdefault.la libother.la -server_SOURCES = server.cpp codegen_server.cpp foo.hxx +server_SOURCES = server.cpp other_server.cpp default_server.cpp other.cpp default.cpp foo.hxx noinst_PROGRAMS = client server -codegen.stamp: server.hxx $(top_builddir)/codegen/codegen - cp $(top_srcdir)/codegen/codegen-stubhead.hxx codegen_common.hxx -# todo use tmp file for server.xml - gccxml $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $< -fxml=server.xml - $(top_builddir)/codegen/codegen $< server.xml codegen_ - touch $@ - -codegen_common.hxx codegen_common.cpp codegen_client.hxx codegen_client.cpp codegen_server.cpp: codegen.stamp +codegen.stamp: default.cpp other.cpp $(top_builddir)/codegen/codegen +# assuming we have some unix like shell + for i in default other; do \ + cp -v $(top_srcdir)/codegen/codegen-stubhead.hxx $${i}_common.hxx; \ + cp -v $(top_srcdir)/codegen/codegen-stubhead.hxx $${i}_server.hxx; \ + done +# todo use tmp file for xml file + for i in default other; do \ + gccxml $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $${i}.cpp -fxml=$${i}.xml; \ + $(top_builddir)/codegen/codegen $${i}.cpp $${i}.xml $${i}; \ + done; touch $@ + +default_common.hxx default_common.cpp default_client.hxx default_client.cpp default_server.hxx default_server.cpp: codegen.stamp +other_common.hxx other_common.cpp other_client.hxx other_client.cpp other_server.hxx other_server.cpp: codegen.stamp TESTS = test diff --git a/example-codegen/client.cpp b/example-codegen/client.cpp index 008d9e1..cdeb124 100644 --- a/example-codegen/client.cpp +++ b/example-codegen/client.cpp @@ -7,7 +7,8 @@ #include // include library header -#include "codegen_client.hxx" +#include "default_client.hxx" +#include "other_client.hxx" int main(int argc, char** argv) { diff --git a/example-codegen/default.cpp b/example-codegen/default.cpp new file mode 100644 index 0000000..38b936b --- /dev/null +++ b/example-codegen/default.cpp @@ -0,0 +1,43 @@ +#include +// serialization of string +#include +// serialization of pair +#include + +// std::vector +#include +#include + +#include "default_common.hxx" + +//! test pass by copy +LIBT2N_EXPORT std::string testfunc(std::string str) +{ + std::string ret; + if (str=="throw") + throw libt2n::t2n_runtime_error("throw me around"); + if (str=="big") + ret.insert(0,100*1024,'x'); + else + ret=str+", testfunc() was here"; + return ret; +} + +//! test pass by const reference +LIBT2N_EXPORT std::string testfunc_ref(const std::string &str) +{ + std::string ret; + if (str=="throw") + throw libt2n::t2n_runtime_error("throw me around"); + if (str=="big") + ret.insert(0,100*1024,'x'); + else + ret=str+", testfunc() was here"; + return ret; +} + +//! test builtin type +LIBT2N_EXPORT int t2(int i) +{ + return i; +} diff --git a/example-codegen/other.cpp b/example-codegen/other.cpp new file mode 100644 index 0000000..c84fcdc --- /dev/null +++ b/example-codegen/other.cpp @@ -0,0 +1,39 @@ +#include +// serialization of string +#include +// serialization of pair +#include + +// std::vector +#include +#include + +#include "foo.hxx" + +#include "other_common.hxx" + +using namespace std; + +//! test function overload +LIBT2N_EXPORT int t3(int i) +{ + return i; +} + +//! test pair, multiple arguments and namespace +LIBT2N_EXPORT bool t3(int i, float f, const string &s, const pair &p) +{ + return (i==p.first) && (f==p.second) && (s=="hello"); +} + +//! test std::vector +LIBT2N_EXPORT bool t3(const std::vector &i) +{ + return (i.size()==1) && (i[0]==10); +} + +//! test own type +LIBT2N_EXPORT bool t3(const Foo &foo) +{ + return (foo.i==foo.j); +} diff --git a/example-codegen/server.cpp b/example-codegen/server.cpp index 1931ab8..4c96d97 100644 --- a/example-codegen/server.cpp +++ b/example-codegen/server.cpp @@ -1,15 +1,11 @@ #include #include -#include "server.hxx" +#include "default_server.hxx" +#include "other_server.hxx" using namespace libt2n; -bool t3(const Foo &foo) -{ - return (foo.i==foo.j); -} - int main(int argc, char** argv) { socket_server ss("./socket"); diff --git a/example-codegen/server.hxx b/example-codegen/server.hxx deleted file mode 100644 index 16068a0..0000000 --- a/example-codegen/server.hxx +++ /dev/null @@ -1,70 +0,0 @@ -#include -// serialization of string -#include -// serialization of pair -#include - -// std::vector -#include -#include - -#include "foo.hxx" - -#include "codegen_common.hxx" - -LIBT2N_SET_DEFAULTGROUP(default); - -//! test pass by copy -LIBT2N_EXPORT std::string testfunc(std::string str) -{ - std::string ret; - if (str=="throw") - throw libt2n::t2n_runtime_error("throw me around"); - if (str=="big") - ret.insert(0,100*1024,'x'); - else - ret=str+", testfunc() was here"; - return ret; -} - -//! test pass by const reference -LIBT2N_EXPORT std::string testfunc_ref(const std::string &str) -{ - std::string ret; - if (str=="throw") - throw libt2n::t2n_runtime_error("throw me around"); - if (str=="big") - ret.insert(0,100*1024,'x'); - else - ret=str+", testfunc() was here"; - return ret; -} - -//! test builtin type -LIBT2N_EXPORT int t2(int i) -{ - return i; -} - -using namespace std; - -//! test pair, multiple arguments and namespace -LIBT2N_EXPORT_GROUP(other) bool t3(int i, float f, const string &s, const pair &p) -{ - return (i==p.first) && (f==p.second) && (s=="hello"); -} - -//! test function overload -LIBT2N_EXPORT_GROUP(other) int t3(int i) -{ - return i; -} - -//! test std::vector -LIBT2N_EXPORT_GROUP(other) bool t3(const std::vector &i) -{ - return (i.size()==1) && (i[0]==10); -} - -//! test own type and seperate declaration and definition -LIBT2N_EXPORT_GROUP(other) bool t3(const Foo &foo);