DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::OksMethod Class Reference

OKS method class. More...

#include <method.hpp>

Collaboration diagram for dunedaq::oks::OksMethod:
[legend]

Public Member Functions

 OksMethod (const std::string &name, OksClass *p=nullptr)
 OKS method constructor.
 OksMethod (const std::string &name, const std::string &description, OksClass *p=nullptr)
 OKS method constructor.
 ~OksMethod ()
bool operator== (const class OksMethod &) const
const std::string & get_name () const noexcept
void set_name (const std::string &name)
 Set method name.
const std::string & get_description () const noexcept
void set_description (const std::string &description)
 Set method description.
const std::list< OksMethodImplementation * > * implementations () const noexcept
OksMethodImplementation * find_implementation (const std::string &language) const
 Find method implementation.
void add_implementation (const std::string &language, const std::string &prototype, const std::string &body)
 Add method implementation.
void remove_implementation (const std::string &language)
 Remove method implementation.

Private Member Functions

 OksMethod (OksXmlInputStream &, OksClass *)
void save (OksXmlOutputStream &) const

Private Attributes

OksClass * p_class
std::string p_name
std::string p_description
std::list< OksMethodImplementation * > * p_implementations

Static Private Attributes

static const char method_xml_tag [] = "method"
static const char name_xml_attr [] = "name"
static const char description_xml_attr [] = "description"

Friends

class OksKernel
class OksClass
class OksMethodImplementation
std::ostream & operator<< (std::ostream &s, const OksMethod &m)

Detailed Description

OKS method class.

The class implements OKS method that is a part of OKS class. It has name, description and implementations.

Methods can be used in generated Data Access Libraries (DAL). This allows to insert user-defined methods (also known as "DAL algorithms") into generated DAL classes. In such case the method should have appropriate implementations for c++ and/or Java languages. For more information on DAL generation see oksdalgen User's Guide.

Definition at line 146 of file method.hpp.

Constructor & Destructor Documentation

◆ OksMethod() [1/3]

dunedaq::oks::OksMethod::OksMethod ( const std::string & name,
OksClass * p = nullptr )

OKS method constructor.

Create new OKS method providing name.

The parameter is:

Parameters
namename of the method

Definition at line 116 of file method.cpp.

117 : p_class(p)
118 , p_name(nm)
119 , p_implementations(nullptr)
120{
121 try {
122 oks::validate_not_empty(p_name, "method name");
123 } catch (std::exception& ex) {
124 Oks::error_msg("OksMethod::OksMethod()") << ex.what() << std::endl;
125 }
126}
std::list< OksMethodImplementation * > * p_implementations
Definition method.hpp:259
static std::ostream & error_msg(const char *)
Definition kernel.cpp:511
void validate_not_empty(const std::string &value, const char *name)

◆ OksMethod() [2/3]

dunedaq::oks::OksMethod::OksMethod ( const std::string & name,
const std::string & description,
OksClass * p = nullptr )

OKS method constructor.

Create new OKS method providing name and descriptions.

The parameter is:

