TimestampVariant.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 General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <chrono>
27 
31 #include <ArmarXCore/interface/observers/Timestamp.h>
32 
33 #include <IceUtil/Time.h>
34 
35 namespace armarx::VariantType
36 {
37  // Variant types
38  const VariantTypeId Timestamp = Variant::addTypeName("::armarx::TimestampBase");
39 }
40 
41 namespace armarx
42 {
43  class TimestampVariant;
45 
46  /**
47  * @class TimestampVariant
48  * @ingroup VariantsGrp
49  * Implements a Variant type for timestamps. The timestamp value is interpreted as microseconds since the Unix Epoch.
50  * Internally the class bases on the IceUtil::Time functionality of Ice.
51  *
52  * For information on how to use this type, refer to Variant.
53  */
54  class ARMARXCORE_IMPORT_EXPORT TimestampVariant : virtual public TimestampBase
55  {
56  public:
58 
59  /**
60  * Construct a timestamp Variant from an initialization value.
61  *
62  * @param timestamp Initialization timestamp in microseconds since the Unix Epoch
63  */
64  TimestampVariant(long timestamp);
66  template<class...Ts>
67  TimestampVariant(std::chrono::duration<Ts...> duration) :
68  TimestampVariant(std::chrono::duration_cast<std::chrono::microseconds>(duration).count())
69  {}
70  template<class...Ts>
71  TimestampVariant(std::chrono::time_point<Ts...> timepoint) :
72  TimestampVariant(timepoint.time_since_epoch())
73  {}
74 
75  /**
76  * @brief return timestamp in microseconds since the Unix Epoch.
77  */
78  long getTimestamp();
79 
80 
81  // inherited from VariantDataClass
82  Ice::ObjectPtr ice_clone() const override
83  {
84  return this->clone();
85  }
86  VariantDataClassPtr clone(const Ice::Current& c = Ice::emptyCurrent) const override
87  {
88  return new TimestampVariant(*this);
89  }
90  std::string output(const Ice::Current& c = Ice::emptyCurrent) const override
91  {
92  std::stringstream s;
93  s << IceUtil::Time::microSeconds(timestamp).toDateTime();
94  return s.str();
95  }
96  VariantTypeId getType(const Ice::Current& c = Ice::emptyCurrent) const override
97  {
99  }
100  bool validate(const Ice::Current& c = Ice::emptyCurrent) override
101  {
102  return true;
103  }
104 
105  friend std::ostream& operator<<(std::ostream& stream, const TimestampVariant& rhs)
106  {
107  stream << "TimestampVariant: " << std::endl << rhs.output() << std::endl;
108  return stream;
109  }
110 
112  {
113  return new TimestampVariant(TimeUtil::GetTime());
114  }
115 
117  {
118  return IceUtil::Time::microSeconds(timestamp);
119  }
120 
121  public:
122  // serialization
123  void serialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = Ice::emptyCurrent) const override;
124  void deserialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = Ice::emptyCurrent) override;
125  };
126 }
127 
armarx::TimestampVariant
Definition: TimestampVariant.h:54
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::TimestampVariant::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: TimestampVariant.h:90
armarx::TimestampVariant::nowPtr
static TimestampVariantPtr nowPtr()
Definition: TimestampVariant.h:111
IceInternal::Handle< TimestampVariant >
armarx::TimestampVariant::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: TimestampVariant.h:82
armarx::TimestampVariant::getType
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: TimestampVariant.h:96
armarx::VariantType
Definition: ChannelRef.h:160
armarx::TimestampVariant::toTime
IceUtil::Time toTime()
Definition: TimestampVariant.h:116
armarx::TimestampVariant::operator<<
friend std::ostream & operator<<(std::ostream &stream, const TimestampVariant &rhs)
Definition: TimestampVariant.h:105
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::VariantType::Timestamp
const VariantTypeId Timestamp
Definition: TimestampVariant.h:38
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
TimeUtil.h
std
Definition: Application.h:66
armarx::TimestampVariant::validate
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Definition: TimestampVariant.h:100
armarx::TimestampVariant::TimestampVariant
TimestampVariant(std::chrono::time_point< Ts... > timepoint)
Definition: TimestampVariant.h:71
ImportExport.h
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::TimestampVariant::TimestampVariant
TimestampVariant(std::chrono::duration< Ts... > duration)
Definition: TimestampVariant.h:67
armarx::TimestampVariant::clone
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: TimestampVariant.h:86
Variant.h
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::Variant::addTypeName
static VariantTypeId addTypeName(const std::string &typeName)
Register a new type for the use in a Variant.
Definition: Variant.cpp:751