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
OksMethodImplementationfind_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

OksClassp_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 157 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 113 of file method.cpp.

113 :
114 p_class (p),
115 p_name (nm),
116 p_implementations (nullptr)
117{
118 try {
119 oks::validate_not_empty(p_name, "method name");
120 }
121 catch(std::exception& ex) {
122 Oks::error_msg("OksMethod::OksMethod()") << ex.what() << std::endl;
123 }
124}
std::list< OksMethodImplementation * > * p_implementations
Definition method.hpp:285
static std::ostream & error_msg(const char *)
Definition kernel.cpp:561
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 126 of file method.cpp.

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

◆ ~OksMethod()

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

Definition at line 135 of file method.cpp.

136{
138 while(!p_implementations->empty()) {
140 p_implementations->pop_front();
141 delete i;
142 }
143
144 delete p_implementations;
145 }
146}
friend class OksMethodImplementation
Definition method.hpp:161

◆ OksMethod() [3/3]

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

Definition at line 234 of file method.cpp.

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

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) p_class->lock_file("OksMethod::add_implementation");
379
380 if(!p_implementations) {
381 p_implementations = new std::list<OksMethodImplementation *>();
382 }
383
384 OksMethodImplementation * i = new OksMethodImplementation(language, prototype, body);
385
386 p_implementations->push_back(i);
387 i->p_method = this;
388
389 if(p_class) p_class->registrate_class_change(OksClass::ChangeMethodImplementation, (const void *)this);
390}
OksMethodImplementation * find_implementation(const std::string &language) const
Find method implementation.
Definition method.cpp:359

◆ 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 359 of file method.cpp.

360{
362 for(std::list<OksMethodImplementation *>::iterator i = p_implementations->begin(); i != p_implementations->end(); ++i)
363 if(language == (*i)->get_language()) 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 219 of file method.hpp.

219{return p_description;}

◆ get_name()

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

Get name of method.

Definition at line 201 of file method.hpp.

201{return p_name;}

◆ implementations()

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

Get implementations of method.

Definition at line 235 of file method.hpp.

235{return p_implementations;}

◆ operator==()

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

Definition at line 150 of file method.cpp.

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

◆ 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 393 of file method.cpp.

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

◆ save()

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

Definition at line 209 of file method.cpp.

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

◆ 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 417 of file method.cpp.

418{
419 if(p_description != desc) {
420 if(p_class) p_class->lock_file("OksMethod::set_description");
421
422 p_description = desc;
423
424 if(p_class) p_class->registrate_class_change(OksClass::ChangeMethodDescription, (const void *)this);
425 }
426}

◆ 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 303 of file method.cpp.

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

◆ OksClass

friend class OksClass
friend

Definition at line 160 of file method.hpp.

◆ OksKernel

friend class OksKernel
friend

Definition at line 159 of file method.hpp.

◆ OksMethodImplementation

friend class OksMethodImplementation
friend

Definition at line 161 of file method.hpp.

◆ operator<<

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

Definition at line 189 of file method.cpp.

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

Member Data Documentation

◆ description_xml_attr

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

Definition at line 298 of file method.hpp.

◆ method_xml_tag

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

Definition at line 296 of file method.hpp.

◆ name_xml_attr

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

Definition at line 297 of file method.hpp.

◆ p_class

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

Definition at line 282 of file method.hpp.

◆ p_description

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

Definition at line 284 of file method.hpp.

◆ p_implementations

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

Definition at line 285 of file method.hpp.

◆ p_name

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

Definition at line 283 of file method.hpp.


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