You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ag...@apache.org on 2007/07/17 19:50:21 UTC
svn commit: r556989 - in /incubator/tuscany/cpp/sdo/runtime/core:
src/commonj/sdo/DataFactory.h src/commonj/sdo/DataFactoryImpl.cpp
src/commonj/sdo/DataFactoryImpl.h test/sdotest.h test/sdotest2.cpp
Author: agrove
Date: Tue Jul 17 10:50:18 2007
New Revision: 556989
URL: http://svn.apache.org/viewvc?view=rev&rev=556989
Log:
removed static code generation from C++ code base
Modified:
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactory.h
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h
incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h
incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactory.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactory.h?view=diff&rev=556989&r1=556988&r2=556989
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactory.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactory.h Tue Jul 17 10:50:18 2007
@@ -173,18 +173,6 @@
bool isRestriction = false) = 0;
- /**
- * Generate a typesafe interface for a given data factory
- * test code.
- */
-
- virtual SDO_API bool generateInterface(const char* fileroot,
- const char *factoryname) = 0;
-
- virtual SDO_API bool generateInterface(const SDOString& fileroot,
- const SDOString& factoryname) = 0;
-
-
/**
* DataFactory::setAlias sets an alternative name
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp?view=diff&rev=556989&r1=556988&r2=556989
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp Tue Jul 17 10:50:18 2007
@@ -1664,472 +1664,6 @@
}
-bool DataFactoryImpl::generateInterface(const char* fileroot, const char* factoryname)
-{
-
- FILE* header;
- FILE* body;
-
- if ((fileroot == 0) || (strlen(fileroot) == 0)) return false;
-
- if (factoryname == 0 || (strlen(factoryname) == 0)) return false;
-
-
- char *headername = new char[strlen(fileroot) + 5];
- char *bodyname = new char[strlen(fileroot) + 5];
- strcpy(headername,fileroot);
- strcpy(bodyname,fileroot);
- strcat(headername,".h");
- strcat(bodyname,".cpp");
-
- // here we should check the files - and if they are present with
- // contents we should read them, and merge the new generated code
- // I think the way to do that is to allow sections in between comment
- // pairs in three locations:
- // a) outside any method in the CPP file.
- // b) in the header file anywhere.
- // c) inside method definitions in cpp, either before, or after the
- // entire generated contents.
- //
- //
-
- header = fopen(headername,"w+");
- if (header == 0) return false;
-
- body = fopen(bodyname,"w+");
- if (body == 0) return false;
-
-
- fprintf(header,"/*******************************************\n");
- fprintf(header," * Generated Typesafe Interface Header *\n");
- fprintf(header," *******************************************/\n\n\n");
- fprintf(header,"#include \"commonj/sdo/SDO.h\"\n");
- fprintf(header,"using namespace commonj::sdo;\n\n\n");
-
- fprintf(body,"/*******************************************\n");
- fprintf(body," * Generated Typesafe Interface Body *\n");
- fprintf(body," *******************************************/\n\n\n");
- fprintf(body,"#include \"%s\"\n",headername);
- fprintf(body,"using namespace commonj::sdo;\n\n\n");
-
- delete headername;
- delete bodyname;
-
- try {
-
- int nscount;
-
- TypeList tl = getTypes();
-
- // forward declarations and smart pointers
-
- fprintf(header,"/*******************************************\n");
- fprintf(header," * Forward declarations and smart pointers *\n");
- fprintf(header," *******************************************/\n\n\n");
-
- unsigned int i;
- for (i=0;i<tl.size();i++)
- {
- nscount = 0;
-
- if (!strcmp(tl[i].getURI(),"commonj.sdo")) continue;
-
- const char *uri = tl[i].getURI();
- char *c = (char*)strchr(uri,'.');
-
- if (c == 0)
- {
- fprintf(header,"namespace %s{\n",uri);
- nscount = 1;
- }
- else
- {
- char* buf = new char[strlen(uri) + 1];
- strcpy(buf, uri);
- c = buf;
- char* c1;
- do {
- c1 = strchr(c,'.');
- if (c1) *c1 = 0;
- fprintf(header,"namespace %s{\n", c);
- nscount++;
- if (c1) c = c1+1;
- } while (c1 != 0);
- delete buf;
- }
-
- const char* name = tl[i].getName();
-
- fprintf(header," class %s;\n",name);
- fprintf(header," typedef RefCountingPointer<%s> %sPtr;\n",
- name, name);
-
- for (int i=0;i<nscount;i++)
- {
- fprintf(header,"}\n");
- }
- }
- fprintf(header,"\n\n");
- fprintf(header,"/*******************************************\n");
- fprintf(header," * The Data factory *\n");
- fprintf(header," *******************************************/\n\n\n");
-
- fprintf(header,"class %sDataFactory {\n", factoryname);
- fprintf(header," public:\n");
- fprintf(header," static %sDataFactory* get%sDataFactory();\n",
- factoryname, factoryname);
-
- for (i=0;i<tl.size();i++)
- {
-
- if (!strcmp(tl[i].getURI(),"commonj.sdo")) continue;
-
- const char *uri = tl[i].getURI();
- const char *name = tl[i].getName();
- char* the_uri = (char*) strchr(uri,'.');
-
- if (the_uri == 0)
- {
- the_uri = new char[strlen(uri) + 1];
- strcpy(the_uri,uri);
- }
- else
- {
- the_uri = new char[2 * strlen(uri) + 1];
- int jj=0;
- for (unsigned int ii=0;ii<strlen(uri);ii++)
- {
- if (uri[ii] == '.')
- {
- the_uri[jj++]=':';
- the_uri[jj++]=':';
- }
- else
- {
- the_uri[jj++] = uri[ii];
- }
- }
- the_uri[jj] = 0;
- }
-
- fprintf(header," %s::%sPtr create%s();\n", the_uri, name, name);
-
- fprintf(body,"%s::%sPtr %sDataFactory::create%s()\n",the_uri, name, factoryname, name);
- fprintf(body,"{\n");
- fprintf(body," DataObjectPtr dob = the_factory->create(\"%s\",\"%s\");\n",
- tl[i].getURI(),name);
- fprintf(body," %s::%s* the_ob = new %s::%s(dob);\n",the_uri,name,the_uri,name);
- fprintf(body," return the_ob;\n");
- fprintf(body,"}\n\n");
-
- delete the_uri;
-
- }
-
- fprintf(header," DataFactory* getDataFactory()\n");
- fprintf(header," {\n");
- fprintf(header," return (DataFactory*)the_factory;\n");
- fprintf(header," }\n");
- fprintf(header," private:\n");
- fprintf(header," DataFactoryPtr the_factory;\n");
- fprintf(header,"};\n");
-
- fprintf(header,"\n\n");
-
- fprintf(body,"%sDataFactory* %sDataFactory::get%sDataFactory()\n",
- factoryname,factoryname,factoryname);
- fprintf(body,"{\n");
- fprintf(body," %sDataFactory* t = new %sDataFactory();\n",
- factoryname, factoryname);
- fprintf(body," t->the_factory = DataFactory::getDataFactory();\n");
- fprintf(body," return t;\n");
- fprintf(body,"}\n\n");
-
-
- fprintf(header,"/*******************************************\n");
- fprintf(header," * DataObject Type definitions *\n");
- fprintf(header," *******************************************/\n\n\n");
-
-
- for (i=0;i<tl.size();i++)
- {
- nscount = 0;
-
- if (!strcmp(tl[i].getURI(),"commonj.sdo")) continue;
- const char *uri = tl[i].getURI();
- char *c = (char*) strchr(uri,'.');
-
- if (c == 0)
- {
- fprintf(header,"namespace %s{\n",uri);
- fprintf(body, "namespace %s{\n",uri);
- nscount = 1;
- }
- else
- {
- char* buf = new char[strlen(uri) + 1];
- strcpy(buf, uri);
- c = buf;
- char* c1;
- do {
- c1 = strchr(c,'.');
- if (c1) *c1 = 0;
- fprintf(header,"namespace %s{\n", c);
- fprintf(body, "namespace %s{\n", c);
- nscount++;
- if (c1) c = c1+1;
- } while (c1 != 0);
- delete buf;
- }
-
-
- const char* name = tl[i].getName();
-
- fprintf(header," class %s :public RefCountingObject {\n", name);
- fprintf(header," public:\n");
- fprintf(header," %s(DataObject* d);",name);
-
- // construction from a data object
-
- fprintf(body,"%s::%s(DataObject* d)\n",name,name);
- fprintf(body,"{\n");
- fprintf(body," the_object = d;\n");
- fprintf(body," the_object->setUserData((void*)this);\n");
- fprintf(body,"}\n\n\n");
-
-
-
- PropertyList pl = tl[i].getProperties();
- for (unsigned int j=0;j<pl.size();j++)
- {
- const char* pname = pl[j].getName();
-
- if (pl[j].isMany())
- {
- fprintf(header," DataObjectList& get%s();\n",pname);
- fprintf(body, "DataObjectList& %s::get%s\n{\n",name,pname);
- fprintf(body, " return the_object->getList(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- }
- else
- {
- if (pl[j].getType().isDataType())
- {
- switch (pl[j].getTypeEnum())
- {
- case Type::BooleanType:
- fprintf(header," bool get%s();\n",pname);
- fprintf(body, "bool %s::get%s\n(){\n",name, pname);
- fprintf(body, " return the_object->getBoolean(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(bool b);\n",pname);
- fprintf(body, "void %s::set%s(bool b)\n{\n",name, pname);
- fprintf(body, " the_object->setBoolean(\"%s\",b);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::ByteType:
-
- fprintf(header," char get%s();\n",pname);
- fprintf(body, "char %s::get%s\n{\n",name, pname);
- fprintf(body, " return the_object->getByte(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(char c);\n",pname);
- fprintf(body, "void %s::set%s(char c)\n{\n",name, pname);
- fprintf(body, " the_object->setByte(\"%s\",c);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::BytesType:
-
- fprintf(header," unsigned int get%s(char *buf, unsigned int len);\n",pname);
- fprintf(body, "unsigned int %s::get%s(char *buf, unsigned int len)\n{\n",name,
- pname);
- fprintf(body, " return the_object->getBytes(\"%s\", buf,len);\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(char *buf,unsigned int len);\n",pname);
- fprintf(body, "void %s::set%s(char *buf, unsigned int len)\n{\n",name,
- pname);
- fprintf(body, " the_object->setBytes(\"%s\", buf,len);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::CharacterType:
-
- fprintf(header," wchar_t get%s();\n",pname);
- fprintf(body, "wchar_t %s::get%s\n{\n",name, pname);
- fprintf(body, " return the_object->getCharacter(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(wchar_t c);\n",pname);
- fprintf(body, "void %s::set%s(wchar_t c)\n{\n",name, pname);
- fprintf(body, " the_object->setCharacter(\"%s\",c);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::DateType:
-
- fprintf(header," SDODate get%s();\n",pname);
- fprintf(body, "SDODate %s::get%s\n{\n",name, pname);
- fprintf(body, " return the_object->getDate(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(const SDODate c);\n",pname);
- fprintf(body, "void %s::set%s(const SDODate c)\n{\n",name, pname);
- fprintf(body, " the_object->setDate(\"%s\",c);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::DoubleType:
-
- fprintf(header," long double get%s();\n",pname);
- fprintf(body, "long double %s::get%s\n{\n",name, pname);
- fprintf(body, " return the_object->getDouble(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(long double c);\n",pname);
- fprintf(body, "void %s::set%s(long double c)\n{\n",name, pname);
- fprintf(body, " the_object->setDouble(\"%s\",c);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::FloatType:
-
- fprintf(header," float get%s();\n",pname);
- fprintf(body, "float %s::get%s\n{\n",name, pname);
- fprintf(body, " return the_object->getFloat(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(float c);\n",pname);
- fprintf(body, "void %s::set%s(float c)\n{\n",name, pname);
- fprintf(body, " the_object->setFloat(\"%s\",c);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::IntType:
-
- fprintf(header," long get%s();\n",pname);
- fprintf(body, "long %s::get%s\n{\n",name, pname);
- fprintf(body, " return the_object->getInteger(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(long c);\n",pname);
- fprintf(body, "void %s::set%s(long c)\n{\n",name, pname);
- fprintf(body, " the_object->setInteger(\"%s\",c);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::LongType:
-
- fprintf(header," int64_t get%s();\n",pname);
- fprintf(body, "int64_t %s::get%s\n{\n",name, pname);
- fprintf(body, " return the_object->getLong(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(int64_t c);\n",pname);
- fprintf(body, "void %s::set%s(int64_t c)\n{\n",name, pname);
- fprintf(body, " the_object->setLong(\"%s\",c);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::ShortType:
-
- fprintf(header," short get%s();\n",pname);
- fprintf(body, "short %s::get%s\n{\n",name, pname);
- fprintf(body, " return the_object->getShort(\"%s\");\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(short c);\n",pname);
- fprintf(body, "void %s::set%s(short c)\n{\n",name, pname);
- fprintf(body, " the_object->setShort(\"%s\",c);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- case Type::StringType:
- case Type::UriType:
-
- fprintf(header," unsigned int get%s(wchar_t *buf, unsigned int len);\n",pname);
- fprintf(body, "unsigned int %s::get%s(wchar_t *buf, unsigned int len)\n{\n",name,
- pname);
- fprintf(body, " return the_object->getString(\"%s\", buf,len);\n",pname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(wchar_t *buf,unsigned int len);\n",pname);
- fprintf(body, "void %s::set%s(wchar_t *buf, unsigned int len)\n{\n",name,
- pname);
- fprintf(body, " the_object->setString(\"%s\", buf,len);\nreturn;\n",pname);
- fprintf(body, "}\n\n");
-
- break;
-
- default:
- fprintf(header,"/* unknown primitive:%s */\n",pname);
- break;
- }
- }
- else
-
- {
- const char* ttname = pl[j].getType().getName();
-
- fprintf(header," %sPtr get%s();\n",ttname, pname);
-
- fprintf(body, "%sPtr %s::get%s()\n{\n",
- ttname,
- name,
- pname);
- fprintf(body, "DataObjectPtr dob = the_object->getDataObject(\"%s\");\n",pname);
- fprintf(body, "DataObject* d = (DataObject*)dob;\n");
- fprintf(body,"%s* value = (%s*)(d->getUserData());\n",ttname, ttname);
- fprintf(body, " return (%s*)value;\n", ttname);
- fprintf(body, "}\n\n");
- fprintf(header," void set%s(%sPtr dob);\n",pname, ttname);
- fprintf(body, "void %s::set%s(%sPtr dob)\n{\n",
- name,pname,ttname);
- fprintf(body,"%s* ptr = dob;\n", ttname);
- fprintf(body,"DataObject* the_obj = ptr->getDataObject();\n");
- fprintf(body,"the_object->setDataObject(\"%s\", the_obj);\nreturn;\n",
- pname);
- fprintf(body, "}\n\n");
-
- }
- }
- } // for
-
- // now print the contained data object
-
- fprintf(header," DataObject* getDataObject()\n");
- fprintf(header," {\n");
- fprintf(header," return (DataObject*)the_object;\n");
- fprintf(header," }\n");
- fprintf(header," private:\n");
- fprintf(header," DataObjectPtr the_object;\n");
-
- fprintf(header,"};\n");
- for (int i=0;i<nscount;i++)
- {
- fprintf(header,"}\n");
- fprintf(body,"}\n");
- }
- }
- fclose (header);
- fclose (body);
- }
- catch (SDORuntimeException e)
- {
- cout << "Exception in code Generation" << endl;
- cout << e << endl;
- }
- return true;
-}
-
-bool DataFactoryImpl::generateInterface(const SDOString& fileroot, const SDOString& factoryname)
-{
- return generateInterface(fileroot.c_str(), factoryname.c_str());
-}
-
std::ostream& DataFactoryImpl::printSelf(std::ostream &os)
{
SDOUtils::printTypes(os, this);
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h?view=diff&rev=556989&r1=556988&r2=556989
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h Tue Jul 17 10:50:18 2007
@@ -662,9 +662,6 @@
const propertyMap& getOpenProperties();
virtual const TypeImpl& getTypeImpl(const SDOString& uri, const SDOString& inTypeName) const;
- virtual bool generateInterface(const char* fileroot, const char* factoryname);
- virtual bool generateInterface(const SDOString& fileroot, const SDOString& factoryname);
-
virtual std::ostream& printSelf(std::ostream &os);
private:
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h?view=diff&rev=556989&r1=556988&r2=556989
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h Tue Jul 17 10:50:18 2007
@@ -71,7 +71,6 @@
static int pete();
- static int testgenerate(const char* xsd, const char* output);
static int emptycs();
static int compatiblefactory();
static int transferto(DataObjectPtr d, DataFactoryPtr f, bool expecterror);
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp?view=diff&rev=556989&r1=556988&r2=556989
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp Tue Jul 17 10:50:18 2007
@@ -1018,62 +1018,6 @@
}
-int sdotest::testgenerate(const char* xsd, const char* output)
-{
-
- int i,j;
-
- try {
-
- char * name1 = new char[strlen(output) + 5];
- char * name2 = new char[strlen(output) + 5];
- char * c;
- strcpy(name1,output);
- while ((c = strchr(name1,'.')) != 0)*c='_';
- strcpy(name2,name1);
- strcat(name1,".dat");
- strcat(name2,".txt");
-
-
- DataFactoryPtr mdg = DataFactory::getDataFactory();
-
- XSDHelperPtr xsh = HelperProvider::getXSDHelper(mdg);
-
- if (xsd)
- {
- xsh->defineFile(xsd);
-
- if ((i = xsh->getErrorCount()) > 0)
- {
-
- if (!silent)
- {
- cout << "PROBLEM: generation XSD reported some errors:" << endl;
- for (j=0;j<i;j++)
- {
- const char *m = xsh->getErrorMessage(j);
- if (m != 0) cout << m;
- cout << endl;
- }
- }
- return 0;
- }
- else
- {
- mdg->generateInterface(name1,"Test");
- return comparefiles(name1,name2);
- }
- }
- return 0;
- }
- catch (SDORuntimeException e)
- {
- if (!silent)cout << "Exception in TestGenerate" << e << endl;
- return 0;
- }
-}
-
-
int sdotest::emptycs()
{
try {
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org