LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
lsst::pex::logging::threshold::Family Class Reference

A hierarchical tree structure for holding mappings of names to threshold values. More...

#include <Memory.h>

Public Member Functions

 Family (int defaultThreshold=INHERIT)
 
 ~Family ()
 
int getThreshold ()
 
void setThreshold (int threshold)
 
int getThresholdFor (tokenizer::iterator toptoken, const tokenizer::iterator &end) const
 
void setThresholdFor (tokenizer::iterator toptoken, const tokenizer::iterator &end, int threshold)
 
void resetThresholdFor (tokenizer::iterator toptoken, const tokenizer::iterator &end)
 
void printDescThresholds (std::ostream &out, const std::string &prefix) const
 
void deleteDescendants ()
 

Protected Member Functions

FamilyensureDescendant (tokenizer::iterator toptoken, const tokenizer::iterator &end)
 
const FamilyfindDescendant (tokenizer::iterator toptoken, const tokenizer::iterator &end, bool orNearest=false) const
 
FamilymakeDescendants (tokenizer::iterator toptoken, const tokenizer::iterator &end)
 

Private Types

typedef std::map< std::string,
Family * > 
ChildMap
 

Private Attributes

int _thresh
 
ChildMap_children
 

Detailed Description

A hierarchical tree structure for holding mappings of names to threshold values.

This contain contains a default threshold value and 0 or more child Family instances, each with a name. One can get or set the default threshold value for the Family as a whole or for any arbitrary descendant. If any threshold is set to the special value INHERIT, the effective value should be taken to be the threshold of its nearest ancestor.

Definition at line 59 of file Memory.h.

Member Typedef Documentation

typedef std::map<std::string, Family*> lsst::pex::logging::threshold::Family::ChildMap
private

Definition at line 159 of file Memory.h.

Constructor & Destructor Documentation

lsst::pex::logging::threshold::Family::Family ( int  defaultThreshold = INHERIT)

create a hierarchical container for threshold data

Parameters
defaultThresholdthe threshold value to associate with the name

Definition at line 44 of file Memory.cc.

45  : _thresh(defaultThreshold), _children()
46 { }
lsst::pex::logging::threshold::Family::~Family ( )

delete this container

Definition at line 142 of file Memory.cc.

142  {
144 }

Member Function Documentation

void lsst::pex::logging::threshold::Family::deleteDescendants ( )

delete the descendents

Definition at line 127 of file Memory.cc.

127  {
128 
129  if (_children == 0) return;
130 
131  for(ChildMap::iterator it = _children->begin();
132  it != _children->end();
133  ++it)
134  {
135  if (it->second != 0) delete it->second;
136  }
137 
138  delete _children;
139  _children = 0;
140 }
Family * lsst::pex::logging::threshold::Family::ensureDescendant ( tokenizer::iterator  toptoken,
const tokenizer::iterator &  end 
)
protected

return the child data for a given descendant name. Null is returned if the name does not exist.

Parameters
toptokenthe first field in the hierarchical name
endthe end iterator value from the tokenizer that produced toptoken

Definition at line 48 of file Memory.cc.

50 {
51  if (_children == 0)
52  // we have no children yet, so just make the descendents
53  return makeDescendants(toptoken, end);
54 
55  // look for a child matching the top field in the name
56  ChildMap::iterator out = _children->find(*toptoken);
57 
58  // if name is not found create all descendants
59  if (out == _children->end())
60  return makeDescendants(toptoken, end);
61 
62  // if this was the last token return the found child
63  if (++toptoken == end)
64  return out->second;
65 
66  // look for the the remainder of the name hierarchy
67  return out->second->ensureDescendant(toptoken, end);
68 }
Family * makeDescendants(tokenizer::iterator toptoken, const tokenizer::iterator &end)
Definition: Memory.cc:92
Family * ensureDescendant(tokenizer::iterator toptoken, const tokenizer::iterator &end)
Definition: Memory.cc:48
const Family * lsst::pex::logging::threshold::Family::findDescendant ( tokenizer::iterator  toptoken,
const tokenizer::iterator &  end,
bool  orNearest = false 
) const
protected

return a threshold Family for a given descendant name. What is returned when the name doesn't exist depends on the value of the orNearest parameter.

Parameters
toptokenthe first field in the hierarchical name
endthe end iterator value from the tokenizer that produced toptoken
orNearestif true and the exact named descendant does not exist, return the nearest ancestor that does exist. If false, return null if it doesn't exist.

Definition at line 70 of file Memory.cc.

