SoDaRadio-5.0.3-master:8901fb5
SoDaBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014, Matthew H. Reilly (kb1vc)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #include "SoDaBase.hxx"
30 #include <string>
31 #include <map>
32 #include <boost/format.hpp>
33 
34 namespace SoDa {
35  std::map<std::string, SoDaBase *> SoDaBase::ObjectDirectory;
36 
37  SoDaBase::SoDaBase(const std::string & oname)
38  {
39  objname = oname;
40  if(ObjectDirectory.find(oname) == ObjectDirectory.end()) {
41  ObjectDirectory[oname] = this;
42  }
43  }
44 
45  SoDaBase * SoDaBase::findSoDaObject(const std::string & oname) {
46  std::map<std::string, SoDaBase *>::iterator mi;
47  mi = ObjectDirectory.find(oname);
48  if(mi != ObjectDirectory.end()) {
49  return mi->second;
50  }
51  else {
52  return NULL;
53  }
54  }
55 
56  double SoDaBase::getTime() {
57  struct timespec tp;
58  clock_gettime(CLOCK_MONOTONIC, &tp); // 60nS average in tight loops, 160nS cold.
59  double ret = ((double) tp.tv_sec) + (1.0e-9 * ((double) tp.tv_nsec));
60  if(first_time) {
61  base_first_time = ret;
62  first_time = false;
63  }
64  return ret - base_first_time;
65  }
66 }
67 
68 bool SoDa::SoDaBase::first_time = true;
The Baseclass for all SoDa objects, and useful commonly used classes.
static bool first_time
have we seen the first call to getTime?
Definition: SoDaBase.hxx:203
static std::map< std::string, SoDaBase *> ObjectDirectory
a class member – directory of all registered objects.
Definition: SoDaBase.hxx:206
static double base_first_time
time of first call to getTime from anyone.
Definition: SoDaBase.hxx:204
SoDaBase * findSoDaObject(const std::string &oname)
find a SoDa Object by name.
Definition: SoDaBase.cxx:45
std::string objname
the name of the object
Definition: SoDaBase.hxx:201
double getTime()
Get a time stamp in nS resolution that monotonically increases and that is very inexpensive (typicall...
Definition: SoDaBase.cxx:56
SoDaBase(const std::string &oname)
The constructor – pass a name for the object.
Definition: SoDaBase.cxx:37
The SoDa Base class.
Definition: SoDaBase.hxx:167