Fawkes API  Fawkes Development Version
static_cache.cpp
1 /***************************************************************************
2  * time_cache.cpp - Fawkes tf time cache (based on ROS tf)
3  *
4  * Created: Thu Oct 20 11:26:40 2011
5  * Copyright 2011 Tim Niemueller [www.niemueller.de]
6  ****************************************************************************/
7 
8 /* This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version. A runtime exception applies to
12  * this software (see LICENSE.GPL_WRE file mentioned below for details).
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
20  */
21 
22 /* This code is based on ROS tf with the following copyright and license:
23  *
24  * Copyright (c) 2008, Willow Garage, Inc.
25  * All rights reserved.
26  *
27  * Redistribution and use in source and binary forms, with or without
28  * modification, are permitted provided that the following conditions are met:
29  *
30  * * Redistributions of source code must retain the above copyright
31  * notice, this list of conditions and the following disclaimer.
32  * * Redistributions in binary form must reproduce the above copyright
33  * notice, this list of conditions and the following disclaimer in the
34  * documentation and/or other materials provided with the distribution.
35  * * Neither the name of the Willow Garage, Inc. nor the names of its
36  * contributors may be used to endorse or promote products derived from
37  * this software without specific prior written permission.
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  */
51 
52 #include <tf/time_cache.h>
53 #include <tf/exceptions.h>
54 #include <tf/types.h>
55 
56 namespace fawkes {
57  namespace tf {
58 #if 0 /* just to make Emacs auto-indent happy */
59  }
60 }
61 #endif
62 
63 /** @class StaticCache <tf/time_cache.h>
64  * Transform cache for static transforms.
65  */
66 
67 /** Constructor.
68  */
70  : storage_as_list_(1)
71 {
72 }
73 
74 /** Create a copy of this time cache.
75  * @param look_back_until Ignored for static caches
76  * @return shared pointer to copy of this time cache
77  */
78 TimeCacheInterfacePtr
79 StaticCache::clone(const fawkes::Time &look_back_until) const
80 {
81  StaticCache *copy = new StaticCache();
82  copy->storage_ = storage_;
83  copy->storage_as_list_ = storage_as_list_;
84  return std::shared_ptr<TimeCacheInterface>(copy);
85 }
86 
87 bool
89  std::string* error_str)
90 {
91  data_out = storage_;
92  data_out.stamp = time;
93  return true;
94 }
95 
96 bool
98 {
99  storage_ = new_data;
100  storage_as_list_.front() = new_data;
101  return true;
102 }
103 
104 void
106 {
107  return;
108 }
109 
110 unsigned int
112 {
113  return 1;
114 }
115 
116 CompactFrameID
117 StaticCache::get_parent(fawkes::Time time, std::string *error_str)
118 {
119  return storage_.frame_id;
120 }
121 
122 P_TimeAndFrameID
124 {
125  return std::make_pair(fawkes::Time(0,0), storage_.frame_id);
126 }
127 
130 {
131  return fawkes::Time(0,0);
132 }
133 
136 {
137  return fawkes::Time(0,0);
138 }
139 
142 {
143  return storage_as_list_;
144 }
145 
148 {
149  return storage_as_list_;
150 }
151 
152 
153 } // end namespace tf
154 } // end namespace fawkes
virtual unsigned int get_list_length() const
Debugging information methods.
virtual L_TransformStorage get_storage_copy() const
Get copy of storage elements.
Fawkes library namespace.
Storage for transforms and their parent.
A class for handling time.
Definition: time.h:91
virtual CompactFrameID get_parent(fawkes::Time time, std::string *error_str)
Get parent frame number.
std::list< TransformStorage > L_TransformStorage
List of stored transforms.
Definition: time_cache.h:78
virtual bool get_data(fawkes::Time time, TransformStorage &data_out, std::string *error_str=0)
Get data.
CompactFrameID frame_id
parent/reference frame number
virtual TimeCacheInterfacePtr clone(const fawkes::Time &look_back_until=fawkes::Time(0, 0)) const
Create a copy of this time cache.
Transform cache for static transforms.
Definition: time_cache.h:142
virtual void clear_list()
Clear storage.
virtual const L_TransformStorage & get_storage() const
Get storage list.
virtual bool insert_data(const TransformStorage &new_data)
Insert data.
fawkes::Time stamp
time stamp
StaticCache()
Constructor.
virtual fawkes::Time get_latest_timestamp() const
Get latest timestamp from cache.
virtual fawkes::Time get_oldest_timestamp() const
Get oldest timestamp from cache.
virtual P_TimeAndFrameID get_latest_time_and_parent()
Get latest time and parent frame number.