73 {
74  if (_children == 0)
75  return ((orNearest && _thresh != INHERIT) ? this : 0);
76 
77  // look for a child matching the top field in the name
78  ChildMap::const_iterator found = _children->find(*toptoken);
79 
80  // if name is not found, return null
81  if (found == _children->end())
82  return ((orNearest && _thresh != INHERIT) ? this : 0);
83 
84  const Family *out = found->second;
85  if (++toptoken != end) out = out->findDescendant(toptoken, end, orNearest);
86  if (out != 0 && out->_thresh == INHERIT) out = 0;
87 
88  if (out == 0 && orNearest && _thresh != INHERIT) out = this;
89  return out;
90 }
Family(int defaultThreshold=INHERIT)
Definition: Memory.cc:44
int lsst::pex::logging::threshold::Family::getThreshold ( )
inline

return the default threshold for the top of this hierarchy

Definition at line 76 of file Memory.h.

int lsst::pex::logging::threshold::Family::getThresholdFor ( tokenizer::iterator  toptoken,
const tokenizer::iterator &  end 
) const
inline

return the threshold associated with a descendent with a given name

Definition at line 86 of file Memory.h.

88  {
89  const Family *nfd = findDescendant(toptoken, end, true);
90  if (nfd == 0 || nfd->_thresh == INHERIT) return _thresh;
91  return nfd->_thresh;
92  }
Family(int defaultThreshold=INHERIT)
Definition: Memory.cc:44
const Family * findDescendant(tokenizer::iterator toptoken, const tokenizer::iterator &end, bool orNearest=false) const
Definition: Memory.cc:70
Family * lsst::pex::logging::threshold::Family::makeDescendants ( tokenizer::iterator  toptoken,
const tokenizer::iterator &  end 
)
protected

create a threshold Family for a given descendant name.

Parameters
toptokenthe first field in the hierarchical name
endthe end iterator value from the tokenizer that produced toptoken

Definition at line 92 of file Memory.cc.

94 {
95  if (_children == 0) _children = new ChildMap();
96 
97  Family *next = new Family();
98  _children->insert(ChildMap::value_type(*toptoken, next));
99 
100  if (++toptoken == end) return next;
101 
102  return next->makeDescendants(toptoken, end);
103 }
std::map< std::string, Family * > ChildMap
Definition: Memory.h:159
Family(int defaultThreshold=INHERIT)
Definition: Memory.cc:44
void lsst::pex::logging::threshold::Family::printDescThresholds ( std::ostream &  out,
const std::string &  prefix 
) const

print the thresholds store in this Family that are not set to INHERIT.

This is intended for debugging purposes.

Definition at line 146 of file Memory.cc.

148 {
149  if (_children == 0) return;
150 
151  int i;
152  ChildMap::const_iterator it;
153  for(it = _children->begin(); it != _children->end(); ++it) {
154  out << prefix << it->first;
155  if (it->second != 0 && it->second->_thresh != INHERIT) {
156  for(i = prefix.length()+it->first.length(); i < 20; ++i)
157  out << ' ';
158  if (it->second->_thresh >= 0 && it->second->_thresh < 10)
159  out << ' ';
160  out << it->second->_thresh;
161  }
162  out << endl;
163 
164  if (it->second != 0)
165  it->second->printDescThresholds(out, prefix+' ');
166  }
167 }
void lsst::pex::logging::threshold::Family::resetThresholdFor ( tokenizer::iterator  toptoken,
const tokenizer::iterator &  end 
)

reset the threshold associated with a descendent with a given name to inherit from its parent.

Definition at line 120 of file Memory.cc.

122 {
123  Family *nfd = const_cast<Family*>(findDescendant(toptoken, end));
124  if (nfd != 0) nfd->_thresh = INHERIT;
125 }
Family(int defaultThreshold=INHERIT)
Definition: Memory.cc:44
const Family * findDescendant(tokenizer::iterator toptoken, const tokenizer::iterator &end, bool orNearest=false) const
Definition: Memory.cc:70
void lsst::pex::logging::threshold::Family::setThreshold ( int  threshold)
inline

return the default threshold for the top of this hierarchy

Definition at line 81 of file Memory.h.

81 { _thresh = threshold; }
void lsst::pex::logging::threshold::Family::setThresholdFor ( tokenizer::iterator  toptoken,
const tokenizer::iterator &  end,
int  threshold 
)

set the threshold associated with a descendent with a given name

Definition at line 108 of file Memory.cc.

111 {
112  Family *nfd = ensureDescendant(toptoken, end);
113  nfd->_thresh = threshold;
114 }
Family(int defaultThreshold=INHERIT)
Definition: Memory.cc:44
Family * ensureDescendant(tokenizer::iterator toptoken, const tokenizer::iterator &end)
Definition: Memory.cc:48

Member Data Documentation

ChildMap* lsst::pex::logging::threshold::Family::_children
private

Definition at line 161 of file Memory.h.

int lsst::pex::logging::threshold::Family::_thresh
private

Definition at line 160 of file Memory.h.


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