OSVR-Core
JSONTimestamp.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_JSONTimestamp_h_GUID_F8E6C4C6_5A2F_4DA3_E633_68824AD1ABAF
26 #define INCLUDED_JSONTimestamp_h_GUID_F8E6C4C6_5A2F_4DA3_E633_68824AD1ABAF
27 
28 // Internal Includes
29 #include <osvr/Util/TimeValue.h>
30 
31 // Library/third-party includes
32 #include <json/value.h>
33 
34 // Standard includes
35 // - none
36 
37 namespace osvr {
38 namespace common {
39  static const char SECONDS_KEY[] = "seconds";
40  static const char USECONDS_KEY[] = "microseconds";
41  inline Json::Value toJson(OSVR_TimeValue const &ts) {
42  Json::Value val = Json::objectValue;
43  val[SECONDS_KEY] = Json::Value(Json::Int64(ts.seconds));
44  val[USECONDS_KEY] = ts.microseconds;
45  return val;
46  }
47  inline OSVR_TimeValue timevalueFromJson(Json::Value const &val) {
48  OSVR_TimeValue ts;
49  ts.seconds = val[SECONDS_KEY].asInt64();
50  ts.microseconds = val[USECONDS_KEY].asInt();
51  return ts;
52  }
53 
54 } // namespace common
55 } // namespace osvr
56 
57 #endif // INCLUDED_JSONTimestamp_h_GUID_F8E6C4C6_5A2F_4DA3_E633_68824AD1ABAF
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Header providing a C++ wrapper around TimeValueC.h.
OSVR_TimeValue_Microseconds microseconds
Microseconds portion of the time value.
Definition: TimeValueC.h:85
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
Json::Value toJson(Eigen::QuaternionBase< Derived > const &quat)
Converts quaternions to JSON objects.
Definition: JSONEigen.h:47
OSVR_TimeValue_Seconds seconds
Seconds portion of the time value.
Definition: TimeValueC.h:83