1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
42
#include <opencv2/core.hpp>
46
#include <opencv2/dnn/dnn.hpp>
48
#ifndef OPENCV_DNN_DNN_DICT_HPP
49
#define OPENCV_DNN_DNN_DICT_HPP
53
CV__DNN_INLINE_NS_BEGIN
57
/** @brief This struct stores the scalar value (or array) of one of the following type: double, cv::String or int64.
58
* @todo Maybe int64 is useless because double type exactly stores at least 2^52 integers.
60
struct CV_EXPORTS_W DictValue
62
DictValue(const DictValue &r);
63
DictValue(bool i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i ? 1 : 0; } //!< Constructs integer scalar
64
DictValue(int64 i = 0) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
65
CV_WRAP DictValue(int i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
66
DictValue(unsigned p) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = p; } //!< Constructs integer scalar
67
CV_WRAP DictValue(double p) : type(Param::REAL), pd(new AutoBuffer<double,1>) { (*pd)[0] = p; } //!< Constructs floating point scalar
68
CV_WRAP DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< Constructs string scalar
69
DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< @overload
71
template<typename TypeIter>
72
static DictValue arrayInt(TypeIter begin, int size); //!< Constructs integer array
73
template<typename TypeIter>
74
static DictValue arrayReal(TypeIter begin, int size); //!< Constructs floating point array
75
template<typename TypeIter>
76
static DictValue arrayString(TypeIter begin, int size); //!< Constructs array of strings
79
T get(int idx = -1) const; //!< Tries to convert array element with specified index to requested type and returns its.
83
CV_WRAP bool isInt() const;
84
CV_WRAP bool isString() const;
85
CV_WRAP bool isReal() const;
87
CV_WRAP int getIntValue(int idx = -1) const;
88
CV_WRAP double getRealValue(int idx = -1) const;
89
CV_WRAP String getStringValue(int idx = -1) const;
91
DictValue &operator=(const DictValue &r);
93
friend std::ostream &operator<<(std::ostream &stream, const DictValue &dictv);
103
AutoBuffer<int64, 1> *pi;
104
AutoBuffer<double, 1> *pd;
105
AutoBuffer<String, 1> *ps;
109
DictValue(Param _type, void *_p) : type(_type), pv(_p) {}
113
/** @brief This class implements name-value dictionary, values are instances of DictValue. */
114
class CV_EXPORTS Dict
116
typedef std::map<String, DictValue> _Dict;
121
//! Checks a presence of the @p key in the dictionary.
122
bool has(const String &key) const;
124
//! If the @p key in the dictionary then returns pointer to its value, else returns NULL.
125
DictValue *ptr(const String &key);
128
const DictValue *ptr(const String &key) const;
130
//! If the @p key in the dictionary then returns its value, else an error will be generated.
131
const DictValue &get(const String &key) const;
134
template <typename T>
135
T get(const String &key) const;
137
//! If the @p key in the dictionary then returns its value, else returns @p defaultValue.
138
template <typename T>
139
T get(const String &key, const T &defaultValue) const;
141
//! Sets new @p value for the @p key, or adds new key-value pair into the dictionary.
143
const T &set(const String &key, const T &value);
145
//! Erase @p key from the dictionary.
146
void erase(const String &key);
148
friend std::ostream &operator<<(std::ostream &stream, const Dict &dict);
150
std::map<String, DictValue>::const_iterator begin() const;
152
std::map<String, DictValue>::const_iterator end() const;
156
CV__DNN_INLINE_NS_END