CARMA C++
MonitorContainer.h
Go to the documentation of this file.
1 #ifndef CARMA_MONITOR_MONITORCONTAINER_H
2 #define CARMA_MONITOR_MONITORCONTAINER_H
3 
4 
18 #include <string>
19 #include <vector>
20 
21 #include "carma/monitor/types.h"
24 
25 
26 namespace carma {
27 namespace monitor {
28 
29 
30 class MonitorSubsystem;
31 
32 
43 public:
44 
49  explicit MonitorContainer( const ::std::string & name );
50 
55 
56 
57  class Child {
58  friend class MonitorContainer;
59 
60  public:
61  explicit Child( );
62 
63  bool isNull( ) const;
64 
65  MonitorComponent * componentPtr( ) const;
66  MonitorComponent & componentRef( ) const;
67 
68  bool isMp( ) const;
69  MonitorPoint * mpPtr( ) const;
70  MonitorPoint & mpRef( ) const;
71 
72  bool isContainer( ) const;
73  MonitorContainer * containerPtr( ) const;
74  MonitorContainer & containerRef( ) const;
75 
76  bool isSubsystem( ) const;
77  MonitorSubsystem * subsystemPtr( ) const;
78  MonitorSubsystem & subsystemRef( ) const;
79 
80  private:
81  Child( MonitorComponent & component );
82 
83  MonitorComponent & handleBadComponentDeref( ) const;
84  MonitorPoint & handleBadMpDeref( ) const;
85  MonitorContainer & handleBadContainerDeref( ) const;
86  MonitorSubsystem & handleBadSubsystemDeref( ) const;
87 
88  static const unsigned char kMpBitMask = 1;
89  static const unsigned char kContainerBitMask = 2;
90  static const unsigned char kSubsystemBitMask = 4;
91 
92  MonitorComponent * componentPtr_;
93  unsigned char flags_;
94  };
95 
99  int getNumChildren( ) const;
100 
105  const Child & getChild( int index ) const;
106 
110  ::std::vector< Child > getChildVec( ) const;
111 
117  int getNumMonitorPoints( bool recurse = false ) const;
118 
122  virtual int getNumContainerChildren( ) const;
123 
128  virtual int getNumDescendants( ) const;
129 
134  virtual int getNumContainerDescendants( ) const;
135 
136 
145  getComponentPtr( const ::std::string & name,
146  bool caseSensitive ) const;
147 
152  MonitorPoint &
153  getMonitorPoint( const std::string & name,
154  bool caseSensitive ) const;
155 
156  MonitorPoint *
157  getMonitorPointPtr( const std::string & name,
158  bool caseSensitive ) const;
159 
164  MonitorPoint & getMonitorPoint( tagIDType tagID ) const;
165 
166  MonitorPoint * getMonitorPointPtr( tagIDType tagID ) const;
167 
175  void add(MonitorComponent& component);
176 
182 
189  void setValidity(MonitorPoint::VALIDITY validity);
190 
195  int getNumMonitorPoints();
196 
201  int getNumSamples();
202 
209  void setArchivePriority(
210  const MonitorComponent::ARCHIVE_PRIORITY priority,
211  bool onlyDEFAULT=true);
212 
213 
214 // ---------- Virtual methods that make this a MonitorComponent
215 
216  // Specialize the docs for this one..
223  virtual bool operator==(const MonitorComponent& component) const ;
224 
225  // Virtual, so doc is inherited
226  void setNoData() const ;
227 
228  // Virtual methods of MonitorComponent so docs are inherited
229  bool hasAllData() const ;
230 
231  // The sampleIndex is not used for this class
232  std::string toString(bool canonicalName = false, bool verbose = false,
233  bool value = true, int sampleIndex=0, int indent = 0) const ;
234 
235  std::string toStringAverage(bool canonicalName = false, bool verbose = false,
236  bool value = true, int indent = 0) const ;
237 
238  void setPersistent(bool persistent) ;
239 
252  virtual void setMonitorPointAttributes();
253 
254  // Virtual, so doc is inherited
255  virtual ::std::string monitorPointTags( bool untagged = false ) const;
256 
257  // Virtual, so doc is inherited
258  virtual ::std::string hierarchyToString(
259  bool canonical = false,
260  bool verbose = false,
261  bool value = true,
262  int sampleIndex = 0,
263  int indent = 0,
264  int levels = -1 ) const;
265 
266  // Virtual, so doc is inherited
267  virtual void hierarchyToVector(
268  ::std::vector< ::std::string > & hierarchyList,
269  bool canonical = false,
270  bool verbose = false,
271  int sampleIndex = 0 ) const;
272 
273  // Virtual, so doc is inherited
274  virtual ::std::string hierarchyToStringAverage(
275  bool canonical = false,
276  bool verbose = false,
277  bool value = true,
278  int indent = 0,
279  int levels = -1 ) const;
280 
281  // Virtual, so doc is inherited
282  virtual std::string leafToString( bool verbose = false,
283  bool value = true,
284  int sampleIndex = 0 ) const;
285 
286  // Virtual, so doc is inherited
287  virtual void setCanonicalName( const std::string & parents );
288 
289 protected:
290 
301  virtual void setLocalMonitorPointAttributes();
302 
303  static Child findDescendant( const MonitorContainer & rootContainer,
304  const ::std::string & name,
305  bool caseSensitive );
306 
307 private:
308  // No copying
309  MonitorContainer & operator=( const MonitorContainer & rhs );
310  MonitorContainer( const MonitorContainer & rhs );
311 
312  MonitorContainer( ); // Private default constructor!!
313 
314  static const Child kNullChild;
315 
316  ::std::vector< Child > children_;
317 };
318 
319 
320 } // namespace carma::monitor
321 } // namespace carma
322 
323 
324 // The default c'tor gives the correct answers for a NULL pointer
325 inline
326 carma::monitor::MonitorContainer::Child::Child( ) :
327 componentPtr_( 0 ),
328 flags_( 0 )
329 {
330 }
331 
332 
333 inline bool
334 carma::monitor::MonitorContainer::Child::isNull( ) const
335 {
336  return (componentPtr_ == 0);
337 }
338 
339 
341 carma::monitor::MonitorContainer::Child::componentPtr( ) const
342 {
343  return componentPtr_;
344 }
345 
346 
348 carma::monitor::MonitorContainer::Child::componentRef( ) const
349 {
350  if ( componentPtr_ != 0 )
351  return *componentPtr_;
352  else
353  return handleBadComponentDeref();
354 }
355 
356 
357 inline bool
358 carma::monitor::MonitorContainer::Child::isMp( ) const
359 {
360  return (flags_ & kMpBitMask);
361 }
362 
363 
365 carma::monitor::MonitorContainer::Child::mpPtr( ) const
366 {
367  if ( flags_ & kMpBitMask )
368  return static_cast< MonitorPoint * >( componentPtr_ );
369  else
370  return 0;
371 }
372 
373 
375 carma::monitor::MonitorContainer::Child::mpRef( ) const
376 {
377  if ( flags_ & kMpBitMask )
378  return *static_cast< MonitorPoint * >( componentPtr_ );
379  else
380  return handleBadMpDeref();
381 }
382 
383 
384 inline bool
385 carma::monitor::MonitorContainer::Child::isContainer( ) const
386 {
387  return (flags_ & kContainerBitMask);
388 }
389 
390 
392 carma::monitor::MonitorContainer::Child::containerPtr( ) const
393 {
394  if ( flags_ & kContainerBitMask )
395  return static_cast< MonitorContainer * >( componentPtr_ );
396  else
397  return 0;
398 }
399 
400 
402 carma::monitor::MonitorContainer::Child::containerRef( ) const
403 {
404  if ( flags_ & kContainerBitMask )
405  return *static_cast< MonitorContainer * >( componentPtr_ );
406  else
407  return handleBadContainerDeref();
408 }
409 
410 
411 inline bool
412 carma::monitor::MonitorContainer::Child::isSubsystem( ) const
413 {
414  return (flags_ & kSubsystemBitMask);
415 }
416 
417 
418 inline int
420 {
421  return children_.size();
422 }
423 
424 
425 inline const carma::monitor::MonitorContainer::Child &
427 {
428  if ( (index >= 0) && (static_cast< size_t >( index ) < children_.size()) )
429  return children_[ index ];
430  else
431  return kNullChild;
432 }
433 
434 
435 inline ::std::vector< carma::monitor::MonitorContainer::Child >
437 {
438  return children_;
439 }
440 
441 
442 #endif
VALIDITY
Validity states of the data value.
Definition: MonitorPoint.h:132
virtual bool operator==(const MonitorComponent &component) const
Compares this monitor container for equality to the one passed.
int getNumChildren() const
Get the number of monitor components contained by this component.
ARCHIVE_PRIORITY
Archiving priority.
virtual ::std::string hierarchyToString(bool canonical=false, bool verbose=false, bool value=true, int sampleIndex=0, int indent=0, int levels=-1) const
Dump this and all contained monitor components to a string.
Abstract base class for all monitor points.
void setArchivePriority(const MonitorComponent::ARCHIVE_PRIORITY priority, bool onlyDEFAULT=true)
Recursively set the archive priority of all monitor points below.
The MonitorComponent class is an interface used to build the monitor hierarchy.
virtual ::std::string monitorPointTags(bool untagged=false) const
Write list of monitor points and their tagIDs to a string, one monitor point per line.
virtual void setMonitorPointAttributes()
Set attributes of all monitor points held anywhere in the hierarchy within (and below) this container...
int getNumMonitorPoints()
Get the total number of monitor points in this container.
bool hasAllData() const
See if all MPs in this component and below have data samples.
virtual int getNumContainerChildren() const
Get the number of child monitor containers contained by this component.
virtual std::string leafToString(bool verbose=false, bool value=true, int sampleIndex=0) const
Dump all leaf nodes below this component to a string.
virtual int getNumDescendants() const
Get the total number of monitor components contained by this component and it&#39;s children.
void setValidity(MonitorPoint::VALIDITY validity)
Recursively set validity for all samples of all monitor points below this container.
std::string toString(bool canonicalName=false, bool verbose=false, bool value=true, int sampleIndex=0, int indent=0) const
Write this monitor component to a string.
MonitorPoint & getMonitorPoint(const std::string &name, bool caseSensitive) const
Get a monitor point by name (hierarchical name OK).
MonitorComponent * getComponentPtr(const ::std::string &name, bool caseSensitive) const
Get a contained monitor component by hierarchical name The hierarchical name starts below this contai...
virtual int getNumContainerDescendants() const
Get the number of child monitor containers contained by this component and it&#39;s children.
Abstract base class for a monitor point.
Definition: MonitorPoint.h:68
void setNoData() const
Recursively mark all data samples as INVALID_NO_DATA.
void add(MonitorComponent &component)
Add a subcomponent to this container A reference is kept to this subcomponent, so the caller is respo...
MonitorPoint & getFirstMonitorPoint()
Recursively find the first monitor point in this container.
virtual void hierarchyToVector(::std::vector< ::std::string > &hierarchyList, bool canonical=false, bool verbose=false, int sampleIndex=0) const
Dump this and all contained monitor component strings into a map hierarchy.
A composite interface used to build the monitor system hierarchy.
virtual ::std::string hierarchyToStringAverage(bool canonical=false, bool verbose=false, bool value=true, int indent=0, int levels=-1) const
Dump this and all contained monitor components to a string.
A generic monitor system container base class.
type definitions for monitor system
virtual void setLocalMonitorPointAttributes()
Set attributes of all monitor points held directly by this container.
int getNumSamples()
Get the total number of samples in this container.
const Child & getChild(int index) const
Get reference to child monitor component by index.
virtual bool isSubsystem() const
Check if the component is a MonitorSubsystem.
std::string toStringAverage(bool canonicalName=false, bool verbose=false, bool value=true, int indent=0) const
Write this monitor component to a string, using frame average values.
::std::vector< Child > getChildVec() const
Get a vector of monitor components contained by this component.
Abstract MonitorSubsystem base class.
void setPersistent(bool persistent)
Set the persistent attribute for the value of a MonitorPoint, or in the case of a container for its d...
virtual void setCanonicalName(const std::string &parents)
Recursively set the canonical component name for this and all below.