LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
lsst::pex::logging::Component Class Reference

Create a component in the verbosity tree (deprecated). More...

#include <Component.h>

Public Types

enum  { INHERIT_VERBOSITY = -9999 }
 

Public Member Functions

 Component (const std::string &name=".", int verbosity=INHERIT_VERBOSITY)
 
 ~Component ()
 
void add (const std::string &name, int verbosity, const std::string &separator)
 
int getVerbosity (const std::string &name, const std::string &separator)
 
int highestVerbosity (int highest=0)
 
void printVerbosity (std::ostream &fp, int depth=0)
 
void setVerbosity (int verbosity)
 

Private Types

typedef boost::tokenizer
< boost::char_separator< char > > 
tokenizer
 
typedef std::map< const
std::string, Component * > 
comp_map
 

Private Member Functions

void add (tokenizer::iterator token, const tokenizer::iterator end, int verbosity)
 
int getVerbosity (tokenizer::iterator token, const tokenizer::iterator end, int defaultVerbosity)
 

Private Attributes

std::string * _name
 
int _verbosity
 
comp_map_subcomp
 

Detailed Description

Create a component in the verbosity tree (deprecated).

Deprecated:
threshold::Memory class now provides this functionality.

A name is a string of the form aaa.bbb.ccc, and may itself contain further subcomponents. The Component structure doesn't in fact contain its full name, but only the first part.

The reason for this is inheritance — verbosity is inherited, but may be overriden. For example, if "foo" is at level 2 then "foo.goo.hoo" is taken to be at level 2 unless set specifically – but this inheritance is dynamic (so changing "foo" to 3 changes "foo.goo.hoo" too). However, I may also set "foo.goo.hoo" explicitly, in which case "foo"'s value is irrelevant — but "foo.goo" continues to inherit it.

Definition at line 62 of file Component.h.

Member Typedef Documentation

typedef std::map<const std::string, Component *> lsst::pex::logging::Component::comp_map
private

Definition at line 79 of file Component.h.

typedef boost::tokenizer<boost::char_separator<char> > lsst::pex::logging::Component::tokenizer
private

Definition at line 78 of file Component.h.

Member Enumeration Documentation

anonymous enum
Enumerator
INHERIT_VERBOSITY 

Definition at line 64 of file Component.h.

Constructor & Destructor Documentation

Component::Component ( const std::string &  name = ".",
int  verbosity = INHERIT_VERBOSITY 
)

Initialize the component structure.

Parameters
namecomponent's name
verbositycomponent's verbosity

Definition at line 45 of file Component.cc.

