| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

capi_pluginservice.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <algorithm>
3 #include "capi_pluginservice.h"
4 #include <Gaudi/PluginService.h>
5
6 #include <iostream>
7 using namespace Gaudi::PluginService::Details;
8
9 cgaudi_pluginsvc_t
10 cgaudi_pluginsvc_instance()
11 {
12 static Registry& cxxreg = Registry::instance();
13 return { (void*)(&cxxreg) };
14 }
15
16 int
17 cgaudi_pluginsvc_get_factory_size(cgaudi_pluginsvc_t self)
18 {
19 const Registry::FactoryMap &fmap = ((const Registry*)self.registry)->factories();
20 return int(fmap.size());
21 }
22
23 constexpr struct select1st_t {
24 template <typename S,typename T>
25 const S& operator()(const std::pair<S,T>& p) const
26 { return p.first; }
27 template <typename S,typename T>
28 S& operator()(std::pair<S,T>& p) const
29 { return p.first; }
30 } select1st {};
31
32 cgaudi_factory_t
33 cgaudi_pluginsvc_get_factory_at(cgaudi_pluginsvc_t self, int n)
34 {
35 const Registry *reg = ((const Registry*)self.registry);
36 std::vector<Registry::KeyType> keys;
37 keys.reserve(reg->factories().size());
38 std::transform(reg->factories().begin(),reg->factories().end(),
39 std::back_inserter(keys), select1st );
40 return { self, keys[n].c_str() };
41 }
42
43 const char*
44 cgaudi_factory_get_library(cgaudi_factory_t self)
45 {
46 Registry &reg = Registry::instance();
47 return reg.getInfo(self.id).library.c_str();
48 }
49
50 const char*
51 cgaudi_factory_get_type(cgaudi_factory_t self)
52 {
53 Registry &reg = Registry::instance();
54 return reg.getInfo(self.id).type.c_str();
55 }
56
57 const char*
58 cgaudi_factory_get_rtype(cgaudi_factory_t self)
59 {
60 Registry &reg = Registry::instance();
61 return reg.getInfo(self.id).rtype.c_str();
62 }
63
64 const char*
65 cgaudi_factory_get_classname(cgaudi_factory_t self)
66 {
67 Registry &reg = Registry::instance();
68 return reg.getInfo(self.id).className.c_str();
69 }
70
71 int
72 cgaudi_factory_get_property_size(cgaudi_factory_t self)
73 {
74 Registry &reg = Registry::instance();
75 const Registry::FactoryInfo& fi = reg.getInfo(self.id);
76 return int(fi.properties.size());
77 }
78
79
80 cgaudi_property_t
81 cgaudi_factory_get_property_at(cgaudi_factory_t self, int n)
82 {
83 cgaudi_property_t cprop{ self.registry, self.id, nullptr };
84 Registry &reg = Registry::instance();
85 const Registry::FactoryInfo& fi = reg.getInfo(cprop.id);
86 if (n<(long)fi.properties.size()) {
87 auto itr = std::next(fi.properties.cbegin(),n);
88 cprop.key = itr->first.c_str();
89 }
90 return cprop;
91 }
92
93 const char*
94 cgaudi_property_get_key(cgaudi_property_t self)
95 {
96 return self.key;
97 }
98
99 const char*
100 cgaudi_property_get_value(cgaudi_property_t self)
101 {
102 Registry &reg = Registry::instance();
103 const Registry::FactoryInfo& fi = reg.getInfo(self.id);
104 auto prop = fi.properties.find(self.key);
105 return prop != fi.properties.end() ? prop->second.c_str() : nullptr;
106 }
cgaudi_factory_get_property_at
cgaudi_property_t cgaudi_factory_get_property_at(cgaudi_factory_t self, int n)
Definition: capi_pluginservice.cpp:81
cgaudi_pluginsvc_t
Definition: capi_pluginservice.h:38
cgaudi_factory_get_classname
const char * cgaudi_factory_get_classname(cgaudi_factory_t self)
Definition: capi_pluginservice.cpp:65
Gaudi::PluginService::Details::Registry::getInfo
const FactoryInfo & getInfo(const std::string &id) const
Retrieve the FactoryInfo object for an id.
Definition: PluginService.cpp:296
select1st
constexpr struct select1st_t select1st
std::map::end
T end(T...args)
Gaudi::PluginService::Details::Registry::FactoryInfo
Definition: PluginServiceDetails.h:106
std::map< KeyType, FactoryInfo >
Gaudi::PluginService::Details::Registry::FactoryInfo::properties
Properties properties
Definition: PluginServiceDetails.h:121
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
cgaudi_pluginsvc_instance
cgaudi_pluginsvc_t cgaudi_pluginsvc_instance()
Definition: capi_pluginservice.cpp:10
capi_pluginservice.h
cgaudi_property_get_value
const char * cgaudi_property_get_value(cgaudi_property_t self)
Definition: capi_pluginservice.cpp:100
cgaudi_property_get_key
const char * cgaudi_property_get_key(cgaudi_property_t self)
Definition: capi_pluginservice.cpp:94
cgaudi_pluginsvc_get_factory_size
int cgaudi_pluginsvc_get_factory_size(cgaudi_pluginsvc_t self)
Definition: capi_pluginservice.cpp:17
std::next
T next(T...args)
cgaudi_factory_get_rtype
const char * cgaudi_factory_get_rtype(cgaudi_factory_t self)
Definition: capi_pluginservice.cpp:58
cgaudi_factory_t
Definition: capi_pluginservice.h:42
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:163
cgaudi_property_t::registry
cgaudi_pluginsvc_t registry
Definition: capi_pluginservice.h:48
GaudiPluginService.cpluginsvc.registry
def registry()
Definition: cpluginsvc.py:63
std::pair
cgaudi_factory_get_property_size
int cgaudi_factory_get_property_size(cgaudi_factory_t self)
Definition: capi_pluginservice.cpp:72
cgaudi_property_t
Definition: capi_pluginservice.h:47
select1st_t::operator()
S & operator()(std::pair< S, T > &p) const
Definition: capi_pluginservice.cpp:28
PluginService.h
cgaudi_pluginsvc_get_factory_at
cgaudi_factory_t cgaudi_pluginsvc_get_factory_at(cgaudi_pluginsvc_t self, int n)
Definition: capi_pluginservice.cpp:33
Gaudi::PluginService::Details::Registry::FactoryInfo::library
std::string library
Definition: PluginServiceDetails.h:116
std::map::find
T find(T...args)
std::map::size
T size(T...args)
std::vector
STL class.
std::map::begin
T begin(T...args)
select1st_t::operator()
const S & operator()(const std::pair< S, T > &p) const
Definition: capi_pluginservice.cpp:25
std::back_inserter
T back_inserter(T...args)
std::string::c_str
T c_str(T...args)
Gaudi::PluginService::Details::Registry::instance
static Registry & instance()
Retrieve the singleton instance of Registry.
Definition: PluginService.cpp:138
cgaudi_factory_get_type
const char * cgaudi_factory_get_type(cgaudi_factory_t self)
Definition: capi_pluginservice.cpp:51
Gaudi::PluginService::Details::Registry::FactoryInfo::rtype
std::string rtype
Definition: PluginServiceDetails.h:119
Gaudi::PluginService::Details::Registry
In-memory database of the loaded factories.
Definition: PluginServiceDetails.h:99
Gaudi::PluginService::Details
Definition: PluginServiceDetails.h:49
std::transform
T transform(T...args)
Gaudi::PluginService::Details::Registry::FactoryInfo::className
std::string className
Definition: PluginServiceDetails.h:120
Gaudi::PluginService::Details::Registry::FactoryInfo::type
std::string type
Definition: PluginServiceDetails.h:118
cgaudi_factory_get_library
const char * cgaudi_factory_get_library(cgaudi_factory_t self)
Definition: capi_pluginservice.cpp:44
std::vector::reserve
T reserve(T...args)