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/exceptions.h>
53 #include <tf/time_cache.h>
54 #include <tf/types.h>
55 
56 namespace fawkes {
57 namespace tf {
58 
59 /** @class StaticCache <tf/time_cache.h>
60  * Transform cache for static transforms.
61  */
62 
63 /** Constructor.
64  */
65 StaticCache::StaticCache() : storage_as_list_(1)
66 {
67 }
68 
69 /** Destructor . */
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
88 StaticCache::get_data(fawkes::Time time, TransformStorage &data_out, std::string *error_str)
89 {
90  data_out = storage_;
91  data_out.stamp = time;
92  return true;
93 }
94 
95 bool
97 {
98  storage_ = new_data;
99  storage_as_list_.front() = new_data;
100  return true;
101 }
102 
103 void
105 {
106  return;
107 }
108 
109 unsigned int
111 {
112  return 1;
113 }
114 
115 CompactFrameID
116 StaticCache::get_parent(fawkes::Time time, std::string *error_str)
117 {
118  return storage_.frame_id;
119 }
120 
121 P_TimeAndFrameID
123 {
124  return std::make_pair(fawkes::Time(0, 0), storage_.frame_id);
125 }
126 
129 {
130  return fawkes::Time(0, 0);
131 }
132 
135 {
136  return fawkes::Time(0, 0);
137 }
138 
141 {
142  return storage_as_list_;
143 }
144 
147 {
148  return storage_as_list_;
149 }
150 
151 } // end namespace tf
152 } // 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:92
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:74
virtual ~StaticCache()
Destructor .
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:141
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.