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 "Variant.h"
31 
32 #include <IceUtil/Time.h>
33 
34 
35 namespace armarx
36 {
37  class TimedVariant;
39 
40  class TimedVariant :
41  public armarx::Variant,
42  public TimedVariantBase
43  {
44  public:
45  TimedVariant();
47  TimedVariant(const Variant& variant, const IceUtil::Time& time);
48  TimedVariant(const VariantPtr& variant, const IceUtil::Time& time);
49 
50  template<class Var, class...Ts>
51  TimedVariant(const Var& variant, std::chrono::duration<Ts...> duration) :
52  TimedVariant(variant, IceUtil::Time::microSeconds(std::chrono::duration_cast<std::chrono::microseconds>(duration).count()))
53  {}
54  template<class Var, class...Ts>
55  TimedVariant(const Var& variant, std::chrono::time_point<Ts...> timepoint) :
56  TimedVariant(variant, timepoint.time_since_epoch())
57  {}
58 
59  /**
60  * Construct a TimedVariant from a non-VariantDataClass instance, e.g. from an int
61  *
62  * @tparam T The desired type of the TimedVariant
63  * @param var The initialization value as a T-instance
64  * @param t For type checking only: Do not use
65  */
66  template <class T>
67  TimedVariant(const T& var, const IceUtil::Time& time,
68  typename std::enable_if_t < !(std::is_base_of_v< VariantDataClass, T >
69  || std::is_pointer_v<T>) >::type* t = 0)
70  : Variant(var)
71  {
72  timestamp = time.toMicroSeconds();
73  }
74 
75  /**
76  * Construct a TimedVariant from a string.
77  *
78  * @param var The initialization value
79  */
80  TimedVariant(char const var[], const IceUtil::Time& time)
81  : Variant(var)
82  {
83  timestamp = time.toMicroSeconds();
84  }
85 
86  ~TimedVariant() override;
87 
88  IceUtil::Time getTime() const;
89  void setTime(const IceUtil::Time time)
90  {
91  timestamp = time.toMicroSeconds();
92  }
93  void setMicroseconds(Ice::Long microseconds)
94  {
95  timestamp = microseconds;
96  }
97  // TimedVariantBase interface
98  //! Timestamp in micro seconds
99  Ice::Long getTimestamp(const Ice::Current& c = Ice::emptyCurrent) const override;
100 
101  // Object interface
102  Ice::ObjectPtr ice_clone() const override;
103 
104  std::string getOutputValueOnly() const override;
105  friend std::ostream& operator<<(std::ostream& stream, const TimedVariantPtr& rhs)
106  {
107  if (rhs)
108  {
109  rhs->output(stream);
110  }
111  else
112  {
113  stream << "Null VariantPtr";
114  }
115 
116  return stream;
117  }
118 
119  };
120 }
121 extern template class ::IceInternal::Handle<::armarx::TimedVariant>;
122 
123 
armarx::TimedVariant::~TimedVariant
~TimedVariant() override
Definition: TimedVariant.cpp:68
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::TimedVariant::operator<<
friend std::ostream & operator<<(std::ostream &stream, const TimedVariantPtr &rhs)
Definition: TimedVariant.h:105
armarx::TimedVariant::getTimestamp
Ice::Long getTimestamp(const Ice::Current &c=Ice::emptyCurrent) const override
Timestamp in micro seconds.
Definition: TimedVariant.cpp:78
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
IceUtil
Definition: Instance.h:21
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::TimedVariant::setMicroseconds
void setMicroseconds(Ice::Long microseconds)
Definition: TimedVariant.h:93
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:88
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::TimedVariant::TimedVariant
TimedVariant(const Var &variant, std::chrono::duration< Ts... > duration)
Definition: TimedVariant.h:51
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
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:55
armarx::TimedVariant::getTime
IceUtil::Time getTime() const
Definition: TimedVariant.cpp:73
armarx::TimedVariant::TimedVariant
TimedVariant(char const var[], const IceUtil::Time &time)
Construct a TimedVariant from a string.
Definition: TimedVariant.h:80
std
Definition: Application.h:66
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:67
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:89
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::TimedVariant
Definition: TimedVariant.h:40