47  : _name(new std::string(name)),
48  _verbosity(verbosity),
49  _subcomp(*new(comp_map)) {
50 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
std::map< const std::string, Component * > comp_map
Definition: Component.h:79
Component::~Component ( )

Destroy the component structure.

Definition at line 54 of file Component.cc.

54  {
55  // Note from rlp: memory leak! map members not deleted.
56  delete &_subcomp;
57  delete _name;
58 }

Member Function Documentation

void Component::add ( const std::string &  name,
int  verbosity,
const std::string &  separator 
)

Add a new component to the tree

Parameters
namecomponent's name
verbositycomponent's verbosity
separatorpath separator

Definition at line 62 of file Component.cc.

65  {
66  //
67  // Prepare to parse name
68  //
69  boost::char_separator<char> sep(separator.c_str());
71  tokenizer::iterator token = components.begin();
72  const tokenizer::iterator end = components.end();
73 
74  if (token == end) { // "" or "."
75  this->setVerbosity(verbosity);
76  } else {
77  add(token, end, verbosity);
78  }
79 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
boost::tokenizer< boost::char_separator< char > > tokenizer
Definition: Component.h:78
void add(const std::string &name, int verbosity, const std::string &separator)
Definition: Component.cc:62
void setVerbosity(int verbosity)
Definition: Component.h:75
table::Key< table::Array< int > > components
void Component::add ( tokenizer::iterator  token,
const tokenizer::iterator  end,
int  verbosity 
)
private

Add a new component to the tree

Parameters
tokenparts of name
endend of name
verbositycomponent's verbosity

Definition at line 83 of file Component.cc.

86  {
87  const std::string cpt0 = *token++; // first component of name
88  /*
89  * Does first part of path match this verbosity?
90  */
91  if (*_name == cpt0) { // a match
92  if (token == end) { // name has no more components
93  _verbosity = verbosity;
94  } else {
95  add(token, end, verbosity);
96  }
97 
98  return;
99  }
100  /*
101  * Look for a match for cpt0 in this verbosity's subcomps
102  */
103  comp_map::iterator iter = _subcomp.find(cpt0);
104  if (iter != _subcomp.end()) {
105  if (token == end) {
106  iter->second->_verbosity = verbosity;
107  } else {
108  iter->second->add(token, end, verbosity);
109  }
110 
111  return;
112  }
113  /*
114  * No match; add cpt0 to this verbosity
115  */
116  Component *fcpt0 = new Component(cpt0);
117  _subcomp[*fcpt0->_name] = fcpt0;
118 
119  if (token == end) {
120  fcpt0->_verbosity = verbosity;
121  } else {
122  fcpt0->add(token, end, verbosity);
123  }
124 }
int iter
Create a component in the verbosity tree (deprecated).
Definition: Component.h:62
void add(const std::string &name, int verbosity, const std::string &separator)
Definition: Component.cc:62
Component(const std::string &name=".", int verbosity=INHERIT_VERBOSITY)
Definition: Component.cc:45
int Component::getVerbosity ( const std::string &  name,
const std::string &  separator 
)

Return a component's verbosity, from the perspective of "this".

See Also
Component::getVerbosity

< Return a component's verbosity

< Return a component's verbosity

Parameters
namecomponent of interest
separatorpath separator

Definition at line 179 of file Component.cc.

181  {
182  //
183  // Prepare to parse name
184  //
185  boost::char_separator<char> sep(separator.c_str());
186  tokenizer components(name, sep);
187  tokenizer::iterator token = components.begin();
188 
189  if (token == components.end()) {
190  return _verbosity;
191  }
192 
193  return getVerbosity(token, components.end(), _verbosity);
194 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
int getVerbosity(const std::string &name, const std::string &separator)
Definition: Component.cc:179
boost::tokenizer< boost::char_separator< char > > tokenizer
Definition: Component.h:78
table::Key< table::Array< int > > components
int Component::getVerbosity ( tokenizer::iterator  token,
const tokenizer::iterator  end,
int  defaultVerbosity 
)
private

Return a trace verbosity given a name

< Return trace verbosity given name

< Return trace verbosity given name

Parameters
tokenparts of name
endend of name
defaultVerbositydefault verbosity

Definition at line 146 of file Component.cc.

149  {
150  const std::string cpt0 = *token++; // first component of name
151  /*
152  * Look for a match for cpt0 in this Component's subcomps
153  */
154  comp_map::iterator iter = _subcomp.find(cpt0);
155  if (iter != _subcomp.end()) {
156  int verbosity = iter->second->_verbosity;
157  if (verbosity == INHERIT_VERBOSITY) {
158  verbosity = defaultVerbosity;
159  }
160 
161  if (token == end) { // there was only one component
162  ; // so save the function call
163  } else {
164  verbosity = iter->second->getVerbosity(token, end, verbosity);
165  }
166 
167  return (verbosity == INHERIT_VERBOSITY) ? defaultVerbosity : verbosity;
168  }
169  /*
170  * No match. This is as far as she goes
171  */
172  return _verbosity;
173 }
int iter
int Component::highestVerbosity ( int  highest = 0)

Return the highest verbosity rooted at comp

< return highest verbosity rooted at comp

Parameters
highestminimum verbosity to return

Definition at line 129 of file Component.cc.

130  {
131  if (_verbosity > highest) {
132  highest = _verbosity;
133  }
134 
135  for (comp_map::iterator iter = _subcomp.begin();
136  iter != _subcomp.end(); iter++) {
137  highest = iter->second->highestVerbosity(highest);
138  }
139 
140  return highest;
141 }
int iter
void Component::printVerbosity ( std::ostream &  fp,
int  depth = 0 
)

Print all the trace verbosities rooted at "this"

Parameters
fpOutput stream
depthTree depth to recurse

Definition at line 198 of file Component.cc.

200  {
201  if (_subcomp.empty() && _verbosity == INHERIT_VERBOSITY) {
202  return;
203  }
204  //
205  // Print this verbosity
206  //
207  for (int i = 0; i < depth; i++) {
208  fp << ' ';
209  }
210 
211  std::string &name = *_name;
212  if (name.length() == 0) name = "(root)";
213  fp << name;
214  for (int i = 0; i < 20 - depth - static_cast<int>(name.size()); i++) {
215  fp << ' ';
216  }
217 
218  if (_verbosity != INHERIT_VERBOSITY) {
219  fp << _verbosity;
220  }
221  fp << "\n";
222  //
223  // And other levels of the hierarchy too
224  //
225  for (comp_map::iterator iter = _subcomp.begin();
226  iter != _subcomp.end(); iter++) {
227  iter->second->printVerbosity(fp, depth + 1);
228  }
229 }
int iter
table::Key< std::string > name
Definition: ApCorrMap.cc:71
void lsst::pex::logging::Component::setVerbosity ( int  verbosity)
inline

Definition at line 75 of file Component.h.

75 { _verbosity = verbosity; }

Member Data Documentation

std::string* lsst::pex::logging::Component::_name
private

Definition at line 81 of file Component.h.

comp_map& lsst::pex::logging::Component::_subcomp
private

Definition at line 83 of file Component.h.

int lsst::pex::logging::Component::_verbosity
private

Definition at line 82 of file Component.h.


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