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 152 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 108 of file method.cpp.

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

121 :
122 p_class (p),
123 p_name (nm),
124 p_description (desc),
125 p_implementations (nullptr)
126{
127 oks::validate_not_empty(p_name, "method name");
128}
std::string p_description
Definition method.hpp:279

◆ ~OksMethod()

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

Definition at line 130 of file method.cpp.

131{
133 while(!p_implementations->empty()) {
135 p_implementations->pop_front();
136 delete i;
137 }
138
139 delete p_implementations;
140 }
141}
friend class OksMethodImplementation
Definition method.hpp:156

◆ OksMethod() [3/3]

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

Definition at line 229 of file method.cpp.

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

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

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

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

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

◆ get_description()

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

Get description of method.

Definition at line 214 of file method.hpp.

214{return p_description;}

◆ get_name()

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

Get name of method.

Definition at line 196 of file method.hpp.

196{return p_name;}

◆ implementations()

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

Get implementations of method.

Definition at line 230 of file method.hpp.

230{return p_implementations;}

◆ operator==()

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

Definition at line 145 of file method.cpp.

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

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

389{
391
392 if(i == 0) {
393 std::ostringstream text;
394 text << "Cannot remove implementation on language \"" << language << "\" since it does not exist.";
395 throw oks::SetOperationFailed("OksMethod::remove_implementation", text.str());
396 }
397
398 if(p_class) p_class->lock_file("OksMethod::remove_implementation");
399
400 p_implementations->remove(i);
401
402 if(p_implementations->empty()) {
403 delete p_implementations;
405 }
406
408}

◆ save()

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

Definition at line 204 of file method.cpp.

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

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

413{
414 if(p_description != desc) {
415 if(p_class) p_class->lock_file("OksMethod::set_description");
416
417 p_description = desc;
418
420 }
421}

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

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

Friends And Related Symbol Documentation

◆ OksClass

friend class OksClass
friend

Definition at line 155 of file method.hpp.

◆ OksKernel

friend class OksKernel
friend

Definition at line 154 of file method.hpp.

◆ OksMethodImplementation

friend class OksMethodImplementation
friend

Definition at line 156 of file method.hpp.

◆ operator<<

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

Definition at line 184 of file method.cpp.

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

Member Data Documentation

◆ description_xml_attr

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

Definition at line 293 of file method.hpp.

◆ method_xml_tag

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

Definition at line 291 of file method.hpp.

◆ name_xml_attr

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

Definition at line 292 of file method.hpp.

◆ p_class

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

Definition at line 277 of file method.hpp.

◆ p_description

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

Definition at line 279 of file method.hpp.

◆ p_implementations

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

Definition at line 280 of file method.hpp.

◆ p_name

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

Definition at line 278 of file method.hpp.


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