JeVois  1.8
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Component.C
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 // This code is inspired by the Neuromorphic Robotics Toolkit (http://nrtkit.org)
19 
20 #include <jevois/Debug/Log.H>
24 #include <jevois/Util/Utils.H>
26 
27 #include <fstream>
28 #include <algorithm> // for std::all_of
29 
30 // ######################################################################
31 jevois::Component::Component(std::string const & instanceName) :
32  itsInstanceName(instanceName), itsInitialized(false), itsParent(nullptr), itsPath()
33 {
34  JEVOIS_TRACE(5);
35 }
36 
37 // ######################################################################
38 std::string const & jevois::Component::className() const
39 {
40  boost::shared_lock<boost::shared_mutex> lck(itsMetaMtx);
41 
42  // We need the (derived!) component to be fully constructed for demangle to work, hence the const_cast here:
43  if (itsClassName.empty()) *(const_cast<std::string *>(&itsClassName)) = jevois::demangle(typeid(*this).name());
44 
45  return itsClassName;
46 }
47 
48 // ######################################################################
49 std::string const & jevois::Component::instanceName() const
50 { return itsInstanceName; }
51 
52 // ######################################################################
54 {
55  JEVOIS_TRACE(5);
56 
57  LDEBUG("Deleting Component");
58 
59  // Recursively un-init us and our subs; call base class version as derived classes are destroyed:
60  if (itsInitialized) jevois::Component::uninit();
61 
62  // All right, we need to nuke our subs BEFORE we get destroyed, since they will backflow to us (for param
63  // notices, recursive descriptor access, etc):
64  boost::upgrade_lock<boost::shared_mutex> uplck(itsSubMtx);
65 
66  while (itsSubComponents.empty() == false)
67  {
68  auto itr = itsSubComponents.begin();
69  doRemoveSubComponent(itr, uplck, "SubComponent");
70  }
71 }
72 
73 // ######################################################################
74 void jevois::Component::removeSubComponent(std::string const & instanceName, bool warnIfNotFound)
75 {
76  JEVOIS_TRACE(5);
77 
78  boost::upgrade_lock<boost::shared_mutex> uplck(itsSubMtx);
79 
80  for (auto itr = itsSubComponents.begin(); itr != itsSubComponents.end(); ++itr)
81  if ((*itr)->instanceName() == instanceName)
82  {
83  // All checks out, get doRemoveSubComponent() to do the work:
84  doRemoveSubComponent(itr, uplck, "SubComponent");
85  return;
86  }
87 
88  if (warnIfNotFound) LERROR("SubComponent [" << instanceName << "] not found. Ignored.");
89 }
90 
91 // ######################################################################
92 void jevois::Component::doRemoveSubComponent(std::vector<std::shared_ptr<jevois::Component> >::iterator & itr,
93  boost::upgrade_lock<boost::shared_mutex> & uplck,
94  std::string const & displayname)
95 {
96  JEVOIS_TRACE(5);
97 
98  // Try to delete and let's check that it will actually be deleted:
99  std::shared_ptr<jevois::Component> component = *itr;
100 
101  LDEBUG("Removing " << displayname << " [" << component->descriptor() << ']');
102 
103  // Un-init the component:
104  if (component->initialized()) component->uninit();
105 
106  // Remove it from our list of subs:
107  boost::upgrade_to_unique_lock<boost::shared_mutex> ulck(uplck);
108  itsSubComponents.erase(itr);
109 
110  if (component.use_count() > 1)
111  LERROR(component.use_count() - 1 << " additional external shared_ptr reference(s) exist to "
112  << displayname << " [" << component->descriptor() << "]. It was removed but NOT deleted.");
113 
114  component.reset(); // nuke the shared_ptr, this should yield a delete unless use_count was > 1
115 }
116 
117 // ######################################################################
119 {
120  JEVOIS_TRACE(6);
121 
122  boost::shared_lock<boost::shared_mutex> lck(itsMtx);
123 
124  if (dynamic_cast<jevois::Manager *>(itsParent) != nullptr) return true;
125 
126  return false;
127 }
128 
129 // ######################################################################
130 void jevois::Component::init()
131 {
132  JEVOIS_TRACE(5);
133 
134  if (itsInitialized) { LERROR("Already initialized. Ignored."); return; }
135 
136  LDEBUG("Initializing...");
137 
138  runPreInit();
139  setInitialized();
140  runPostInit();
141 
142  LDEBUG("Initialized.");
143 }
144 
145 // ######################################################################
146 void jevois::Component::runPreInit()
147 {
148  JEVOIS_TRACE(6);
149 
150  // Pre-init all subComponents:
151  {
152  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
153  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->runPreInit();
154  }
155 
156  // Then us. So the last one here will be the manager, and its preInit() will parse the command line:
157  preInit();
158 
159  // If we have some parameters with callbacks that have not been set expicitly by the command-line, call the callback a
160  // first time here. This may add some new parameters
162 }
163 
164 // ######################################################################
165 void jevois::Component::setInitialized()
166 {
167  JEVOIS_TRACE(6);
168 
169  // First all subComponents
170  {
171  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
172  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->setInitialized();
173  }
174 
175  // Then us:
176  itsInitialized = true;
177 }
178 
179 // ######################################################################
180 void jevois::Component::runPostInit()
181 {
182  JEVOIS_TRACE(6);
183 
184  // First all subComponents:
185  {
186  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
187  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->runPostInit();
188  }
189 
190  // Then us:
191  postInit();
192 }
193 
194 // ######################################################################
196 {
197  JEVOIS_TRACE(6);
198 
199  return itsInitialized;
200 }
201 
202 // ######################################################################
203 void jevois::Component::uninit()
204 {
205  JEVOIS_TRACE(5);
206 
207  if (itsInitialized)
208  {
209  LDEBUG("Uninitializing...");
210 
211  runPreUninit();
212  setUninitialized();
213  runPostUninit();
214 
215  LDEBUG("Uninitialized.");
216  }
217 }
218 
219 // ######################################################################
220 void jevois::Component::runPreUninit()
221 {
222  JEVOIS_TRACE(6);
223 
224  // First all subComponents:
225  {
226  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
227  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->runPreUninit();
228  }
229 
230  // Then us:
231  preUninit();
232 }
233 
234 // ######################################################################
235 void jevois::Component::setUninitialized()
236 {
237  JEVOIS_TRACE(6);
238 
239  // First us:
240  itsInitialized = false;
241 
242  // Then all subComponents
243  {
244  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
245  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->setUninitialized();
246  }
247 }
248 
249 // ######################################################################
250 void jevois::Component::runPostUninit()
251 {
252  JEVOIS_TRACE(6);
253 
254  // First us:
255  postUninit();
256 
257  // Then all subComponents:
258  {
259  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
260  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->runPostUninit();
261  }
262 }
263 
264 // ######################################################################
265 std::string jevois::Component::descriptor() const
266 {
267  JEVOIS_TRACE(8);
268 
269  // Top-level components or those with no parent just return their instance name. Sub-components return a chain of
270  // component instance names up to the top level:
271 
272  boost::shared_lock<boost::shared_mutex> lck(itsMtx);
273 
274  if (itsParent && dynamic_cast<jevois::Manager *>(itsParent) == nullptr)
275  return itsParent->descriptor() + ':' + itsInstanceName;
276 
277  return itsInstanceName;
278 }
279 
280 // ######################################################################
281 void jevois::Component::findParamAndActOnIt(std::string const & descrip,
282  std::function<void(jevois::ParameterBase *, std::string const &)> doit,
283  std::function<bool()> empty) const
284 {
285  JEVOIS_TRACE(9);
286 
287  // Split this parameter descriptor by single ":" (skipping over all "::")
288  std::vector<std::string> desc = jevois::split(descrip, ":" /*"FIXME "(?<!:):(?!:)" */);
289 
290  if (desc.empty()) std::range_error(descriptor() + ": Cannot parse empty parameter name");
291 
292  // Recursive call with the vector of tokens:
293  findParamAndActOnIt(desc, true, 0, "", doit);
294 
295  if (empty()) throw std::range_error(descriptor() + ": No Parameter named [" + descrip + ']');
296 }
297 
298 // ######################################################################
299 void jevois::Component::findParamAndActOnIt(std::vector<std::string> const & descrip,
300  bool recur, size_t idx, std::string const & unrolled,
301  std::function<void(jevois::ParameterBase *, std::string const &)> doit) const
302 {
303  JEVOIS_TRACE(9);
304 
305  // Have we not yet reached the bottom (still have some component names before the param)?
306  if (descrip.size() > idx + 1)
307  {
308  // We have some token before the param, is it a '*', in which case we turn on recursion?
309  if (descrip[idx] == "*") { recur = true; ++idx; }
310  else {
311  // We have some Instance specification(s) of component(s) before the param. Let's see if we match against the
312  // first one. If it's a match, eat up the first token and send the rest of the tokens to our subcomponents,
313  // otherwise keep the token and recurse the entire list to the subs:
314  if (itsInstanceName == descrip[idx]) { recur = false; ++idx; }
315  }
316  }
317 
318  // Have we reached the end of the list (the param name)?
319  if (descrip.size() == idx + 1)
320  {
321  // We have just a paramname, let's see if we have that param:
322  boost::shared_lock<boost::shared_mutex> lck(itsParamMtx);
323 
324  for (auto const & p : itsParameterList)
325  if (p.second->name() == descrip[idx])
326  {
327  // param name is a match, act on it:
328  std::string ur = itsInstanceName + ':' + p.second->name();
329  if (unrolled.empty() == false) ur = unrolled + ':' + ur;
330  doit(p.second, ur);
331  }
332  }
333 
334  // Recurse through our subcomponents if recur is on or we have not yet reached the bottom:
335  if (recur || descrip.size() > idx + 1)
336  {
337  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
338 
339  std::string ur;
340  if (unrolled.empty()) ur = itsInstanceName; else ur = unrolled + ':' + itsInstanceName;
341 
342  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->findParamAndActOnIt(descrip, recur, idx, ur, doit);
343  }
344 }
345 
346 // ######################################################################
347 std::vector<std::string> jevois::Component::setParamString(std::string const & descriptor, std::string const & val)
348 {
349  JEVOIS_TRACE(7);
350 
351  std::vector<std::string> ret;
352  findParamAndActOnIt(descriptor,
353 
354  [&ret,&val](jevois::ParameterBase * param, std::string const & unrolled)
355  { param->strset(val); ret.push_back(unrolled); },
356 
357  [&ret]() { return ret.empty(); }
358  );
359  return ret;
360 }
361 
362 // ######################################################################
363 void jevois::Component::setParamStringUnique(std::string const & descriptor, std::string const & val)
364 {
365  JEVOIS_TRACE(7);
366 
367  std::vector<std::string> ret = setParamString(descriptor, val);
368  if (ret.size() > 1)
369  throw std::range_error("Multiple matches for descriptor [" + descriptor + "] while only one is allowed");
370 }
371 
372 // ######################################################################
373 std::vector<std::pair<std::string, std::string> >
375 {
376  JEVOIS_TRACE(8);
377 
378  std::vector<std::pair<std::string, std::string> > ret;
379  findParamAndActOnIt(descriptor,
380 
381  [&ret](jevois::ParameterBase * param, std::string const & unrolled)
382  { ret.push_back(std::make_pair(unrolled, param->strget())); },
383 
384  [&ret]() { return ret.empty(); }
385  );
386  return ret;
387 }
388 
389 // ######################################################################
390 std::string jevois::Component::getParamStringUnique(std::string const & descriptor) const
391 {
392  JEVOIS_TRACE(8);
393 
394  std::vector<std::pair<std::string, std::string> > ret = getParamString(descriptor);
395  if (ret.size() > 1)
396  throw std::range_error("Multiple matches for descriptor [" + descriptor + "] while only one is allowed");
397 
398  // We know that ret is not empty because getParamString() throws if the param is not found:
399  return ret[0].second;
400 }
401 
402 // ######################################################################
403 void jevois::Component::freezeParam(std::string const & paramdescriptor)
404 {
405  int n = 0;
406  findParamAndActOnIt(paramdescriptor,
407  [&n](jevois::ParameterBase * param, std::string const & JEVOIS_UNUSED_PARAM(unrolled))
408  { param->freeze(); ++n; },
409 
410  [&n]() { return (n == 0); }
411  );
412 }
413 
414 // ######################################################################
415 void jevois::Component::unFreezeParam(std::string const & paramdescriptor)
416 {
417  int n = 0;
418  findParamAndActOnIt(paramdescriptor,
419  [&n](jevois::ParameterBase * param, std::string const & JEVOIS_UNUSED_PARAM(unrolled))
420  { param->unFreeze(); ++n; },
421 
422  [&n]() { return (n == 0); }
423  );
424 }
425 
426 // ######################################################################
428 {
429  boost::shared_lock<boost::shared_mutex> lck(itsParamMtx);
430 
431  for (auto const & p : itsParameterList) p.second->freeze();
432 }
433 
434 // ######################################################################
436 {
437  boost::shared_lock<boost::shared_mutex> lck(itsParamMtx);
438 
439  for (auto const & p : itsParameterList) p.second->unFreeze();
440 }
441 
442 // ######################################################################
443 void jevois::Component::setParamsFromFile(std::string const & filename)
444 {
445  std::string const absfile = absolutePath(filename);
446  std::ifstream ifs(absfile);
447  if (!ifs) LFATAL("Could not open file " << absfile);
448  setParamsFromStream(ifs, absfile);
449 }
450 
451 // ######################################################################
452 std::istream & jevois::Component::setParamsFromStream(std::istream & is,std::string const & absfile)
453 {
454  size_t linenum = 1;
455  for (std::string line; std::getline(is, line); /* */)
456  {
457  // Skip over comments:
458  if (line.length() && line[0] == '#') { ++linenum; continue; }
459 
460  // Skip over empty lines:
461  if (std::all_of(line.begin(), line.end(), [](unsigned char c) { return std::isspace(c); })) { ++linenum; continue; }
462 
463  // Parse descriptor=value:
464  size_t idx = line.find('=');
465  if (idx == line.npos) LFATAL("No '=' symbol found at line " << linenum << " in " << absfile);
466  if (idx == 0) LFATAL("No parameter descriptor found at line " << linenum << " in " << absfile);
467  if (idx == line.length() - 1) LFATAL("No parameter value found at line " << linenum << " in " << absfile);
468 
469  std::string desc = line.substr(0, idx);
470  std::string val = line.substr(idx + 1);
471 
472  // Be nice and clean whitespace at start and end (not in the middle):
473  while (desc.length() > 0 && std::isspace(desc[0])) desc.erase(0, 1);
474  while (desc.length() > 0 && std::isspace(desc[desc.length()-1])) desc.erase(desc.length()-1, 1);
475  if (desc.empty()) LFATAL("Invalid blank parameter descriptor at line " << linenum << " in " << absfile);
476 
477  while (val.length() > 0 && std::isspace(val[0])) val.erase(0, 1);
478  while (val.length() > 0 && std::isspace(val[val.length()-1])) val.erase(val.length()-1, 1);
479  if (val.empty()) LFATAL("Invalid blank parameter value at line " << linenum << " in " << absfile);
480 
481  // Ok, set that param:
482  setParamString(desc, val);
483 
484  ++linenum;
485  }
486  return is;
487 }
488 
489 // ######################################################################
490 void jevois::Component::setPath(std::string const & path)
491 {
492  JEVOIS_TRACE(5);
493 
494  // First all subComponents:
495  {
496  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
497  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->setPath(path);
498  }
499 
500  itsPath = path;
501 }
502 
503 // ######################################################################
504 std::string jevois::Component::absolutePath(std::string const & path)
505 {
506  JEVOIS_TRACE(6);
507 
508  // If path is empty, return itsPath (be it empty of not):
509  if (path.empty()) return itsPath;
510 
511  // no-op if the given path is already absolute:
512  if (path[0] == '/') return path;
513 
514  // no-op if itsPath is empty:
515  if (itsPath.empty()) return path;
516 
517  // We know itsPath is not empty and path does not start with a / and is not empty; concatenate both:
518  return itsPath + '/' + path;
519 }
520 
521 // ######################################################################
522 void jevois::Component::paramInfo(std::shared_ptr<UserInterface> s, std::map<std::string, std::string> & categs,
523  bool skipFrozen, std::string const & cname, std::string const & pfx)
524 {
525  JEVOIS_TRACE(9);
526 
527  std::string const compname = cname.empty() ? itsInstanceName : cname + ':' + itsInstanceName;
528 
529  // First add our own params:
530  {
531  boost::shared_lock<boost::shared_mutex> lck(itsParamMtx);
532  for (auto const & p : itsParameterList)
533  {
534  jevois::ParameterSummary const ps = p.second->summary();
535 
536  if (skipFrozen && ps.frozen) continue;
537 
538  categs[ps.category] = ps.categorydescription;
539 
540  if (ps.frozen) s->writeString(pfx, "F"); else s->writeString(pfx, "N");
541  s->writeString(pfx, compname);
542  s->writeString(pfx, ps.category);
543  s->writeString(pfx, ps.name);
544  s->writeString(pfx, ps.valuetype);
545  s->writeString(pfx, ps.value);
546  s->writeString(pfx, ps.defaultvalue);
547  s->writeString(pfx, ps.validvalues);
548  s->writeString(pfx, ps.description);
549  }
550  }
551 
552  // Then recurse through our subcomponents:
553  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
554  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->paramInfo(s, categs, skipFrozen, compname, pfx);
555 
556  // At the root only, dump the list of categories:
557  if (cname.empty())
558  {
559  s->writeString(pfx, "C");
560  for (auto const & c : categs)
561  {
562  s->writeString(pfx, c.first);
563  s->writeString(pfx, c.second);
564  }
565  }
566 }
567 
568 // ######################################################################
569 void jevois::Component::populateHelpMessage(std::string const & cname,
570  std::unordered_map<std::string,
571  std::unordered_map<std::string,
572  std::vector<std::pair<std::string, std::string> > > > & helplist,
573  bool recurse) const
574 {
575  JEVOIS_TRACE(9);
576 
577  std::string const compname = cname.empty() ? itsInstanceName : cname + ':' + itsInstanceName;
578 
579  // First add our own params:
580  {
581  boost::shared_lock<boost::shared_mutex> lck(itsParamMtx);
582  for (auto const & p : itsParameterList)
583  {
584  jevois::ParameterSummary const ps = p.second->summary();
585 
586  if (ps.frozen) continue; // skip frozen parameters
587 
588  std::string const key1 = ps.category + ": "+ ps.categorydescription;
589  std::string const key2 = " --" + ps.name + " (" + ps.valuetype + ") default=[" + ps.defaultvalue + "]" +
590  (ps.validvalues == "None:[]" ? "\n" : " " + ps.validvalues + "\n") + " " + ps.description;
591  std::string val = "";
592  if (ps.value != ps.defaultvalue) val = ps.value;
593  helplist[key1][key2].push_back(std::make_pair(compname, val));
594  }
595  }
596 
597  // Then recurse through our subcomponents:
598  if (recurse)
599  {
600  boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
601  for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->populateHelpMessage(compname, helplist);
602  }
603 }
604 
605 // ######################################################################
606 std::string jevois::Component::computeInstanceName(std::string const & instance, std::string const & classname) const
607 {
608  JEVOIS_TRACE(9);
609 
610  std::string inst = instance;
611 
612  // If empty instance, replace it by the classname:
613  if (inst.empty())
614  {
615  // Use the class name:
616  inst = classname + '#';
617 
618  // Remove any namespace:: prefix:
619  size_t const idxx = inst.rfind(':'); if (idxx != inst.npos) inst = inst.substr(idxx + 1);
620  }
621 
622  // Replace all # characters by some number, if necessary:
623  std::vector<std::string> vec = jevois::split(inst, "#");
624  if (vec.size() > 1)
625  {
626  // First try to have no numbers in there:
627  inst = jevois::join(vec, ""); bool found = false;
628  for (std::shared_ptr<Component> const & c : itsSubComponents)
629  if (c->instanceName() == inst) { found = true; break; }
630 
631  if (found)
632  {
633  // Ok, we have some conflict, so let's add some numbers where the # signs were:
634  inst = "";
635  for (std::string const & v : vec)
636  {
637  if (v.empty()) continue;
638 
639  inst += v;
640  size_t largestId = 1;
641 
642  while (true)
643  {
644  std::string stem = inst + std::to_string(largestId);
645  bool gotit = false;
646 
647  for (std::shared_ptr<Component> const & c : itsSubComponents)
648  if (c->instanceName() == stem) { gotit = true; break; }
649 
650  if (gotit == false) { inst = stem; break; }
651 
652  ++largestId;
653  }
654  }
655  }
656 
657  LDEBUG("Using automatic instance name [" << inst << ']');
658  return inst;
659  }
660 
661  // If we have not returned yet, no # was given. Throw if there is a conflict:
662  for (std::shared_ptr<Component> const & c : itsSubComponents)
663  if (c->instanceName() == inst)
664  throw std::runtime_error("Provided instance name [" + instance + "] clashes with existing sub-components.");
665 
666  return inst;
667 }
668 
#define LDEBUG(msg)
Convenience macro for users to print out console or syslog messages, DEBUG level. ...
Definition: Log.H:155
std::string name
Plain name of the parameter.
Definition: Parameter.H:90
std::string validvalues
Description of the parameter&#39;s valid values specification, as a string.
Definition: Parameter.H:105
std::string description
Description of the parameter.
Definition: Parameter.H:93
virtual void preInit()
Called before all sub-Components are init()ed.
Definition: Component.H:459
std::vector< std::string > setParamString(std::string const &paramdescriptor, std::string const &val)
Set a parameter value, by string.
Definition: Component.C:347
void unFreeze()
Unfreeze this parameter, it becomes read-write and will show up in the help message.
Definition: ParameterImpl.H:41
ParameterSummary provides a summary about a parameter.
Definition: Parameter.H:83
std::string value
Current value of the parameter, as a string.
Definition: Parameter.H:102
std::string const & className() const
The class name of this component.
Definition: Component.C:38
std::string defaultvalue
Default value of the parameter, as a string.
Definition: Parameter.H:99
void setPath(std::string const &path)
Assign a filesystem path to this component.
Definition: Component.C:490
void setParamStringUnique(std::string const &paramdescriptor, std::string const &val)
Set a parameter value by string, simple version assuming only one parameter match.
Definition: Component.C:363
void setParamsFromFile(std::string const &filename)
Set some parameters from a file.
Definition: Component.C:443
#define JEVOIS_TRACE(level)
Trace object.
Definition: Log.H:267
bool isTopLevel() const
Returns true if this component is top-level, i.e., its parent is jevois::Manager. ...
Definition: Component.C:118
void freezeParam(std::string const &paramdescriptor)
Freeze a parameter, by name, see ParameterBase::freeze()
Definition: Component.C:403
bool initialized() const
Has this component been initialized yet?
Definition: Component.C:195
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level. ...
Definition: Log.H:193
std::string join(std::vector< std::string > const &strings, std::string const &delimiter)
Concatenate a vector of tokens into a string.
Definition: Utils.C:152
std::string getParamStringUnique(std::string const &paramdescriptor) const
Get a parameter value by string, simple version assuming only one parameter match.
Definition: Component.C:390
std::string demangle(std::string const &mangledName)
Demangle a mangled name.
Definition: DemangleImpl.H:54
virtual void preUninit()
Called before all sub-Components are uninit()ed.
Definition: Component.H:465
std::string valuetype
Parameter value type, as a string.
Definition: Parameter.H:96
virtual ~Component()
Virtual destructor for safe inheritance.
Definition: Component.C:53
std::string descriptor() const
Get our full descriptor (including all parents) as [Instancename]:[...]:[...].
Definition: Component.C:265
bool frozen
Flag that indicates whether parameter is frozen.
Definition: Parameter.H:114
void removeSubComponent(std::shared_ptr< Comp > &component)
Remove a sub-Component from this Component, by shared_ptr.
void freeze()
Freeze this parameter, it becomes read-only and will not show up in the help message.
Definition: ParameterImpl.H:37
Base class for Parameter.
Definition: Parameter.H:121
Component(std::string const &instance)
Constructor.
Definition: Component.C:31
virtual void strset(std::string const &valstring)=0
Set the value from a string representation of it.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level. ...
Definition: Log.H:212
std::istream & setParamsFromStream(std::istream &is, std::string const &absfile)
Set some parameters from an open stream.
Definition: Component.C:452
virtual void paramInfo(std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="")
Get machine-oriented descriptions of all parameters.
Definition: Component.C:522
virtual std::string const strget() const =0
Get the value as a string.
std::string category
Category of the parameter, as a string.
Definition: Parameter.H:108
virtual void postInit()
Called after all sub-Components are init()ed.
Definition: Component.H:462
std::vector< std::pair< std::string, std::string > > getParamString(std::string const &paramdescriptor) const
Get a parameter value, by string.
Definition: Component.C:374
void unFreezeParam(std::string const &paramdescriptor)
Unfreeze a parameter, by name, see ParameterBase::unFreeze()
Definition: Component.C:415
std::string to_string(T const &val)
Convert from type to string.
Definition: UtilsImpl.H:58
void callbackInitCall()
For all parameters that have a callback which has never been called, call it with the default param v...
void freezeAllParams()
Freeze all parameters.
Definition: Component.C:427
void unFreezeAllParams()
Unfreeze all parameters.
Definition: Component.C:435
std::string const & instanceName() const
The instance name of this component.
Definition: Component.C:49
std::string categorydescription
Category description.
Definition: Parameter.H:111
virtual void postUninit()
Called after all sub-Components are uninit()ed.
Definition: Component.H:468
std::string absolutePath(std::string const &path="")
If given path is relative (not starting with /), prepend the Component path to it.
Definition: Component.C:504
std::vector< std::string > split(std::string const &input, std::string const &regex="\+")
Split string into vector of tokens using a regex to specify what to split on; default regex splits by...
Definition: Utils.C:142