TimedVariant.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * ArmarX is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @package ArmarX::
20 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
21 * @date 2015
22 * @copyright http://www.gnu.org/licenses/gpl.txt
23 * GNU General Public License
24 */
25 
26 #pragma once
27 
28 #include <chrono>
29 
30 #include <IceUtil/Time.h>
31 
32 #include "Variant.h"
33 
34 namespace armarx
35 {
36  class TimedVariant;
38 
39  class TimedVariant : public armarx::Variant, public TimedVariantBase
40  {
41  public:
42  TimedVariant();
44  TimedVariant(const Variant& variant, const IceUtil::Time& time);
45  TimedVariant(const VariantPtr& variant, const IceUtil::Time& time);
46 
47  template <class Var, class... Ts>
48  TimedVariant(const Var& variant, std::chrono::duration<Ts...> duration) :
50  variant,
51  IceUtil::Time::microSeconds(
52  std::chrono::duration_cast<std::chrono::microseconds>(duration).count()))
53  {
54  }
55 
56  template <class Var, class... Ts>
57  TimedVariant(const Var& variant, std::chrono::time_point<Ts...> timepoint) :
58  TimedVariant(variant, timepoint.time_since_epoch())
59  {
60  }
61 
62  /**
63  * Construct a TimedVariant from a non-VariantDataClass instance, e.g. from an int
64  *
65  * @tparam T The desired type of the TimedVariant
66  * @param var The initialization value as a T-instance
67  * @param t For type checking only: Do not use
68  */
69  template <class T>
70  TimedVariant(const T& var,
71  const IceUtil::Time& time,
72  typename std::enable_if_t<!(std::is_base_of_v<VariantDataClass, T> ||
73  std::is_pointer_v<T>)>::type* t = 0) :
74  Variant(var)
75  {
76  timestamp = time.toMicroSeconds();
77  }
78 
79  /**
80  * Construct a TimedVariant from a string.
81  *
82  * @param var The initialization value
83  */
84  TimedVariant(char const var[], const IceUtil::Time& time) : Variant(var)
85  {
86  timestamp = time.toMicroSeconds();
87  }
88 
89  ~TimedVariant() override;
90 
91  IceUtil::Time getTime() const;
92 
93  void
94  setTime(const IceUtil::Time time)
95  {
96  timestamp = time.toMicroSeconds();
97  }
98 
99  void
101  {
102  timestamp = microseconds;
103  }
104 
105  // TimedVariantBase interface
106  //! Timestamp in micro seconds
107  Ice::Long getTimestamp(const Ice::Current& c = Ice::emptyCurrent) const override;
108 
109  // Object interface
110  Ice::ObjectPtr ice_clone() const override;
111 
112  std::string getOutputValueOnly() const override;
113 
114  friend std::ostream&
115  operator<<(std::ostream& stream, const TimedVariantPtr& rhs)
116  {
117  if (rhs)
118  {
119  rhs->output(stream);
120  }
121  else
122  {
123  stream << "Null VariantPtr";
124  }
125 
126  return stream;
127  }
128  };
129 } // namespace armarx
130 extern template class ::IceInternal::Handle<::armarx::TimedVariant>;
armarx::TimedVariant::~TimedVariant
~TimedVariant() override
Definition: TimedVariant.cpp:66
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::TimedVariant::operator<<
friend std::ostream & operator<<(std::ostream &stream, const TimedVariantPtr &rhs)
Definition: TimedVariant.h:115
armarx::TimedVariant::getTimestamp
Ice::Long getTimestamp(const Ice::Current &c=Ice::emptyCurrent) const override
Timestamp in micro seconds.
Definition: TimedVariant.cpp:77
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
IceUtil
Definition: Instance.h:21
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::TimedVariant::setMicroseconds
void setMicroseconds(Ice::Long microseconds)
Definition: TimedVariant.h:100
armarx::TimedVariant::TimedVariant
TimedVariant()
Definition: TimedVariant.cpp:32
armarx::TimedVariant::getOutputValueOnly
std::string getOutputValueOnly() const override
Returns the formatted content of the Variant as a string.
Definition: TimedVariant.cpp:89
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::TimedVariant::TimedVariant
TimedVariant(const T &var, const IceUtil::Time &time, typename std::enable_if_t<!(std::is_base_of_v< VariantDataClass, T >||std::is_pointer_v< T >)>::type *t=0)
Construct a TimedVariant from a non-VariantDataClass instance, e.g.
Definition: TimedVariant.h:70
armarx::TimedVariant::TimedVariant
TimedVariant(const Var &variant, std::chrono::duration< Ts... > duration)
Definition: TimedVariant.h:48
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::TimedVariant::TimedVariant
TimedVariant(const Var &variant, std::chrono::time_point< Ts... > timepoint)
Definition: TimedVariant.h:57
armarx::TimedVariant::getTime
IceUtil::Time getTime() const
Definition: TimedVariant.cpp:71
armarx::TimedVariant::TimedVariant
TimedVariant(char const var[], const IceUtil::Time &time)
Construct a TimedVariant from a string.
Definition: TimedVariant.h:84
std
Definition: Application.h:66
armarx::TimedVariant::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: TimedVariant.cpp:83
armarx::TimedVariant::setTime
void setTime(const IceUtil::Time time)
Definition: TimedVariant.h:94
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::TimedVariant
Definition: TimedVariant.h:39