43 #include "../Logger.hpp" 46 #include "../internal/mystd.hpp" 47 #include "../internal/DataSourceTypeInfo.hpp" 48 #include <boost/algorithm/string.hpp> 53 using namespace detail;
56 boost::shared_ptr<TypeInfoRepository> typerepos;
59 TypeInfoRepository::TypeInfoRepository()
78 loadTypeKitForName = loader;
81 TypeInfo* TypeInfoRepository::typeInternal(
const std::string& name )
const 84 map_t::const_iterator i = data.find( name );
85 if ( i != data.end() ) {
91 string tkname =
"/" + boost::replace_all_copy(boost::replace_all_copy(name,
string(
"."),
"/"),
"<",
"</");
92 i = data.find( tkname );
93 if ( i != data.end() ) {
99 for (i = data.begin(); i != data.end(); ++i) {
100 std::vector< std::string > names = i->second->getTypeNames();
101 vector<std::string>::iterator j = names.begin();
102 for (; j != names.end(); ++j) {
103 if(((*j) == name) || ((*j) == tkname)) {
117 if(!ret && loadTypeKitForName)
119 if(loadTypeKitForName(name))
120 ret = typeInternal(name);
129 vector<TypeInfo*> todelete =
values(data);
130 sort(todelete.begin(), todelete.end());
131 vector<TypeInfo*>::iterator begin, last = unique( todelete.begin(), todelete.end() );
132 begin = todelete.begin();
133 for( ; begin != last; ++begin )
144 map_t::const_iterator i = data.begin();
145 for (; i != data.end(); ++i){
146 if (i->second->getTypeId() && *(i->second->getTypeId()) == *type_id)
155 map_t::const_iterator i = data.begin();
156 for (; i != data.end(); ++i){
157 if (i->second->getTypeId() && i->second->getTypeId()->name() == type_id_name)
169 log(
Error) <<
"Can't register a new TypeInfo object for '"<<t->
getTypeName() <<
"': one already exists."<<endlog();
186 if (ti && data.count(tname) && data[tname] != ti ) {
187 log(
Error) <<
"Refusing to add type information for '" << tname <<
"': the name is already in use by another type."<<endlog();
204 log(
Debug) <<
"Registered Type '"<<tname <<
"' to the Orocos Type System."<<
Logger::endl;
205 for(Transports::iterator it = transports.begin(); it != transports.end(); ++it)
206 if ( (*it)->registerTransport( tname, ti) )
207 log(
Info) <<
"Registered new '"<< (*it)->getTransportName()<<
"' transport for " << tname <<endlog();
222 string dotname = boost::replace_all_copy(boost::replace_all_copy(type,
string(
"/"),
"."),
"<.",
"<");
223 if ( dotname[0] ==
'.')
224 dotname = dotname.substr(1);
231 vector<string> result =
keys( data );
232 for( vector<string>::iterator it = result.begin(); it != result.end(); ++it)
240 transports.reserve( transports.size() + 1 );
241 transports.push_back( tr );
243 map_t::const_iterator i = data.begin();
244 for( ; i != data.end(); ++i )
246 log(
Info) <<
"Registered new '"<< tr->
getTransportName()<<
"' transport for " << i->first <<endlog();
249 log(
Debug) <<
"Transport " << tr->
getTransportName() <<
" did not install a fallback handler for 'unknown_t'." <<endlog();
257 for(map_t::const_iterator it = data.begin(); it != data.end(); ++it)
259 std::vector<int> transports;
260 transports = it->second->getTransportNames();
261 log(
Debug) <<
"-- " << it->first
262 <<
" (" << (*it).second->getTypeName() <<
") protocols [";
263 for (std::vector<int>::const_iterator iter=transports.begin();
264 iter != transports.end();
273 for(Transports::const_iterator it = transports.begin(); it != transports.end(); ++it)
void addAlias(const std::string &alias)
Adds an alias to the this type.
const std::string & getTypeName() const
Return the type name which was first registered.
std::vector< std::string > getDottedTypes() const
List all registered types in the package.type notation.
std::vector< std::string > getTypes() const
List all types registered with their original type name.
This class contains all known types to Orocos.
virtual bool installTypeInfoObject(TypeInfo *ti)=0
Installs the type info object in the global data source type info handler and adds any additional fea...
const std::type_info * TypeId
A class which registers TypeTransporter instances to types.
virtual std::string getTransportName() const =0
Returns the (protocol) name of this transport.
std::string toDot(const std::string &type) const
Convert any type name returned by getTypes() to the dotted type notation.
All generator classes inherit from this object in order to allow them to be added to the TypeInfoRepo...
void registerTransport(TransportPlugin *tr)
Call this function to add a new (network) transport for Orocos types.
void logTypeInfo() const
Dump all known types, along with transports and their types, to the log.
static std::ostream & endl(std::ostream &__os)
bool addType(TypeInfo *ti)
Add a type to the Orocos type repository.
A class for representing a user type, and which can build instances of that type. ...
virtual TypeInfo * getTypeInfoObject() const =0
Returns the TypeInfo object of this type, or null if none exists yet.
std::vector< typename MapT::key_type > keys(const MapT &map)
Every DataSource of type T has a type info class which it can ask type information.
static shared_ptr Instance()
static Logger & log()
As Instance(), but more userfriendly.
std::vector< typename MapT::mapped_type > values(const MapT &map)
TypeInfo * getTypeById(TypeInfo::TypeId type_id) const
Return the type info structure of a given type by its type_id.
void setAutoLoader(const boost::function< bool(const std::string &)> &loader)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
virtual const std::string & getTypeName() const =0
Return the type name for which this generator generates type info features.
virtual bool registerTransport(std::string type_name, TypeInfo *ti)=0
Add a transport for the given type to the types::TypeInfo instance.
TypeInfo * type(const std::string &name) const
Retrieve a type with a given name.
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...