Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Interface to specify which plugin is meant
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 :
11 : #ifndef TOOLS_PLUGIN_SPEC_HPP
12 : #define TOOLS_PLUGIN_SPEC_HPP
13 :
14 : #include <string>
15 : #include <vector>
16 :
17 : #include <kdb.hpp>
18 :
19 : namespace kdb
20 : {
21 :
22 : namespace tools
23 : {
24 :
25 : /**
26 : * @brief Specifies a plugin by its name and configuration
27 : *
28 : * @invariant name is valid (nonempty, starts with a-z, then a-z_0-9)
29 : * @invariant refname is valid (same as above or a size_t number)
30 : */
31 302478 : class PluginSpec
32 : {
33 : public:
34 1 : PluginSpec ()
35 4 : {
36 1 : }
37 :
38 : explicit PluginSpec (std::string pluginName, KeySet pluginConfig = KeySet ());
39 :
40 : explicit PluginSpec (std::string pluginName, std::string refName, KeySet pluginConfig = KeySet ());
41 :
42 : explicit PluginSpec (std::string pluginName, size_t refNumber, KeySet pluginConfig = KeySet ());
43 :
44 : std::string getFullName () const;
45 : std::string getRefName () const;
46 : bool isRefNumber () const;
47 : std::string getName () const;
48 :
49 : KeySet getConfig () const;
50 :
51 :
52 : void setFullName (std::string const & name);
53 : void setRefName (std::string const & name);
54 : void setRefNumber (size_t number);
55 : void setName (std::string const & name);
56 :
57 : void appendConfig (KeySet config);
58 : void setConfig (KeySet config);
59 :
60 : void validate (std::string const & str) const;
61 :
62 : private:
63 : std::string name;
64 : std::string refname;
65 : KeySet config;
66 : };
67 :
68 : struct PluginSpecName
69 : {
70 1410 : bool operator() (PluginSpec const & s1, PluginSpec const & s2) const
71 : {
72 4230 : return s1.getName () == s2.getName ();
73 : }
74 : };
75 :
76 : struct PluginSpecRefName
77 : {
78 1041 : bool operator() (PluginSpec const & s1, PluginSpec const & s2) const
79 : {
80 3123 : return s1.getRefName () == s2.getRefName ();
81 : }
82 : };
83 :
84 : struct PluginSpecFullName
85 : {
86 12 : bool operator() (PluginSpec const & s1, PluginSpec const & s2) const
87 : {
88 36 : return s1.getFullName () == s2.getFullName ();
89 : }
90 : };
91 :
92 :
93 : /**
94 : * @brief Only to be used with PluginSpecName!
95 : */
96 : struct PluginSpecHash
97 : {
98 1672 : size_t operator() (kdb::tools::PluginSpec const & s) const
99 : {
100 5016 : return std::hash<std::string> () (s.getName ());
101 : }
102 : };
103 :
104 : #ifdef ELEKTRA_PLUGINSPEC_WITH_COMPARE
105 : bool operator== (PluginSpec const & self, PluginSpec const & other);
106 : bool operator!= (PluginSpec const & self, PluginSpec const & other);
107 : #endif
108 :
109 : typedef std::vector<PluginSpec> PluginSpecVector;
110 :
111 : std::ostream & operator<< (std::ostream & os, PluginSpec const & spec);
112 : } // namespace tools
113 : } // namespace kdb
114 :
115 : #endif
|