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<t2n_procedure> get_procedures() {
xmlpp::DomParser parser;
}
protected:
std::string m_fname;
+ std::string m_group;
std::list<t2n_procedure> m_procedures;
void parse_function(const xmlpp::Element* root, const xmlpp::Node* node) {
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());
o << "#include \"" << common_cpp << "\"\n";
}
+void output_server_hpp(std::ostream &o, const std::list<t2n_procedure> &procs, const std::string &common_hpp) {
+ o << "#include \"" << common_hpp << "\"\n";
+
+ // output function declarations
+ for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it)
+ o << *it << ";\n";
+}
+
void output_server_cpp(std::ostream &o, const std::list<t2n_procedure> &procs, const std::string &common_hpp, const std::string &common_cpp) {
o << "#include \"" << common_hpp << "\"\n";
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<std::string> 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<t2n_procedure> procedures(parser.get_procedures());
std::cerr << "Procedures:" << std::endl;
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());
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){
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
#include <socket_client.hxx>
// include library header
-#include "codegen_client.hxx"
+#include "default_client.hxx"
+#include "other_client.hxx"
int main(int argc, char** argv)
{
--- /dev/null
+#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"
+
+//! 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;
+}
--- /dev/null
+#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;
+
+//! 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<int, float> &p)
+{
+ return (i==p.first) && (f==p.second) && (s=="hello");
+}
+
+//! test std::vector
+LIBT2N_EXPORT bool t3(const std::vector<int> &i)
+{
+ return (i.size()==1) && (i[0]==10);
+}
+
+//! test own type
+LIBT2N_EXPORT bool t3(const Foo &foo)
+{
+ return (foo.i==foo.j);
+}
#include <socket_server.hxx>
#include <command_server.hxx>
-#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");
+++ /dev/null
-#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 "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<int, float> &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<int> &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);