TkN 2.4
Toolkit for Nuclei
Loading...
Searching...
No Matches
tkproperty_list.cpp
1/********************************************************************************
2 * Copyright (c) : Université de Lyon 1, CNRS/IN2P3, UMR5822, *
3 * IP2I, F-69622 Villeurbanne Cedex, France *
4 * Normandie Université, ENSICAEN, UNICAEN, CNRS/IN2P3, *
5 * LPC Caen, F-14000 Caen, France *
6 * Contibutor(s) : *
7 * Jérémie Dudouet jeremie.dudouet@cnrs.fr [2020] *
8 * Diego Gruyer diego.gruyer@cnrs.fr [2020] *
9 * *
10 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#include "tkproperty_list.h"
15
16namespace tkn {
27}
28
29using namespace tkn;
30
31bool tkproperty_list::has_property(const tkstring &_property) const
32{
33 return (fProperties.count(_property)>0);
34}
35
37{
38 if(has_property(_property)) return fProperties.at(_property).value;
39 return "";
40}
41
43{
44 if(has_property(_property)) return fProperties.at(_property).unit;
45 return "";
46}
47
49{
50 if(has_property(_property)) return fProperties.at(_property).type;
51 return "";
52}
53
55{
56 glog << info << fname << " properties:" << do_endl;
57 for(const auto &prop : fProperties)
58 if (prop.first.match(_opt))
59 glog << info << left << setw(35) << prop.first << setw(35) << prop.second.value + " " + prop.second.unit << "[" << prop.second.type<< "]" << do_endl;
60}
61
63{
64 glog << info << fname << " data properties:" << do_endl;
65 for(const auto &prop : fDataProperties)
66 if (prop.first.match(_opt))
67 glog << info << left << setw(35) << prop.first << prop.second << do_endl;
68}
69
70vector<shared_ptr<tkmeasure>> tkproperty_list::get_data_properties(const tkstring &_opt)
71{
72 vector<shared_ptr<tkmeasure>> list;
73 for (auto &data : fDataProperties) {
74 if (data.first.match(_opt)) list.push_back(data.second);
75 }
76 return list;
77}
78
79shared_ptr<tkmeasure> tkproperty_list::get(const tkstring &_property) const
80{
81 if(fDataProperties.count(_property)>0)
82 return fDataProperties.at(_property);
83 return nullptr;
84}
85
86void tkproperty_list::add_property_str(const tkstring &_name, const tkstring &_val, const tkstring &_unit, const tkstring &_type)
87{
88 fProperties[_name].value = _val;
89 fProperties[_name].unit = _unit;
90 fProperties[_name].type = _type;
91}
92
93void tkproperty_list::add_property(const tkstring &_name, const shared_ptr<tkmeasure> &_property, const tkstring &_value_str, const tkstring &_unit_str)
94{
95 tkstring val = tkstring::form("%f",_property->get_value());
96 tkstring unit = _property->get_unit();
97 if(!_value_str.is_empty()) val = _value_str;
98 if(_unit_str!="!") unit = _unit_str;
99 add_property_str(_name,val,unit,"FLOAT");
100 fDataProperties[_name] = _property;
101}
102
103#ifdef HAS_ROOT
104ClassImp(tkproperty_list);
105#endif
106
107
Contains list of properties.
tkstring get_property_unit(const tkstring &_property) const
get the property unnit as a string
void list_data_properties(const tkstring &_opt="*") const
list the available tkmeasure properties
bool has_property(const tkstring &_property) const
to check if the property is available
shared_ptr< tkmeasure > get(const tkstring &_property) const
get the property as tkmeasure
tkstring get_property_type(const tkstring &_property) const
get the property type as a string
tkstring get_property(const tkstring &_property) const
get the property value as a string
vector< shared_ptr< tkmeasure > > get_data_properties(const tkstring &_opt="*")
get a vector of data properties according to a regular expression
void list_properties(const tkstring &_opt="*") const
list the available properties
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:31
static const char * form(const char *_format,...)
Definition tkstring.cpp:408
bool is_empty() const
Definition tkstring.h:140
Definition tklog.cpp:16
tklog & info(tklog &log)
Definition tklog.h:313
tklog & do_endl(tklog &log)
Definition tklog.h:212