#include "Proc.hxx"
#include "InputDataStreamPort.hxx"
#include "OutputDataStreamPort.hxx"
+#include "Catalog.hxx"
+#include "TypeCode.hxx"
+
#include<iostream>
//#define _DEVDEBUG_
using namespace std;
Runtime* Runtime::_singleton = 0;
+TypeCode* Runtime::_tc_double = 0;
+TypeCode* Runtime::_tc_int = 0;
+TypeCode* Runtime::_tc_bool = 0;
+TypeCode* Runtime::_tc_string = 0;
+TypeCode* Runtime::_tc_file = 0;
// --- init typecodes for edInit with C++ Any
-TypeCode *Runtime::_tc_double = new TypeCode(Double);
-TypeCode *Runtime::_tc_int = new TypeCode(Int);
-TypeCode *Runtime::_tc_bool = new TypeCode(Bool);
-TypeCode *Runtime::_tc_string = new TypeCode(String);
-TypeCode *Runtime::_tc_file = new TypeCodeObjref("file", "file");
const char Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME[]="Neutral";
return Runtime::_singleton;
}
+Runtime::Runtime()
+{
+ DEBTRACE("Runtime::Runtime");
+ Runtime::_tc_double = new TypeCode(Double);
+ Runtime::_tc_int = new TypeCode(Int);
+ Runtime::_tc_bool = new TypeCode(Bool);
+ Runtime::_tc_string = new TypeCode(String);
+ Runtime::_tc_file = new TypeCodeObjref("file", "file");
+ DEBTRACE( "_tc_double refcnt: " << Runtime::_tc_double->getRefCnt() );
+ DEBTRACE( "_tc_int refcnt: " << Runtime::_tc_int->getRefCnt() );
+ DEBTRACE( "_tc_bool refcnt: " << Runtime::_tc_bool->getRefCnt() );
+ DEBTRACE( "_tc_string refcnt: " << Runtime::_tc_string->getRefCnt() );
+ DEBTRACE( "_tc_file refcnt: " << Runtime::_tc_file->getRefCnt() );
+ _builtinCatalog = new Catalog("builtins");
+ _builtinCatalog->_composednodeMap["Bloc"]=new Bloc("Bloc");
+ _builtinCatalog->_composednodeMap["Switch"]=new Switch("Switch");
+ _builtinCatalog->_composednodeMap["WhileLoop"]=new WhileLoop("WhileLoop");
+ _builtinCatalog->_composednodeMap["ForLoop"]=new ForLoop("ForLoop");
+ _builtinCatalog->_composednodeMap["ForEachLoopDouble"]=new ForEachLoop("ForEachLoopDouble",Runtime::_tc_double);
+ std::map<std::string,TypeCode*>& typeMap=_builtinCatalog->_typeMap;
+ Runtime::_tc_double->incrRef();
+ typeMap["double"]=Runtime::_tc_double;
+ Runtime::_tc_int->incrRef();
+ typeMap["int"]=Runtime::_tc_int;
+ Runtime::_tc_bool->incrRef();
+ typeMap["bool"]=Runtime::_tc_bool;
+ Runtime::_tc_string->incrRef();
+ typeMap["string"]=Runtime::_tc_string;
+ Runtime::_tc_file->incrRef();
+ typeMap["file"]=Runtime::_tc_file;
+}
+
+void Runtime::removeRuntime()
+{
+ delete this;
+}
+
Runtime::~Runtime()
{
+ delete _builtinCatalog;
DEBTRACE( "_tc_double refcnt: " << Runtime::_tc_double->getRefCnt() );
DEBTRACE( "_tc_int refcnt: " << Runtime::_tc_int->getRefCnt() );
DEBTRACE( "_tc_bool refcnt: " << Runtime::_tc_bool->getRefCnt() );
Runtime::_tc_bool->decrRef();
Runtime::_tc_string->decrRef();
Runtime::_tc_file->decrRef();
+ for(std::vector<Catalog *>::const_iterator it=_catalogs.begin();it !=_catalogs.end();it++)
+ delete (*it);
Runtime::_singleton=0;
DEBTRACE( "Total YACS::ENGINE::Refcount: " << RefCounter::_totalCnt );
}
+DataNode* Runtime::createInDataNode(const std::string& kind,const std::string& name)
+{
+ throw Exception("InDataNode factory not implemented");
+}
+
+DataNode* Runtime::createOutDataNode(const std::string& kind,const std::string& name)
+{
+ throw Exception("OutDataNode factory not implemented");
+}
+
InlineFuncNode* Runtime::createFuncNode(const std::string& kind,const std::string& name)
{
throw Exception("FuncNode factory not implemented");
{
return new OutputDataStreamPort(name,node,type);
}
+
+//! Load a catalog of calculation to use as factory
+/*!
+ * \param sourceKind: the kind of catalog source. It depends on runtime. It could be a file, a server, a directory
+ * \param path: the path to the catalog.
+ * \return the loaded Catalog
+ */
+Catalog* Runtime::loadCatalog(const std::string& sourceKind,const std::string& path)
+{
+ if (_catalogLoaderFactoryMap.find(sourceKind) == _catalogLoaderFactoryMap.end())
+ {
+ throw Exception("This type of catalog loader does not exist: " + sourceKind);
+ }
+ else
+ {
+ Catalog* cata=new Catalog(path);
+ CatalogLoader* proto=_catalogLoaderFactoryMap[sourceKind];
+ proto->load(cata,path);
+ return cata;
+ }
+}
+
+//! Add a catalog loader factory to the map _catalogLoaderFactoryMap under the name name
+/*!
+ * \param name: name under which the factory is registered
+ * \param factory: the factory
+ */
+void Runtime::setCatalogLoaderFactory(const std::string& name, CatalogLoader* factory)
+{
+ _catalogLoaderFactoryMap[name]=factory;
+}
+
+//! Get the catalog of base nodes (elementary and composed)
+/*!
+ * \return the builtin Catalog
+ */
+Catalog* Runtime::getBuiltinCatalog()
+{
+ return _builtinCatalog;
+}
+
+//! Add a catalog of types and nodes to the runtime
+/*!
+ * These catalogs are searched when calling getTypeCode method
+ */
+void Runtime::addCatalog(Catalog* catalog)
+{
+ _catalogs.push_back(catalog);
+}
+
+//! Get a typecode by its name from runtime catalogs
+/*!
+ * \return the typecode if it exists or NULL
+ */
+TypeCode* Runtime::getTypeCode(const std::string& name)
+{
+ if (_builtinCatalog->_typeMap.count(name) != 0)
+ return _builtinCatalog->_typeMap[name];
+ for(std::vector<Catalog *>::const_iterator it=_catalogs.begin();it !=_catalogs.end();it++)
+ {
+ if ((*it)->_typeMap.count(name) != 0)
+ return (*it)->_typeMap[name];
+ }
+ return 0;
+}
+