Parameters
namename of the method (max 128 bytes, see #s_max_name_length variable)
descriptiondescription of the method (max 2000 bytes, see #s_max_description_length variable)
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 128 of file method.cpp.

129 : p_class(p)
130 , p_name(nm)
131 , p_description(desc)
132 , p_implementations(nullptr)
133{
134 oks::validate_not_empty(p_name, "method name");
135}
std::string p_description
Definition method.hpp:258

◆ ~OksMethod()

dunedaq::oks::OksMethod::~OksMethod ( )

Definition at line 137 of file method.cpp.

138{
139 if (p_implementations) {
140 while (!p_implementations->empty()) {
142 p_implementations->pop_front();
143 delete i;
144 }
145
146 delete p_implementations;
147 }
148}
friend class OksMethodImplementation
Definition method.hpp:150

◆ OksMethod() [3/3]

dunedaq::oks::OksMethod::OksMethod ( OksXmlInputStream & s,
OksClass * parent )
private

Definition at line 238 of file method.cpp.

239 : p_class(parent)
241{
242 try {
243 while (true) {
244 OksXmlAttribute attr(s);
245
246 // check for close of tag
247
248 if (oks::cmp_str1(attr.name(), ">")) {
249 break;
250 }
251
252 // check for known oks-relationship' attributes
253
254 else if (oks::cmp_str4(attr.name(), name_xml_attr))
255 p_name.assign(attr.value(), attr.value_len());
256 else if (oks::cmp_str11(attr.name(), description_xml_attr))
257 p_description.assign(attr.value(), attr.value_len());
258 else {
259 s.throw_unexpected_attribute(attr.name());
260 }
261 }
262 } catch (oks::exception& e) {
263 throw oks::FailedRead("xml method", e);
264 } catch (std::exception& e) {
265 throw oks::FailedRead("xml method", e.what());
266 }
267
268 // check validity of read values
269
270 try {
271 oks::validate_not_empty(p_name, "method name");
272 } catch (std::exception& ex) {
273 throw oks::FailedRead("oks method", oks::BadFileData(ex.what(), s.get_line_no(), s.get_line_pos()));
274 }
275
276 // read 'body' and 'method-actions'
277
278 {
279 while (true)
280 try {
281 const char* tag_start = s.get_tag_start();
282
283 if (oks::cmp_str7(tag_start, "/method")) {
284 break;
285 }
286
287 else if (!strcmp(tag_start, "method-implementation")) {
289 p_implementations = new std::list<OksMethodImplementation*>();
290 p_implementations->push_back(new OksMethodImplementation(s, this));
291 }
292
293 else {
294 std::ostringstream text;
295 text << "Unexpected tag \'" << tag_start << "\' inside method \'" << p_name << "\'\n";
296 throw std::runtime_error(text.str().c_str());
297 }
298
299 } catch (oks::exception& e) {
300 throw oks::FailedRead("method tag", e);
301 } catch (std::exception& e) {
302 throw oks::FailedRead("method tag", e.what());
303 }
304 }
305}
OksMethodImplementation(const std::string &language, const std::string &prototype, const std::string &body, OksMethod *p=nullptr)
OKS method implementation constructor.
Definition method.cpp:28
static const char name_xml_attr[]
Definition method.hpp:269
static const char description_xml_attr[]
Definition method.hpp:270
bool cmp_str1(const char *s1, const char s2[2])
Definition cstring.hpp:15
bool cmp_str4(const char *s1, const char s2[5])
Definition cstring.hpp:45
bool cmp_str11(const char *s1, const char s2[12])
Definition cstring.hpp:117
bool cmp_str7(const char *s1, const char s2[8])
Definition cstring.hpp:81

Member Function Documentation

◆ add_implementation()

void dunedaq::oks::OksMethod::add_implementation ( const std::string & language,
const std::string & prototype,
const std::string & body )

Add method implementation.

Add new method implementation. Implementations linked with method shall have different languages.

Parameters
languagelanguage of method implementation
prototypeprototype of method implementation
bodybody of method implementation

In case of problems the oks::exception is thrown.

Definition at line 370 of file method.cpp.

371{
372 if (find_implementation(language)) {
373 std::ostringstream text;
374 text << "Cannot add implementation on language \"" << language << "\" since it already exists.";
375 throw oks::SetOperationFailed("OksMethod::add_implementation", text.str());
376 }
377
378 if (p_class)
379 p_class->lock_file("OksMethod::add_implementation");
380
381 if (!p_implementations) {
382 p_implementations = new std::list<OksMethodImplementation*>();
383 }
384
385 OksMethodImplementation* i = new OksMethodImplementation(language, prototype, body);
386
387 p_implementations->push_back(i);
388 i->p_method = this;
389
390 if (p_class)
392}
void registrate_class_change(ChangeType, const void *, bool=true)
Definition class.cpp:2009
void lock_file(const char *)
Definition class.cpp:733
OksMethodImplementation * find_implementation(const std::string &language) const
Find method implementation.
Definition method.cpp:357

◆ find_implementation()

OksMethodImplementation * dunedaq::oks::OksMethod::find_implementation ( const std::string & language) const

Find method implementation.

Find method implementation by language.

Parameters
languagelanguage of method implementation
Returns
the pointer on method implementation for given language, or 0, if it is not found

Definition at line 357 of file method.cpp.

358{
359 if (p_implementations) {
360 for (std::list<OksMethodImplementation*>::iterator i = p_implementations->begin(); i != p_implementations->end();
361 ++i)
362 if (language == (*i)->get_language())
363 return *i;
364 }
365
366 return 0;
367}

◆ get_description()

const std::string & dunedaq::oks::OksMethod::get_description ( ) const
inlinenoexcept

Get description of method.

Definition at line 201 of file method.hpp.

201{ return p_description; }

◆ get_name()

const std::string & dunedaq::oks::OksMethod::get_name ( ) const
inlinenoexcept

Get name of method.

Definition at line 185 of file method.hpp.

185{ return p_name; }

◆ implementations()

const std::list< OksMethodImplementation * > * dunedaq::oks::OksMethod::implementations ( ) const
inlinenoexcept

Get implementations of method.

Definition at line 215 of file method.hpp.

215{ return p_implementations; }

◆ operator==()

bool dunedaq::oks::OksMethod::operator== ( const class OksMethod & m) const

Definition at line 151 of file method.cpp.

152{
153 // check if compare with self
154
155 if (this == &m)
156 return true;
157
158 // check if attributes are different
159
160 if (p_name != m.p_name || p_description != m.p_description)
161 return false;
162
163 // check if methods have no implementations
164
165 if (p_implementations == 0 && m.p_implementations == 0)
166 return true;
167
168 // check if only one method has implementation
169
170 if (p_implementations == 0 || m.p_implementations == 0)
171 return false;
172
173 // check if numbers of implementations are different
174
175 if (p_implementations->size() != m.p_implementations->size())
176 return false;
177
178 // check implementations
179
180 std::list<OksMethodImplementation*>::const_iterator i1 = p_implementations->begin();
181 std::list<OksMethodImplementation*>::const_iterator i2 = m.p_implementations->begin();
182
183 for (; i1 != p_implementations->end(); ++i1, ++i2) {
184 if (!(*(*i1) == *(*i2)))
185 return false;
186 }
187
188 return true;
189}

◆ remove_implementation()

void dunedaq::oks::OksMethod::remove_implementation ( const std::string & language)

Remove method implementation.

Remove method implementation by language.

Parameters
languagelanguage of method implementation

In case of problems the oks::exception is thrown.

Definition at line 395 of file method.cpp.

396{
398
399 if (i == 0) {
400 std::ostringstream text;
401 text << "Cannot remove implementation on language \"" << language << "\" since it does not exist.";
402 throw oks::SetOperationFailed("OksMethod::remove_implementation", text.str());
403 }
404
405 if (p_class)
406 p_class->lock_file("OksMethod::remove_implementation");
407
408 p_implementations->remove(i);
409
410 if (p_implementations->empty()) {
411 delete p_implementations;
413 }
414
415 if (p_class)
417}

◆ save()

void dunedaq::oks::OksMethod::save ( OksXmlOutputStream & s) const
private

Definition at line 213 of file method.cpp.

214{
215 s.put_raw(' ');
216 s.put_raw(' ');
217
218 s.put_start_tag(method_xml_tag, sizeof(method_xml_tag) - 1);
219
220 s.put_attribute(name_xml_attr, sizeof(name_xml_attr) - 1, p_name.c_str());
221 s.put_attribute(description_xml_attr, sizeof(description_xml_attr) - 1, p_description.c_str());
222
223 s.put_raw('>');
224 s.put_raw('\n');
225
226 if (p_implementations) {
227 for (std::list<OksMethodImplementation*>::iterator i = p_implementations->begin(); i != p_implementations->end();
228 ++i)
229 (*i)->save(s);
230 }
231
232 s.put_raw(' ');
233 s.put_raw(' ');
234
235 s.put_last_tag(method_xml_tag, sizeof(method_xml_tag) - 1);
236}
static const char method_xml_tag[]
Definition method.hpp:268

◆ set_description()

void dunedaq::oks::OksMethod::set_description ( const std::string & description)

Set method description.

Parameters
descriptionnew description of method (max 2000 bytes, see #s_max_description_length variable)
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 420 of file method.cpp.

421{
422 if (p_description != desc) {
423 if (p_class)
424 p_class->lock_file("OksMethod::set_description");
425
426 p_description = desc;
427
428 if (p_class)
430 }
431}

◆ set_name()

void dunedaq::oks::OksMethod::set_name ( const std::string & name)

Set method name.

Methods linked with the same class shall have different names.

Parameters
namenew name of method (max 128 bytes, see #s_max_name_length variable)
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 308 of file method.cpp.

309{
310 // ignore when name is the same
311
312 if (p_name == new_name)
313 return;
314
315 // additional checks are required,
316 // if the method already belongs to some class
317
318 if (p_class) {
319
320 // check allowed length for attribute name
321
322 try {
323 oks::validate_not_empty(new_name, "name");
324 } catch (std::exception& ex) {
325 throw oks::SetOperationFailed("OksMethod::set_name", ex.what());
326 }
327
328 // having a direct method with the same name is an error
329
330 if (p_class->find_direct_method(new_name) != 0) {
331 std::ostringstream text;
332 text << "Class \"" << p_class->get_name() << "\" already has direct method \"" << new_name << '\"';
333 throw oks::SetOperationFailed("OksMethod::set_name", text.str());
334 }
335
336 // check that it is possible to lock the file
337
338 p_class->lock_file("OksMethod::set_name");
339
340 // probably a non-direct method already exists
341
342 OksMethod* m = p_class->find_method(new_name);
343
344 // change the name
345
346 p_name = new_name;
347
348 // registrate the change
349
351 } else {
352 p_name = new_name;
353 }
354}
OksMethod * find_method(const std::string &name) const noexcept
Find method (search in this and base classes).
Definition class.cpp:1302
const std::string & get_name() const noexcept
Definition class.hpp:374
OksMethod * find_direct_method(const std::string &name) const noexcept
Find direct method.
Definition class.cpp:1290
OksMethod(const std::string &name, OksClass *p=nullptr)
OKS method constructor.
Definition method.cpp:116

◆ OksClass

friend class OksClass
friend

Definition at line 149 of file method.hpp.

◆ OksKernel

friend class OksKernel
friend

Definition at line 148 of file method.hpp.

◆ OksMethodImplementation

friend class OksMethodImplementation
friend

Definition at line 150 of file method.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const OksMethod & m )
friend

Definition at line 191 of file method.cpp.

193{
194 s << "Method name: \"" << m.p_name
195 << "\"\n"
196 " description: \""
197 << m.p_description << "\"\n";
198
199 if (m.p_implementations) {
200 s << " implementations:\n";
201
202 for (std::list<OksMethodImplementation*>::const_iterator i = m.p_implementations->begin();
203 i != m.p_implementations->end();
204 ++i)
205 s << *(*i);
206 } else
207 s << " there are no implementation(s)\n";
208
209 return s;
210}

Member Data Documentation

◆ description_xml_attr

const char dunedaq::oks::OksMethod::description_xml_attr = "description"
staticprivate

Definition at line 270 of file method.hpp.

◆ method_xml_tag

const char dunedaq::oks::OksMethod::method_xml_tag = "method"
staticprivate

Definition at line 268 of file method.hpp.

◆ name_xml_attr

const char dunedaq::oks::OksMethod::name_xml_attr = "name"
staticprivate

Definition at line 269 of file method.hpp.

◆ p_class

OksClass* dunedaq::oks::OksMethod::p_class
private

Definition at line 256 of file method.hpp.

◆ p_description

std::string dunedaq::oks::OksMethod::p_description
private

Definition at line 258 of file method.hpp.

◆ p_implementations

std::list<OksMethodImplementation*>* dunedaq::oks::OksMethod::p_implementations
private

Definition at line 259 of file method.hpp.

◆ p_name

std::string dunedaq::oks::OksMethod::p_name
private

Definition at line 257 of file method.hpp.


The documentation for this class was generated from the following files: