Rearrage include and src
This commit is contained in:
1
include/deprecated/mynteye/api.h
Normal file
1
include/deprecated/mynteye/api.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/api/api.h"
|
||||
1
include/deprecated/mynteye/callbacks.h
Normal file
1
include/deprecated/mynteye/callbacks.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/device/callbacks.h"
|
||||
1
include/deprecated/mynteye/context.h
Normal file
1
include/deprecated/mynteye/context.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/device/context.h"
|
||||
1
include/deprecated/mynteye/device.h
Normal file
1
include/deprecated/mynteye/device.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/device/device.h"
|
||||
1
include/deprecated/mynteye/files.h
Normal file
1
include/deprecated/mynteye/files.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/util/files.h"
|
||||
1
include/deprecated/mynteye/glog_init.h
Normal file
1
include/deprecated/mynteye/glog_init.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/logger.h"
|
||||
1
include/deprecated/mynteye/object.h
Normal file
1
include/deprecated/mynteye/object.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/api/object.h"
|
||||
1
include/deprecated/mynteye/plugin.h
Normal file
1
include/deprecated/mynteye/plugin.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/api/plugin.h"
|
||||
1
include/deprecated/mynteye/strings.h
Normal file
1
include/deprecated/mynteye/strings.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/util/strings.h"
|
||||
1
include/deprecated/mynteye/times.h
Normal file
1
include/deprecated/mynteye/times.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/util/times.h"
|
||||
1
include/deprecated/mynteye/utils.h
Normal file
1
include/deprecated/mynteye/utils.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "mynteye/device/utils.h"
|
||||
285
include/mynteye/api/api.h
Normal file
285
include/mynteye/api/api.h
Normal file
@@ -0,0 +1,285 @@
|
||||
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_API_API_H_
|
||||
#define MYNTEYE_API_API_H_
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
#include "mynteye/types.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
class Device;
|
||||
class Synthetic;
|
||||
|
||||
namespace device {
|
||||
|
||||
class Frame;
|
||||
|
||||
} // namespace device
|
||||
|
||||
namespace api {
|
||||
|
||||
/**
|
||||
* @ingroup datatypes
|
||||
* API stream data.
|
||||
*/
|
||||
struct MYNTEYE_API StreamData {
|
||||
/** ImgData. */
|
||||
std::shared_ptr<ImgData> img;
|
||||
/** Frame. */
|
||||
cv::Mat frame;
|
||||
/** Raw frame. */
|
||||
std::shared_ptr<device::Frame> frame_raw;
|
||||
/** Frame ID. */
|
||||
std::uint16_t frame_id;
|
||||
|
||||
bool operator==(const StreamData &other) const {
|
||||
if (img && other.img) {
|
||||
return img->frame_id == other.img->frame_id &&
|
||||
img->timestamp == other.img->timestamp;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup datatypes
|
||||
* API motion data.
|
||||
*/
|
||||
struct MYNTEYE_API MotionData {
|
||||
/** ImuData. */
|
||||
std::shared_ptr<ImuData> imu;
|
||||
|
||||
bool operator==(const MotionData &other) const {
|
||||
if (imu && other.imu) {
|
||||
return imu->frame_id == other.imu->frame_id &&
|
||||
imu->timestamp == other.imu->timestamp;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
/**
|
||||
* The API class to communicate with MYNT® EYE device.
|
||||
*/
|
||||
class MYNTEYE_API API {
|
||||
public:
|
||||
/** The api::StreamData callback. */
|
||||
using stream_callback_t = std::function<void(const api::StreamData &data)>;
|
||||
/** The api::MotionData callback. */
|
||||
using motion_callback_t = std::function<void(const api::MotionData &data)>;
|
||||
|
||||
explicit API(std::shared_ptr<Device> device);
|
||||
virtual ~API();
|
||||
|
||||
/**
|
||||
* Create the API instance.
|
||||
* @return the API instance.
|
||||
* @note This will call device::select() to select a device.
|
||||
*/
|
||||
static std::shared_ptr<API> Create();
|
||||
/**
|
||||
* Create the API instance.
|
||||
* @param device the selected device.
|
||||
* @return the API instance.
|
||||
*/
|
||||
static std::shared_ptr<API> Create(std::shared_ptr<Device> device);
|
||||
/**
|
||||
* Create the API instance.
|
||||
* @param argc the arg count.
|
||||
* @param argv the arg values.
|
||||
* @return the API instance.
|
||||
* @note This will init glog with args and call device::select() to select a
|
||||
* device.
|
||||
*/
|
||||
static std::shared_ptr<API> Create(int argc, char *argv[]);
|
||||
/**
|
||||
* Create the API instance.
|
||||
* @param argc the arg count.
|
||||
* @param argv the arg values.
|
||||
* @param device the selected device.
|
||||
* @return the API instance.
|
||||
* @note This will init glog with args.
|
||||
*/
|
||||
static std::shared_ptr<API> Create(
|
||||
int argc, char *argv[], std::shared_ptr<Device> device);
|
||||
|
||||
/**
|
||||
* Get the model.
|
||||
*/
|
||||
Model GetModel() const;
|
||||
|
||||
/**
|
||||
* Supports the stream or not.
|
||||
*/
|
||||
bool Supports(const Stream &stream) const;
|
||||
/**
|
||||
* Supports the capability or not.
|
||||
*/
|
||||
bool Supports(const Capabilities &capability) const;
|
||||
/**
|
||||
* Supports the option or not.
|
||||
*/
|
||||
bool Supports(const Option &option) const;
|
||||
/**
|
||||
* Supports the addon or not.
|
||||
*/
|
||||
bool Supports(const AddOns &addon) const;
|
||||
|
||||
/**
|
||||
* Get all stream requests of the capability.
|
||||
*/
|
||||
const std::vector<StreamRequest> &GetStreamRequests(
|
||||
const Capabilities &capability) const;
|
||||
/**
|
||||
* Config the stream request to the capability.
|
||||
*/
|
||||
void ConfigStreamRequest(
|
||||
const Capabilities &capability, const StreamRequest &request);
|
||||
|
||||
/**
|
||||
* Get the device info.
|
||||
*/
|
||||
std::string GetInfo(const Info &info) const;
|
||||
|
||||
/**
|
||||
* Get the intrinsics of stream.
|
||||
*/
|
||||
Intrinsics GetIntrinsics(const Stream &stream) const;
|
||||
/**
|
||||
* Get the extrinsics from one stream to another.
|
||||
*/
|
||||
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
|
||||
/**
|
||||
* Get the intrinsics of motion.
|
||||
*/
|
||||
MotionIntrinsics GetMotionIntrinsics() const;
|
||||
/**
|
||||
* Get the extrinsics from one stream to motion.
|
||||
*/
|
||||
Extrinsics GetMotionExtrinsics(const Stream &from) const;
|
||||
|
||||
/**
|
||||
* Log all option infos.
|
||||
*/
|
||||
void LogOptionInfos() const;
|
||||
/**
|
||||
* Get the option info.
|
||||
*/
|
||||
OptionInfo GetOptionInfo(const Option &option) const;
|
||||
|
||||
/**
|
||||
* Get the option value.
|
||||
*/
|
||||
std::int32_t GetOptionValue(const Option &option) const;
|
||||
/**
|
||||
* Set the option value.
|
||||
*/
|
||||
void SetOptionValue(const Option &option, std::int32_t value);
|
||||
|
||||
/**
|
||||
* Run the option action.
|
||||
*/
|
||||
bool RunOptionAction(const Option &option) const;
|
||||
|
||||
/**
|
||||
* Set the callback of stream.
|
||||
*/
|
||||
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
|
||||
/**
|
||||
* Set the callback of motion.
|
||||
*/
|
||||
void SetMotionCallback(motion_callback_t callback);
|
||||
|
||||
/**
|
||||
* Has the callback of stream.
|
||||
*/
|
||||
bool HasStreamCallback(const Stream &stream) const;
|
||||
/**
|
||||
* Has the callback of motion.
|
||||
*/
|
||||
bool HasMotionCallback() const;
|
||||
|
||||
/**
|
||||
* Start capturing the source.
|
||||
*/
|
||||
void Start(const Source &source);
|
||||
/**
|
||||
* Stop capturing the source.
|
||||
*/
|
||||
void Stop(const Source &source);
|
||||
|
||||
/**
|
||||
* Wait the streams are ready.
|
||||
*/
|
||||
void WaitForStreams();
|
||||
|
||||
/**
|
||||
* Enable the data of stream.
|
||||
* @note must enable the stream if it's a synthetic one. This means the stream
|
||||
* in not native, the device has the capability to provide this stream, but
|
||||
* still support this stream.
|
||||
*/
|
||||
void EnableStreamData(const Stream &stream);
|
||||
/**
|
||||
* Disable the data of stream.
|
||||
*/
|
||||
void DisableStreamData(const Stream &stream);
|
||||
|
||||
/**
|
||||
* Get the latest data of stream.
|
||||
*/
|
||||
api::StreamData GetStreamData(const Stream &stream);
|
||||
/**
|
||||
* Get the datas of stream.
|
||||
* @note default cache 4 datas at most.
|
||||
*/
|
||||
std::vector<api::StreamData> GetStreamDatas(const Stream &stream);
|
||||
|
||||
/**
|
||||
* Enable cache motion datas.
|
||||
*/
|
||||
void EnableMotionDatas(
|
||||
std::size_t max_size = std::numeric_limits<std::size_t>::max());
|
||||
/**
|
||||
* Get the motion datas.
|
||||
*/
|
||||
std::vector<api::MotionData> GetMotionDatas();
|
||||
|
||||
/**
|
||||
* Enable the plugin.
|
||||
*/
|
||||
void EnablePlugin(const std::string &path);
|
||||
|
||||
std::shared_ptr<Device> device();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Device> device_;
|
||||
|
||||
std::unique_ptr<Synthetic> synthetic_;
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_API_API_H_
|
||||
115
include/mynteye/api/object.h
Normal file
115
include/mynteye/api/object.h
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_API_OBJECT_H_
|
||||
#define MYNTEYE_API_OBJECT_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
/**
|
||||
* Input & output object.
|
||||
*/
|
||||
struct MYNTEYE_API Object {
|
||||
Object() = default;
|
||||
virtual ~Object() = default;
|
||||
|
||||
virtual Object *Clone() const = 0;
|
||||
virtual bool DecValidity() const = 0;
|
||||
|
||||
/** Cast the obj to T pointer */
|
||||
template <typename T>
|
||||
static T *Cast(Object *obj) {
|
||||
return dynamic_cast<T *>(obj);
|
||||
}
|
||||
|
||||
/** Cast the obj to const T pointer */
|
||||
template <typename T>
|
||||
static const T *Cast(const Object *obj) {
|
||||
return dynamic_cast<const T *>(obj);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static std::shared_ptr<T> Cast(const std::shared_ptr<Object> &obj) {
|
||||
return std::dynamic_pointer_cast<T>(obj);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Input & output object of one cv::Mat.
|
||||
*/
|
||||
struct MYNTEYE_API ObjMat : public Object {
|
||||
ObjMat() = default;
|
||||
ObjMat(const cv::Mat &value, std::uint16_t id)
|
||||
: value(value), id(id) {}
|
||||
|
||||
/** The value */
|
||||
cv::Mat value;
|
||||
/** The id **/
|
||||
std::uint16_t id;
|
||||
|
||||
Object *Clone() const {
|
||||
ObjMat *mat = new ObjMat;
|
||||
mat->value = value.clone();
|
||||
mat->id = id;
|
||||
return mat;
|
||||
}
|
||||
|
||||
bool DecValidity() const {
|
||||
return !value.empty();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Input & output object of two cv::Mat.
|
||||
*/
|
||||
struct MYNTEYE_API ObjMat2 : public Object {
|
||||
ObjMat2() = default;
|
||||
ObjMat2(const cv::Mat &first, std::uint16_t first_id,
|
||||
const cv::Mat &second, std::uint16_t second_id)
|
||||
: first(first), first_id(first_id),
|
||||
second(second), second_id(second_id) {}
|
||||
|
||||
/** The first value */
|
||||
cv::Mat first;
|
||||
/** The first id **/
|
||||
std::uint16_t first_id;
|
||||
|
||||
/** The second value */
|
||||
cv::Mat second;
|
||||
/** The second id **/
|
||||
std::uint16_t second_id;
|
||||
|
||||
Object *Clone() const {
|
||||
ObjMat2 *mat2 = new ObjMat2;
|
||||
mat2->first = first.clone();
|
||||
mat2->first_id = first_id;
|
||||
mat2->second = second.clone();
|
||||
mat2->second_id = second_id;
|
||||
return mat2;
|
||||
}
|
||||
|
||||
bool DecValidity() const {
|
||||
return !first.empty() && !second.empty();
|
||||
}
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_API_OBJECT_H_
|
||||
141
include/mynteye/api/plugin.h
Normal file
141
include/mynteye/api/plugin.h
Normal file
@@ -0,0 +1,141 @@
|
||||
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_API_PLUGIN_H_
|
||||
#define MYNTEYE_API_PLUGIN_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
#ifndef MYNTEYE_PLUGIN_VERSION_CODE
|
||||
#define MYNTEYE_PLUGIN_VERSION_CODE 0
|
||||
#endif
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
class API;
|
||||
struct Object;
|
||||
|
||||
/**
|
||||
* The plugin which could implement processing by yourself.
|
||||
*/
|
||||
class MYNTEYE_API Plugin {
|
||||
public:
|
||||
Plugin() = default;
|
||||
virtual ~Plugin() = 0;
|
||||
|
||||
/**
|
||||
* Called when plugin created.
|
||||
* @param api the API instacne.
|
||||
*/
|
||||
virtual void OnCreate(API *api) {
|
||||
api_ = api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process rectify.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process rectify.
|
||||
*/
|
||||
virtual bool OnRectifyProcess(Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process disparity.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process disparity.
|
||||
*/
|
||||
virtual bool OnDisparityProcess(Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process normalized disparity.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process normalized disparity.
|
||||
*/
|
||||
virtual bool OnDisparityNormalizedProcess(
|
||||
Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process points.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process points.
|
||||
*/
|
||||
virtual bool OnPointsProcess(Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process depth.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process depth.
|
||||
*/
|
||||
virtual bool OnDepthProcess(Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
API *api_;
|
||||
};
|
||||
|
||||
inline Plugin::~Plugin() = default;
|
||||
|
||||
using plugin_version_code_t = std::uint32_t();
|
||||
using plugin_create_t = Plugin *();
|
||||
using plugin_destroy_t = void(Plugin *);
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
extern "C" {
|
||||
|
||||
/**
|
||||
* Get the plugin version code.
|
||||
*/
|
||||
MYNTEYE_API std::uint32_t plugin_version_code();
|
||||
|
||||
/**
|
||||
* Create the plugin.
|
||||
*/
|
||||
MYNTEYE_API mynteye::Plugin *plugin_create();
|
||||
|
||||
/**
|
||||
* Destroy the plugin.
|
||||
*/
|
||||
MYNTEYE_API void plugin_destroy(mynteye::Plugin *plugin);
|
||||
|
||||
}
|
||||
|
||||
#endif // MYNTEYE_API_PLUGIN_H_
|
||||
@@ -11,8 +11,8 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_CALLBACKS_H_ // NOLINT
|
||||
#define MYNTEYE_CALLBACKS_H_
|
||||
#ifndef MYNTEYE_DEVICE_CALLBACKS_H_
|
||||
#define MYNTEYE_DEVICE_CALLBACKS_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
@@ -133,4 +133,4 @@ using MotionCallback = std::function<void(const MotionData &data)>;
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_CALLBACKS_H_ NOLINT
|
||||
#endif // MYNTEYE_DEVICE_CALLBACKS_H_
|
||||
56
include/mynteye/device/context.h
Normal file
56
include/mynteye/device/context.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_DEVICE_CONTEXT_H_
|
||||
#define MYNTEYE_DEVICE_CONTEXT_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
namespace uvc {
|
||||
|
||||
struct context;
|
||||
|
||||
} // namespace uvc
|
||||
|
||||
class Device;
|
||||
|
||||
/**
|
||||
* The context about devices.
|
||||
*/
|
||||
class MYNTEYE_API Context {
|
||||
public:
|
||||
Context();
|
||||
~Context();
|
||||
|
||||
/**
|
||||
* Get all devices now.
|
||||
* @return a vector of all devices.
|
||||
*/
|
||||
std::vector<std::shared_ptr<Device>> devices() const {
|
||||
return devices_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<uvc::context> context_;
|
||||
std::vector<std::shared_ptr<Device>> devices_;
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_DEVICE_CONTEXT_H_
|
||||
325
include/mynteye/device/device.h
Normal file
325
include/mynteye/device/device.h
Normal file
@@ -0,0 +1,325 @@
|
||||
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_DEVICE_DEVICE_H_
|
||||
#define MYNTEYE_DEVICE_DEVICE_H_
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
#include "mynteye/types.h"
|
||||
#include "mynteye/device/callbacks.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
namespace uvc {
|
||||
|
||||
struct device;
|
||||
|
||||
} // namespace uvc
|
||||
|
||||
namespace tools {
|
||||
|
||||
class DeviceWriter;
|
||||
|
||||
} // namespace tools
|
||||
|
||||
struct DeviceInfo;
|
||||
|
||||
class API;
|
||||
class Channels;
|
||||
class Motions;
|
||||
class Streams;
|
||||
|
||||
template <class Data>
|
||||
class AsyncCallback;
|
||||
|
||||
/**
|
||||
* The Device class to communicate with MYNT® EYE device.
|
||||
*/
|
||||
class MYNTEYE_API Device {
|
||||
public:
|
||||
/** The device::StreamData callback. */
|
||||
using stream_callback_t = device::StreamCallback;
|
||||
/** The device::MotionData callback. */
|
||||
using motion_callback_t = device::MotionCallback;
|
||||
|
||||
using stream_callbacks_t = std::map<Stream, stream_callback_t>;
|
||||
|
||||
using stream_async_callback_t = AsyncCallback<device::StreamData>;
|
||||
using motion_async_callback_t = AsyncCallback<device::MotionData>;
|
||||
using stream_async_callback_ptr_t = std::shared_ptr<stream_async_callback_t>;
|
||||
using motion_async_callback_ptr_t = std::shared_ptr<motion_async_callback_t>;
|
||||
|
||||
Device(const Model &model, std::shared_ptr<uvc::device> device);
|
||||
virtual ~Device();
|
||||
|
||||
/**
|
||||
* Create the Device instance.
|
||||
* @param name the device name.
|
||||
* @param device the device from uvc.
|
||||
* @return the Device instance.
|
||||
*/
|
||||
static std::shared_ptr<Device> Create(
|
||||
const std::string &name, std::shared_ptr<uvc::device> device);
|
||||
|
||||
/**
|
||||
* Get the model.
|
||||
*/
|
||||
Model GetModel() const {
|
||||
return model_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports the stream or not.
|
||||
*/
|
||||
bool Supports(const Stream &stream) const;
|
||||
/**
|
||||
* Supports the capability or not.
|
||||
*/
|
||||
bool Supports(const Capabilities &capability) const;
|
||||
/**
|
||||
* Supports the option or not.
|
||||
*/
|
||||
bool Supports(const Option &option) const;
|
||||
/**
|
||||
* Supports the addon or not.
|
||||
*/
|
||||
bool Supports(const AddOns &addon) const;
|
||||
|
||||
/**
|
||||
* Get all stream requests of the capability.
|
||||
*/
|
||||
const std::vector<StreamRequest> &GetStreamRequests(
|
||||
const Capabilities &capability) const;
|
||||
/**
|
||||
* Config the stream request to the capability.
|
||||
*/
|
||||
void ConfigStreamRequest(
|
||||
const Capabilities &capability, const StreamRequest &request);
|
||||
|
||||
/**
|
||||
* Get the device info.
|
||||
*/
|
||||
std::shared_ptr<DeviceInfo> GetInfo() const;
|
||||
/**
|
||||
* Get the device info of a field.
|
||||
*/
|
||||
std::string GetInfo(const Info &info) const;
|
||||
|
||||
/**
|
||||
* Get the intrinsics of stream.
|
||||
*/
|
||||
Intrinsics GetIntrinsics(const Stream &stream) const;
|
||||
/**
|
||||
* Get the extrinsics from one stream to another.
|
||||
*/
|
||||
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
|
||||
/**
|
||||
* Get the intrinsics of motion.
|
||||
*/
|
||||
MotionIntrinsics GetMotionIntrinsics() const;
|
||||
/**
|
||||
* Get the extrinsics from one stream to motion.
|
||||
*/
|
||||
Extrinsics GetMotionExtrinsics(const Stream &from) const;
|
||||
|
||||
/**
|
||||
* Get the intrinsics of stream.
|
||||
*/
|
||||
Intrinsics GetIntrinsics(const Stream &stream, bool *ok) const;
|
||||
/**
|
||||
* Get the extrinsics from one stream to another.
|
||||
*/
|
||||
Extrinsics GetExtrinsics(
|
||||
const Stream &from, const Stream &to, bool *ok) const;
|
||||
/**
|
||||
* Get the intrinsics of motion.
|
||||
*/
|
||||
MotionIntrinsics GetMotionIntrinsics(bool *ok) const;
|
||||
/**
|
||||
* Get the extrinsics from one stream to motion.
|
||||
*/
|
||||
Extrinsics GetMotionExtrinsics(const Stream &from, bool *ok) const;
|
||||
|
||||
/**
|
||||
* Set the intrinsics of stream.
|
||||
*/
|
||||
void SetIntrinsics(const Stream &stream, const Intrinsics &in);
|
||||
/**
|
||||
* Set the extrinsics from one stream to another.
|
||||
*/
|
||||
void SetExtrinsics(
|
||||
const Stream &from, const Stream &to, const Extrinsics &ex);
|
||||
/**
|
||||
* Set the intrinsics of motion.
|
||||
*/
|
||||
void SetMotionIntrinsics(const MotionIntrinsics &in);
|
||||
/**
|
||||
* Set the extrinsics from one stream to motion.
|
||||
*/
|
||||
void SetMotionExtrinsics(const Stream &from, const Extrinsics &ex);
|
||||
|
||||
/**
|
||||
* Log all option infos.
|
||||
*/
|
||||
void LogOptionInfos() const;
|
||||
/**
|
||||
* Get the option info.
|
||||
*/
|
||||
OptionInfo GetOptionInfo(const Option &option) const;
|
||||
|
||||
/**
|
||||
* Get the option value.
|
||||
*/
|
||||
std::int32_t GetOptionValue(const Option &option) const;
|
||||
/**
|
||||
* Set the option value.
|
||||
*/
|
||||
void SetOptionValue(const Option &option, std::int32_t value);
|
||||
|
||||
/**
|
||||
* Run the option action.
|
||||
*/
|
||||
bool RunOptionAction(const Option &option) const;
|
||||
|
||||
/**
|
||||
* Set the callback of stream.
|
||||
*/
|
||||
void SetStreamCallback(
|
||||
const Stream &stream, stream_callback_t callback, bool async = false);
|
||||
/**
|
||||
* Set the callback of motion.
|
||||
*/
|
||||
void SetMotionCallback(motion_callback_t callback, bool async = false);
|
||||
|
||||
/**
|
||||
* Has the callback of stream.
|
||||
*/
|
||||
bool HasStreamCallback(const Stream &stream) const;
|
||||
/**
|
||||
* Has the callback of motion.
|
||||
*/
|
||||
bool HasMotionCallback() const;
|
||||
|
||||
/**
|
||||
* Start capturing the source.
|
||||
*/
|
||||
virtual void Start(const Source &source);
|
||||
/**
|
||||
* Stop capturing the source.
|
||||
*/
|
||||
virtual void Stop(const Source &source);
|
||||
|
||||
/**
|
||||
* Wait the streams are ready.
|
||||
*/
|
||||
void WaitForStreams();
|
||||
|
||||
/**
|
||||
* Get the datas of stream.
|
||||
* @note default cache 4 datas at most.
|
||||
*/
|
||||
std::vector<device::StreamData> GetStreamDatas(const Stream &stream);
|
||||
/**
|
||||
* Get the latest data of stream.
|
||||
*/
|
||||
device::StreamData GetLatestStreamData(const Stream &stream);
|
||||
|
||||
/**
|
||||
* Enable cache motion datas.
|
||||
*/
|
||||
void EnableMotionDatas(
|
||||
std::size_t max_size = std::numeric_limits<std::size_t>::max());
|
||||
/**
|
||||
* Get the motion datas.
|
||||
*/
|
||||
std::vector<device::MotionData> GetMotionDatas();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<uvc::device> device() const {
|
||||
return device_;
|
||||
}
|
||||
|
||||
std::shared_ptr<Streams> streams() const {
|
||||
return streams_;
|
||||
}
|
||||
|
||||
std::shared_ptr<Channels> channels() const {
|
||||
return channels_;
|
||||
}
|
||||
|
||||
std::shared_ptr<Motions> motions() const {
|
||||
return motions_;
|
||||
}
|
||||
|
||||
const StreamRequest &GetStreamRequest(const Capabilities &capability);
|
||||
|
||||
virtual void StartVideoStreaming();
|
||||
virtual void StopVideoStreaming();
|
||||
|
||||
virtual void StartMotionTracking();
|
||||
virtual void StopMotionTracking();
|
||||
|
||||
virtual void OnStereoStreamUpdate();
|
||||
|
||||
virtual std::vector<Stream> GetKeyStreams() const = 0;
|
||||
|
||||
bool video_streaming_;
|
||||
bool motion_tracking_;
|
||||
|
||||
private:
|
||||
Model model_;
|
||||
std::shared_ptr<uvc::device> device_;
|
||||
std::shared_ptr<DeviceInfo> device_info_;
|
||||
|
||||
std::map<Stream, Intrinsics> stream_intrinsics_;
|
||||
std::map<Stream, std::map<Stream, Extrinsics>> stream_from_extrinsics_;
|
||||
|
||||
std::shared_ptr<MotionIntrinsics> motion_intrinsics_;
|
||||
std::map<Stream, Extrinsics> motion_from_extrinsics_;
|
||||
|
||||
stream_callbacks_t stream_callbacks_;
|
||||
motion_callback_t motion_callback_;
|
||||
|
||||
std::map<Stream, stream_async_callback_ptr_t> stream_async_callbacks_;
|
||||
motion_async_callback_ptr_t motion_async_callback_;
|
||||
|
||||
std::shared_ptr<Streams> streams_;
|
||||
|
||||
std::map<Capabilities, StreamRequest> stream_config_requests_;
|
||||
|
||||
std::mutex mtx_streams_;
|
||||
|
||||
std::shared_ptr<Channels> channels_;
|
||||
|
||||
std::shared_ptr<Motions> motions_;
|
||||
|
||||
void ReadAllInfos();
|
||||
|
||||
void CallbackPushedStreamData(const Stream &stream);
|
||||
void CallbackMotionData(const device::MotionData &data);
|
||||
|
||||
friend API;
|
||||
friend tools::DeviceWriter;
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_DEVICE_DEVICE_H_
|
||||
@@ -11,8 +11,8 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_UTILS_H_ // NOLINT
|
||||
#define MYNTEYE_UTILS_H_
|
||||
#ifndef MYNTEYE_DEVICE_UTILS_H_
|
||||
#define MYNTEYE_DEVICE_UTILS_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
@@ -59,4 +59,4 @@ MYNTEYE_API float get_real_exposure_time(
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_UTILS_H_ NOLINT
|
||||
#endif // MYNTEYE_DEVICE_UTILS_H_
|
||||
@@ -45,7 +45,7 @@ MYNTEYE_API_VERSION_CHECK( \
|
||||
((major<<16)|(minor<<8)|(patch)) // NOLINT
|
||||
|
||||
/* MYNTEYE_API_VERSION in "X.Y.Z" format */
|
||||
#define MYNTEYE_API_VERSION_STR (STRINGIFY(MYNTEYE_API_VERSION_MAJOR.MYNTEYE_API_VERSION_MINOR.MYNTEYE_API_VERSION_PATCH)) // NOLINT
|
||||
#define MYNTEYE_API_VERSION_STR (MYNTEYE_STRINGIFY(MYNTEYE_API_VERSION_MAJOR.MYNTEYE_API_VERSION_MINOR.MYNTEYE_API_VERSION_PATCH)) // NOLINT
|
||||
|
||||
#cmakedefine MYNTEYE_NAMESPACE @MYNTEYE_NAMESPACE@
|
||||
#if defined(MYNTEYE_NAMESPACE)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_TYPES_H_ // NOLINT
|
||||
#ifndef MYNTEYE_TYPES_H_
|
||||
#define MYNTEYE_TYPES_H_
|
||||
#pragma once
|
||||
|
||||
@@ -483,4 +483,4 @@ std::ostream &operator<<(std::ostream &os, const OptionInfo &info);
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_TYPES_H_ NOLINT
|
||||
#endif // MYNTEYE_TYPES_H_
|
||||
|
||||
32
include/mynteye/util/files.h
Normal file
32
include/mynteye/util/files.h
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_UTIL_FILES_H_
|
||||
#define MYNTEYE_UTIL_FILES_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
namespace files {
|
||||
|
||||
MYNTEYE_API bool mkdir(const std::string &path);
|
||||
|
||||
} // namespace files
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_UTIL_FILES_H_
|
||||
62
include/mynteye/util/strings.h
Normal file
62
include/mynteye/util/strings.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_UTIL_STRINGS_H_
|
||||
#define MYNTEYE_UTIL_STRINGS_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
/** The strings error */
|
||||
class MYNTEYE_API strings_error : public std::runtime_error {
|
||||
public:
|
||||
explicit strings_error(const std::string &what_arg) noexcept
|
||||
: std::runtime_error(std::move(what_arg)) {}
|
||||
explicit strings_error(const char *what_arg) noexcept
|
||||
: std::runtime_error(std::move(what_arg)) {}
|
||||
};
|
||||
|
||||
namespace strings {
|
||||
|
||||
MYNTEYE_API
|
||||
int hex2int(const std::string &text);
|
||||
|
||||
MYNTEYE_API
|
||||
bool starts_with(const std::string &text, const std::string &prefix);
|
||||
|
||||
MYNTEYE_API
|
||||
bool ends_with(const std::string &text, const std::string &suffix);
|
||||
|
||||
MYNTEYE_API
|
||||
std::vector<std::string> split(
|
||||
const std::string &text, const std::string &delimiters);
|
||||
|
||||
MYNTEYE_API void ltrim(std::string &s); // NOLINT
|
||||
MYNTEYE_API void rtrim(std::string &s); // NOLINT
|
||||
MYNTEYE_API void trim(std::string &s); // NOLINT
|
||||
|
||||
MYNTEYE_API
|
||||
std::string trim_copy(const std::string &text);
|
||||
|
||||
} // namespace strings
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_UTIL_STRINGS_H_
|
||||
223
include/mynteye/util/times.h
Normal file
223
include/mynteye/util/times.h
Normal file
@@ -0,0 +1,223 @@
|
||||
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MYNTEYE_UTIL_TIMES_H_
|
||||
#define MYNTEYE_UTIL_TIMES_H_
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <ratio>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
namespace times {
|
||||
|
||||
using system_clock = std::chrono::system_clock;
|
||||
|
||||
using nanoseconds = std::chrono::nanoseconds;
|
||||
using microseconds = std::chrono::microseconds;
|
||||
using milliseconds = std::chrono::milliseconds;
|
||||
using seconds = std::chrono::seconds;
|
||||
using minutes = std::chrono::minutes;
|
||||
using hours = std::chrono::hours;
|
||||
using days = std::chrono::duration<std::int64_t, std::ratio<86400>>;
|
||||
|
||||
// to
|
||||
|
||||
template <typename Duration>
|
||||
inline Duration to_duration(const std::int64_t &t) {
|
||||
return Duration{t};
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline system_clock::time_point to_time_point(const Duration &d) {
|
||||
return system_clock::time_point(d);
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline system_clock::time_point to_time_point(const std::int64_t &t) {
|
||||
return system_clock::time_point(Duration{t});
|
||||
}
|
||||
|
||||
inline system_clock::time_point to_time_point(std::tm *tm) {
|
||||
return system_clock::from_time_t(std::mktime(tm));
|
||||
}
|
||||
|
||||
inline struct std::tm *to_local_tm(const system_clock::time_point &t) {
|
||||
auto t_c = system_clock::to_time_t(t);
|
||||
return std::localtime(&t_c);
|
||||
}
|
||||
|
||||
inline struct std::tm *to_utc_tm(const system_clock::time_point &t) {
|
||||
auto t_c = system_clock::to_time_t(t);
|
||||
return std::gmtime(&t_c);
|
||||
}
|
||||
|
||||
// cast
|
||||
|
||||
template <typename FromDuration, typename ToDuration>
|
||||
inline ToDuration cast(const FromDuration &d) {
|
||||
return std::chrono::duration_cast<ToDuration>(d);
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline Duration cast(const system_clock::duration &d) {
|
||||
return cast<system_clock::duration, Duration>(d);
|
||||
}
|
||||
|
||||
template <typename FromDuration, typename ToDuration>
|
||||
inline std::int64_t cast(const std::int64_t &t) {
|
||||
return cast<FromDuration, ToDuration>(FromDuration{t}).count();
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline system_clock::time_point cast(const system_clock::time_point &d) {
|
||||
// C++17, floor
|
||||
return std::chrono::time_point_cast<Duration>(d);
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline system_clock::duration cast_mod(const system_clock::time_point &t) {
|
||||
return t - cast<Duration>(t);
|
||||
}
|
||||
|
||||
// count
|
||||
|
||||
template <typename FromDuration, typename ToDuration>
|
||||
inline std::int64_t count(const FromDuration &d) {
|
||||
return cast<FromDuration, ToDuration>(d).count();
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline std::int64_t count(const system_clock::duration &d) {
|
||||
return cast<Duration>(d).count();
|
||||
}
|
||||
|
||||
// day
|
||||
|
||||
inline std::tm *day_beg(std::tm *tm) {
|
||||
tm->tm_hour = 0;
|
||||
tm->tm_min = 0;
|
||||
tm->tm_sec = 0;
|
||||
return tm;
|
||||
}
|
||||
|
||||
inline std::tm *day_end(std::tm *tm) {
|
||||
tm->tm_hour = 23;
|
||||
tm->tm_min = 59;
|
||||
tm->tm_sec = 59;
|
||||
return tm;
|
||||
}
|
||||
|
||||
inline system_clock::time_point day_beg(const system_clock::time_point &t) {
|
||||
return cast<days>(t);
|
||||
}
|
||||
|
||||
inline system_clock::time_point day_end(const system_clock::time_point &t) {
|
||||
return day_beg(t) + days(1) - system_clock::duration(1);
|
||||
}
|
||||
|
||||
inline system_clock::duration day_time(const system_clock::time_point &t) {
|
||||
return cast_mod<days>(t);
|
||||
}
|
||||
|
||||
// between
|
||||
|
||||
template <typename Duration>
|
||||
inline std::int64_t between(
|
||||
const system_clock::time_point &t1, const system_clock::time_point &t2) {
|
||||
return count<Duration>(t2 - t1);
|
||||
}
|
||||
|
||||
inline std::int64_t between_days(
|
||||
const system_clock::time_point &t1, const system_clock::time_point &t2) {
|
||||
return between<days>(day_beg(t1), day_beg(t2));
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline std::int64_t between_days(
|
||||
const std::int64_t &t1, const std::int64_t &t2) {
|
||||
return between_days(to_time_point<Duration>(t1), to_time_point<Duration>(t2));
|
||||
}
|
||||
|
||||
// epoch
|
||||
|
||||
inline system_clock::time_point epoch() {
|
||||
return system_clock::time_point(system_clock::duration{0});
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline std::int64_t since_epoch(const system_clock::time_point &t) {
|
||||
return count<Duration>(t.time_since_epoch());
|
||||
}
|
||||
|
||||
// now
|
||||
|
||||
inline system_clock::time_point now() {
|
||||
return system_clock::now();
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline std::int64_t now() {
|
||||
return since_epoch<Duration>(now());
|
||||
}
|
||||
|
||||
// string
|
||||
|
||||
inline std::string to_string(
|
||||
const system_clock::time_point &t, const std::tm *tm,
|
||||
const char *fmt = "%F %T", std::int32_t precision = 6) {
|
||||
std::stringstream ss;
|
||||
#if defined(MYNTEYE_OS_ANDROID) || defined(MYNTEYE_OS_LINUX)
|
||||
char foo[20];
|
||||
strftime(foo, sizeof(foo), fmt, tm);
|
||||
ss << foo;
|
||||
#else
|
||||
ss << std::put_time(tm, fmt);
|
||||
#endif
|
||||
if (precision > 0) {
|
||||
if (precision > 6)
|
||||
precision = 6;
|
||||
ss << '.' << std::setfill('0') << std::setw(precision)
|
||||
<< static_cast<std::int32_t>(
|
||||
count<microseconds>(cast_mod<seconds>(t)) /
|
||||
std::pow(10, 6 - precision));
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline std::string to_local_string(
|
||||
const system_clock::time_point &t, const char *fmt = "%F %T",
|
||||
const std::int32_t &precision = 6) {
|
||||
return to_string(t, to_local_tm(t), fmt, precision);
|
||||
}
|
||||
|
||||
inline std::string to_utc_string(
|
||||
const system_clock::time_point &t, const char *fmt = "%F %T",
|
||||
const std::int32_t &precision = 6) {
|
||||
return to_string(t, to_utc_tm(t), fmt, precision);
|
||||
}
|
||||
|
||||
} // namespace times
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_UTIL_TIMES_H_
|
||||
Reference in New Issue
Block a user