Evoplex  0.2.1
abstractplugin.h
1 /* Evoplex <https://evoplex.org>
2  * Copyright (C) 2016-present - Marcos Cardinot <marcos@cardinot.net>
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ABSTRACT_PLUGIN_H
18 #define ABSTRACT_PLUGIN_H
19 
20 #include <QString>
21 
22 #include "attributes.h"
23 #include "prg.h"
24 #include "value.h"
25 
26 namespace evoplex {
27 
28 class Trial;
29 
35 {
36  friend class Trial;
37  friend class AbstractGraph;
38 
39 public:
42 
50  virtual bool init();
51 
56  PRG* prg() const;
57 
62  inline PRG* rand() const;
63 
67  inline const Attributes* attrs() const;
68 
73  inline const QString& attrName(int attrId) const;
74 
79  inline const Value& attr(int attrId) const;
80 
87  inline Value attr(const QString& name, Value defaultValue=Value()) const;
88 
94  inline bool attrExists(const char* name) const;
96  inline bool attrExists(const QString& name) const;
97 
100 protected:
101  Trial* m_trial;
102 
104  AbstractPlugin() = default;
106  ~AbstractPlugin() = default;
107 
108 private:
109  const Attributes* m_attrs;
110 
111  bool setup(Trial& trial, const Attributes& attrs);
112 };
113 
114 /************************************************************************
115  AbstractPlugin: Inline member functions
116  ************************************************************************/
117 
118 inline PRG* AbstractPlugin::rand() const
119 { return prg(); }
120 
121 inline const Attributes* AbstractPlugin::attrs() const
122 { return m_attrs; }
123 
124 inline const QString& AbstractPlugin::attrName(int attrId) const
125 { return m_attrs->name(attrId); }
126 
127 inline const Value& AbstractPlugin::attr(int attrId) const
128 { return m_attrs->value(attrId); }
129 
130 inline Value AbstractPlugin::attr(const QString& name, Value defaultValue) const
131 { return m_attrs->value(name, defaultValue); }
132 
133 inline bool AbstractPlugin::attrExists(const char* name) const
134 { return m_attrs->contains(name); }
135 
136 inline bool AbstractPlugin::attrExists(const QString& name) const
137 { return m_attrs->contains(name); }
138 
139 } // evoplex
140 #endif // ABSTRACT_PLUGIN_H
A class for variant data types (tagged union).
Definition: value.h:56
~AbstractPlugin()=default
destructor
bool contains(const QString &name) const
Checks if the container contains name.
Definition: attributes.h:187
const QString & name(int id) const
Gets the name of the attribute at id.
Definition: attributes.h:207
PRG * rand() const
prg() alias
Definition: abstractplugin.h:118
bool attrExists(const char *name) const
Checks if the plugin&#39;s attribute name exists.
Definition: abstractplugin.h:133
const Attributes * attrs() const
Gets the plugin&#39;s attributes.
Definition: abstractplugin.h:121
const Value & value(int id) const
Gets the value of the attribute at id.
Definition: attributes.h:213
const Value & attr(int attrId) const
Gets the attribute&#39;s value for attrId.
Definition: abstractplugin.h:127
PRG * prg() const
pseudo-random generator pointer.
Pseudo-random number generator.
Definition: prg.h:29
Base class for plugins.
Definition: abstractplugin.h:34
const QString & attrName(int attrId) const
Gets the attribute&#39;s name for attrId.
Definition: abstractplugin.h:124
Definition: abstractgraph.h:29
A container of labeled values.
Definition: attributes.h:39
Abstract base class for graph plugins.
Definition: abstractgraph.h:54
virtual bool init()
Initializes the plugin.
AbstractPlugin()=default
constructor