Merge pull request #12486 from cv3d:fix_cpp11

Support MSVC 2013 (#12486)

* Added CV_CONSTEXPR macro

* Utilize CV_NOEXCEPT and CV_CONSTEXPR

* Provides some Ptr<> logical operators
pull/12508/head
Hamdi Sahloul 6 years ago committed by Alexander Alekhin
parent cb3ae1232b
commit 10ae0c4364
  1. 8
      modules/core/include/opencv2/core/cvdef.h
  2. 38
      modules/core/include/opencv2/core/cvstd_wrapper.hpp
  3. 56
      modules/dnn/src/op_inf_engine.cpp
  4. 56
      modules/dnn/src/op_inf_engine.hpp

@ -456,6 +456,14 @@ Cv64suf;
# define CV_NOEXCEPT
#endif
#ifndef CV_CONSTEXPR
# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/)
# define CV_CONSTEXPR constexpr
# endif
#endif
#ifndef CV_CONSTEXPR
# define CV_CONSTEXPR const
#endif
// Integer types portatibility
#ifdef OPENCV_STDINT_HEADER

@ -43,14 +43,14 @@ struct has_parenthesis_operator
{
private:
template<typename T>
static constexpr std::true_type check(typename std::is_same<typename std::decay<decltype(std::declval<T>().operator()(std::declval<Args>()...))>::type, Ret>::type*);
static CV_CONSTEXPR std::true_type check(typename std::is_same<typename std::decay<decltype(std::declval<T>().operator()(std::declval<Args>()...))>::type, Ret>::type*);
template<typename> static constexpr std::false_type check(...);
template<typename> static CV_CONSTEXPR std::false_type check(...);
typedef decltype(check<C>(0)) type;
public:
static constexpr bool value = type::value;
static CV_CONSTEXPR bool value = type::value;
};
} // namespace sfinae
@ -62,21 +62,21 @@ struct Ptr : public std::shared_ptr<T>
#if 0
using std::shared_ptr<T>::shared_ptr; // GCC 5.x can't handle this
#else
inline Ptr() noexcept : std::shared_ptr<T>() {}
inline Ptr(nullptr_t) noexcept : std::shared_ptr<T>(nullptr) {}
inline Ptr() CV_NOEXCEPT : std::shared_ptr<T>() {}
inline Ptr(nullptr_t) CV_NOEXCEPT : std::shared_ptr<T>(nullptr) {}
template<typename Y, typename D> inline Ptr(Y* p, D d) : std::shared_ptr<T>(p, d) {}
template<typename D> inline Ptr(nullptr_t, D d) : std::shared_ptr<T>(nullptr, d) {}
template<typename Y> inline Ptr(const Ptr<Y>& r, T* ptr) noexcept : std::shared_ptr<T>(r, ptr) {}
template<typename Y> inline Ptr(const Ptr<Y>& r, T* ptr) CV_NOEXCEPT : std::shared_ptr<T>(r, ptr) {}
inline Ptr(const Ptr<T>& o) noexcept : std::shared_ptr<T>(o) {}
inline Ptr(Ptr<T>&& o) noexcept : std::shared_ptr<T>(std::move(o)) {}
inline Ptr(const Ptr<T>& o) CV_NOEXCEPT : std::shared_ptr<T>(o) {}
inline Ptr(Ptr<T>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {}
template<typename Y> inline Ptr(const Ptr<Y>& o) noexcept : std::shared_ptr<T>(o) {}
template<typename Y> inline Ptr(Ptr<Y>&& o) noexcept : std::shared_ptr<T>(std::move(o)) {}
template<typename Y> inline Ptr(const Ptr<Y>& o) CV_NOEXCEPT : std::shared_ptr<T>(o) {}
template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {}
#endif
inline Ptr(const std::shared_ptr<T>& o) noexcept : std::shared_ptr<T>(o) {}
inline Ptr(std::shared_ptr<T>&& o) noexcept : std::shared_ptr<T>(std::move(o)) {}
inline Ptr(const std::shared_ptr<T>& o) CV_NOEXCEPT : std::shared_ptr<T>(o) {}
inline Ptr(std::shared_ptr<T>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {}
#ifndef _MSC_VER
// Overload with custom DefaultDeleter: Ptr<IplImage>(...)
@ -105,27 +105,27 @@ struct Ptr : public std::shared_ptr<T>
template<class Y, class Deleter>
void reset(Y* ptr, Deleter d) { std::shared_ptr<T>::reset(ptr, d); }
void reset() noexcept { std::shared_ptr<T>::reset(); }
void reset() CV_NOEXCEPT { std::shared_ptr<T>::reset(); }
Ptr& operator=(const Ptr& o) { std::shared_ptr<T>::operator =(o); return *this; }
template<typename Y> inline Ptr& operator=(const Ptr<Y>& o) { std::shared_ptr<T>::operator =(o); return *this; }
T* operator->() const noexcept { return std::shared_ptr<T>::get();}
typename std::add_lvalue_reference<T>::type operator*() const noexcept { return *std::shared_ptr<T>::get(); }
T* operator->() const CV_NOEXCEPT { return std::shared_ptr<T>::get();}
typename std::add_lvalue_reference<T>::type operator*() const CV_NOEXCEPT { return *std::shared_ptr<T>::get(); }
// OpenCV 3.x methods (not a part of standart C++ library)
inline void release() { std::shared_ptr<T>::reset(); }
inline operator T* () const { return std::shared_ptr<T>::get(); }
inline bool empty() const { return std::shared_ptr<T>::get() == NULL; }
inline bool empty() const { return std::shared_ptr<T>::get() == nullptr; }
template<typename Y> inline
Ptr<Y> staticCast() const noexcept { return std::static_pointer_cast<Y>(*this); }
Ptr<Y> staticCast() const CV_NOEXCEPT { return std::static_pointer_cast<Y>(*this); }
template<typename Y> inline
Ptr<Y> constCast() const noexcept { return std::const_pointer_cast<Y>(*this); }
Ptr<Y> constCast() const CV_NOEXCEPT { return std::const_pointer_cast<Y>(*this); }
template<typename Y> inline
Ptr<Y> dynamicCast() const noexcept { return std::dynamic_pointer_cast<Y>(*this); }
Ptr<Y> dynamicCast() const CV_NOEXCEPT { return std::dynamic_pointer_cast<Y>(*this); }
};
template<typename _Tp, typename ... A1> static inline

@ -164,92 +164,92 @@ InfEngineBackendNet::InfEngineBackendNet(InferenceEngine::CNNNetwork& net)
netOwner = net;
}
void InfEngineBackendNet::Release() noexcept
void InfEngineBackendNet::Release() CV_NOEXCEPT
{
layers.clear();
inputs.clear();
outputs.clear();
}
void InfEngineBackendNet::setPrecision(InferenceEngine::Precision p) noexcept
void InfEngineBackendNet::setPrecision(InferenceEngine::Precision p) CV_NOEXCEPT
{
precision = p;
}
InferenceEngine::Precision InfEngineBackendNet::getPrecision() noexcept
InferenceEngine::Precision InfEngineBackendNet::getPrecision() CV_NOEXCEPT
{
return precision;
}
InferenceEngine::Precision InfEngineBackendNet::getPrecision() const noexcept
InferenceEngine::Precision InfEngineBackendNet::getPrecision() const CV_NOEXCEPT
{
return precision;
}
// Assume that outputs of network is unconnected blobs.
void InfEngineBackendNet::getOutputsInfo(InferenceEngine::OutputsDataMap &outputs_) noexcept
void InfEngineBackendNet::getOutputsInfo(InferenceEngine::OutputsDataMap &outputs_) CV_NOEXCEPT
{
const_cast<const InfEngineBackendNet*>(this)->getOutputsInfo(outputs_);
}
void InfEngineBackendNet::getOutputsInfo(InferenceEngine::OutputsDataMap &outputs_) const noexcept
void InfEngineBackendNet::getOutputsInfo(InferenceEngine::OutputsDataMap &outputs_) const CV_NOEXCEPT
{
outputs_ = outputs;
}
// Returns input references that aren't connected to internal outputs.
void InfEngineBackendNet::getInputsInfo(InferenceEngine::InputsDataMap &inputs_) noexcept
void InfEngineBackendNet::getInputsInfo(InferenceEngine::InputsDataMap &inputs_) CV_NOEXCEPT
{
const_cast<const InfEngineBackendNet*>(this)->getInputsInfo(inputs_);
}
// Returns input references that aren't connected to internal outputs.
void InfEngineBackendNet::getInputsInfo(InferenceEngine::InputsDataMap &inputs_) const noexcept
void InfEngineBackendNet::getInputsInfo(InferenceEngine::InputsDataMap &inputs_) const CV_NOEXCEPT
{
inputs_ = inputs;
}
InferenceEngine::InputInfo::Ptr InfEngineBackendNet::getInput(const std::string &inputName) noexcept
InferenceEngine::InputInfo::Ptr InfEngineBackendNet::getInput(const std::string &inputName) CV_NOEXCEPT
{
return const_cast<const InfEngineBackendNet*>(this)->getInput(inputName);
}
InferenceEngine::InputInfo::Ptr InfEngineBackendNet::getInput(const std::string &inputName) const noexcept
InferenceEngine::InputInfo::Ptr InfEngineBackendNet::getInput(const std::string &inputName) const CV_NOEXCEPT
{
const auto& it = inputs.find(inputName);
CV_Assert(it != inputs.end());
return it->second;
}
void InfEngineBackendNet::getName(char*, size_t) noexcept
void InfEngineBackendNet::getName(char*, size_t) CV_NOEXCEPT
{
}
void InfEngineBackendNet::getName(char*, size_t) const noexcept
void InfEngineBackendNet::getName(char*, size_t) const CV_NOEXCEPT
{
}
const std::string& InfEngineBackendNet::getName() const noexcept
const std::string& InfEngineBackendNet::getName() const CV_NOEXCEPT
{
return name;
}
size_t InfEngineBackendNet::layerCount() noexcept
size_t InfEngineBackendNet::layerCount() CV_NOEXCEPT
{
return const_cast<const InfEngineBackendNet*>(this)->layerCount();
}
size_t InfEngineBackendNet::layerCount() const noexcept
size_t InfEngineBackendNet::layerCount() const CV_NOEXCEPT
{
return layers.size();
}
InferenceEngine::DataPtr& InfEngineBackendNet::getData(const char *dname) noexcept
InferenceEngine::DataPtr& InfEngineBackendNet::getData(const char *dname) CV_NOEXCEPT
{
CV_Error(Error::StsNotImplemented, "");
return outputs.begin()->second; // Just return something.
}
void InfEngineBackendNet::addLayer(const InferenceEngine::CNNLayerPtr &layer) noexcept
void InfEngineBackendNet::addLayer(const InferenceEngine::CNNLayerPtr &layer) CV_NOEXCEPT
{
layers.push_back(layer);
inputs.clear();
@ -258,7 +258,7 @@ void InfEngineBackendNet::addLayer(const InferenceEngine::CNNLayerPtr &layer) no
InferenceEngine::StatusCode
InfEngineBackendNet::addOutput(const std::string &layerName, size_t outputIndex,
InferenceEngine::ResponseDesc *resp) noexcept
InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT
{
for (const auto& l : layers)
{
@ -277,14 +277,14 @@ InfEngineBackendNet::addOutput(const std::string &layerName, size_t outputIndex,
InferenceEngine::StatusCode
InfEngineBackendNet::getLayerByName(const char *layerName, InferenceEngine::CNNLayerPtr &out,
InferenceEngine::ResponseDesc *resp) noexcept
InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT
{
return const_cast<const InfEngineBackendNet*>(this)->getLayerByName(layerName, out, resp);
}
InferenceEngine::StatusCode InfEngineBackendNet::getLayerByName(const char *layerName,
InferenceEngine::CNNLayerPtr &out,
InferenceEngine::ResponseDesc *resp) const noexcept
InferenceEngine::ResponseDesc *resp) const CV_NOEXCEPT
{
for (auto& l : layers)
{
@ -298,7 +298,7 @@ InferenceEngine::StatusCode InfEngineBackendNet::getLayerByName(const char *laye
return InferenceEngine::StatusCode::NOT_FOUND;
}
void InfEngineBackendNet::setTargetDevice(InferenceEngine::TargetDevice device) noexcept
void InfEngineBackendNet::setTargetDevice(InferenceEngine::TargetDevice device) CV_NOEXCEPT
{
if (device != InferenceEngine::TargetDevice::eCPU &&
device != InferenceEngine::TargetDevice::eGPU &&
@ -307,42 +307,42 @@ void InfEngineBackendNet::setTargetDevice(InferenceEngine::TargetDevice device)
targetDevice = device;
}
InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() noexcept
InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() CV_NOEXCEPT
{
return targetDevice;
}
InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() const noexcept
InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() const CV_NOEXCEPT
{
return targetDevice;
}
InferenceEngine::StatusCode InfEngineBackendNet::setBatchSize(const size_t) noexcept
InferenceEngine::StatusCode InfEngineBackendNet::setBatchSize(const size_t) CV_NOEXCEPT
{
CV_Error(Error::StsNotImplemented, "");
return InferenceEngine::StatusCode::OK;
}
InferenceEngine::StatusCode InfEngineBackendNet::setBatchSize(size_t size, InferenceEngine::ResponseDesc *responseDesc) noexcept
InferenceEngine::StatusCode InfEngineBackendNet::setBatchSize(size_t size, InferenceEngine::ResponseDesc *responseDesc) CV_NOEXCEPT
{
CV_Error(Error::StsNotImplemented, "");
return InferenceEngine::StatusCode::OK;
}
size_t InfEngineBackendNet::getBatchSize() const noexcept
size_t InfEngineBackendNet::getBatchSize() const CV_NOEXCEPT
{
CV_Error(Error::StsNotImplemented, "");
return 0;
}
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R2)
InferenceEngine::StatusCode InfEngineBackendNet::AddExtension(const InferenceEngine::IShapeInferExtensionPtr &extension, InferenceEngine::ResponseDesc *resp) noexcept
InferenceEngine::StatusCode InfEngineBackendNet::AddExtension(const InferenceEngine::IShapeInferExtensionPtr &extension, InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT
{
CV_Error(Error::StsNotImplemented, "");
return InferenceEngine::StatusCode::OK;
}
InferenceEngine::StatusCode InfEngineBackendNet::reshape(const InferenceEngine::ICNNNetwork::InputShapes &inputShapes, InferenceEngine::ResponseDesc *resp) noexcept
InferenceEngine::StatusCode InfEngineBackendNet::reshape(const InferenceEngine::ICNNNetwork::InputShapes &inputShapes, InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT
{
CV_Error(Error::StsNotImplemented, "");
return InferenceEngine::StatusCode::OK;

@ -47,67 +47,67 @@ public:
InfEngineBackendNet(InferenceEngine::CNNNetwork& net);
virtual void Release() noexcept CV_OVERRIDE;
virtual void Release() CV_NOEXCEPT CV_OVERRIDE;
void setPrecision(InferenceEngine::Precision p) noexcept;
void setPrecision(InferenceEngine::Precision p) CV_NOEXCEPT;
virtual InferenceEngine::Precision getPrecision() noexcept;
virtual InferenceEngine::Precision getPrecision() CV_NOEXCEPT;
virtual InferenceEngine::Precision getPrecision() const noexcept;
virtual InferenceEngine::Precision getPrecision() const CV_NOEXCEPT;
virtual void getOutputsInfo(InferenceEngine::OutputsDataMap &out) noexcept /*CV_OVERRIDE*/;
virtual void getOutputsInfo(InferenceEngine::OutputsDataMap &out) CV_NOEXCEPT /*CV_OVERRIDE*/;
virtual void getOutputsInfo(InferenceEngine::OutputsDataMap &out) const noexcept /*CV_OVERRIDE*/;
virtual void getOutputsInfo(InferenceEngine::OutputsDataMap &out) const CV_NOEXCEPT /*CV_OVERRIDE*/;
virtual void getInputsInfo(InferenceEngine::InputsDataMap &inputs) noexcept /*CV_OVERRIDE*/;
virtual void getInputsInfo(InferenceEngine::InputsDataMap &inputs) CV_NOEXCEPT /*CV_OVERRIDE*/;
virtual void getInputsInfo(InferenceEngine::InputsDataMap &inputs) const noexcept /*CV_OVERRIDE*/;
virtual void getInputsInfo(InferenceEngine::InputsDataMap &inputs) const CV_NOEXCEPT /*CV_OVERRIDE*/;
virtual InferenceEngine::InputInfo::Ptr getInput(const std::string &inputName) noexcept;
virtual InferenceEngine::InputInfo::Ptr getInput(const std::string &inputName) CV_NOEXCEPT;
virtual InferenceEngine::InputInfo::Ptr getInput(const std::string &inputName) const noexcept;
virtual InferenceEngine::InputInfo::Ptr getInput(const std::string &inputName) const CV_NOEXCEPT;
virtual void getName(char *pName, size_t len) noexcept;
virtual void getName(char *pName, size_t len) CV_NOEXCEPT;
virtual void getName(char *pName, size_t len) const noexcept;
virtual void getName(char *pName, size_t len) const CV_NOEXCEPT;
virtual const std::string& getName() const noexcept;
virtual const std::string& getName() const CV_NOEXCEPT;
virtual size_t layerCount() noexcept;
virtual size_t layerCount() CV_NOEXCEPT;
virtual size_t layerCount() const noexcept;
virtual size_t layerCount() const CV_NOEXCEPT;
virtual InferenceEngine::DataPtr& getData(const char *dname) noexcept CV_OVERRIDE;
virtual InferenceEngine::DataPtr& getData(const char *dname) CV_NOEXCEPT CV_OVERRIDE;
virtual void addLayer(const InferenceEngine::CNNLayerPtr &layer) noexcept CV_OVERRIDE;
virtual void addLayer(const InferenceEngine::CNNLayerPtr &layer) CV_NOEXCEPT CV_OVERRIDE;
virtual InferenceEngine::StatusCode addOutput(const std::string &layerName,
size_t outputIndex = 0,
InferenceEngine::ResponseDesc *resp = nullptr) noexcept;
InferenceEngine::ResponseDesc *resp = nullptr) CV_NOEXCEPT;
virtual InferenceEngine::StatusCode getLayerByName(const char *layerName,
InferenceEngine::CNNLayerPtr &out,
InferenceEngine::ResponseDesc *resp) noexcept;
InferenceEngine::ResponseDesc *resp) CV_NOEXCEPT;
virtual InferenceEngine::StatusCode getLayerByName(const char *layerName,
InferenceEngine::CNNLayerPtr &out,
InferenceEngine::ResponseDesc *resp) const noexcept;
InferenceEngine::ResponseDesc *resp) const CV_NOEXCEPT;
virtual void setTargetDevice(InferenceEngine::TargetDevice device) noexcept CV_OVERRIDE;
virtual void setTargetDevice(InferenceEngine::TargetDevice device) CV_NOEXCEPT CV_OVERRIDE;
virtual InferenceEngine::TargetDevice getTargetDevice() noexcept;
virtual InferenceEngine::TargetDevice getTargetDevice() CV_NOEXCEPT;
virtual InferenceEngine::TargetDevice getTargetDevice() const noexcept;
virtual InferenceEngine::TargetDevice getTargetDevice() const CV_NOEXCEPT;
virtual InferenceEngine::StatusCode setBatchSize(const size_t size) noexcept CV_OVERRIDE;
virtual InferenceEngine::StatusCode setBatchSize(const size_t size) CV_NOEXCEPT CV_OVERRIDE;
virtual InferenceEngine::StatusCode setBatchSize(size_t size, InferenceEngine::ResponseDesc* responseDesc) noexcept;
virtual InferenceEngine::StatusCode setBatchSize(size_t size, InferenceEngine::ResponseDesc* responseDesc) CV_NOEXCEPT;
virtual size_t getBatchSize() const noexcept CV_OVERRIDE;
virtual size_t getBatchSize() const CV_NOEXCEPT CV_OVERRIDE;
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R2)
virtual InferenceEngine::StatusCode AddExtension(const InferenceEngine::IShapeInferExtensionPtr& extension, InferenceEngine::ResponseDesc* resp) noexcept;
virtual InferenceEngine::StatusCode reshape(const InputShapes& inputShapes, InferenceEngine::ResponseDesc* resp) noexcept;
virtual InferenceEngine::StatusCode AddExtension(const InferenceEngine::IShapeInferExtensionPtr& extension, InferenceEngine::ResponseDesc* resp) CV_NOEXCEPT;
virtual InferenceEngine::StatusCode reshape(const InputShapes& inputShapes, InferenceEngine::ResponseDesc* resp) CV_NOEXCEPT;
#endif
void init(int targetId);

Loading…
Cancel
Save