20 #ifndef ESSENTIA_POOL_H
21 #define ESSENTIA_POOL_H
33 #define PoolOf(type) std::map<std::string, std::vector<type > >
154 void add(
const std::string& name,
const Real&
value,
bool validityCheck =
false);
157 void add(
const std::string& name,
const std::vector<Real>&
value,
bool validityCheck =
false);
160 void add(
const std::string& name,
const std::string&
value,
bool validityCheck =
false);
163 void add(
const std::string& name,
const std::vector<std::string>&
value,
bool validityCheck =
false);
179 template <
typename T>
180 void append(
const std::string& name,
const std::vector<T>& values);
202 void set(
const std::string& name,
const Real&
value,
bool validityCheck=
false);
205 void set(
const std::string& name,
const std::vector<Real>&
value,
bool validityCheck=
false);
208 void set(
const std::string& name,
const std::string&
value,
bool validityCheck=
false);
211 void set(
const std::string& name,
const std::vector<std::string>&
value,
bool validityCheck=
false);
243 void merge(
const std::string& name,
const std::vector<Real>&
value,
const std::string& type=
"");
246 void merge(
const std::string& name,
const std::vector<std::vector<Real> >&
value,
const std::string& type=
"");
249 void merge(
const std::string& name,
const std::vector<std::string>&
value,
const std::string& type=
"");
252 void merge(
const std::string& name,
const std::vector<std::vector<std::string> >&
value,
const std::string& type=
"");
261 void merge(
const std::string& name,
const std::vector<StereoSample>&
value,
const std::string& type=
"");
266 void mergeSingle(
const std::string& name,
const std::vector<Real>&
value,
const std::string& type=
"");
268 void mergeSingle(
const std::string& name,
const std::string&
value,
const std::string& type=
"");
270 void mergeSingle(
const std::string& name,
const std::vector<std::string>&
value,
const std::string& type=
"");
294 template <
typename T>
295 const T&
value(
const std::string& name)
const;
302 template <
typename T>
411 #define SPECIALIZE_VALUE(type, tname) \
413 inline const type& Pool::value(const std::string& name) const { \
414 MutexLocker lock(mutex##tname); \
415 std::map<std::string,type >::const_iterator result = _pool##tname.find(name);\
416 if (result == _pool##tname.end()) { \
417 std::ostringstream msg; \
418 msg << "Descriptor name '" << name << "' of type " \
419 << nameOfType(typeid(type)) << " not found"; \
420 throw EssentiaException(msg); \
422 return result->second; \
425 SPECIALIZE_VALUE(
Real, SingleReal);
426 SPECIALIZE_VALUE(std::string, SingleString);
428 SPECIALIZE_VALUE(std::vector<std::vector<Real> >, VectorReal);
429 SPECIALIZE_VALUE(std::vector<std::vector<std::string> >, VectorString);
431 SPECIALIZE_VALUE(std::vector<
Tensor<Real> >, TensorReal);
433 SPECIALIZE_VALUE(std::vector<StereoSample>,
StereoSample);
438 inline const std::vector<Real>&
Pool::value(
const std::string& name)
const {
439 std::map<std::string, std::vector<Real> >::const_iterator result;
444 return result->second;
452 return result->second;
456 std::ostringstream msg;
457 msg <<
"Descriptor name '" << name <<
"' of type "
458 <<
nameOfType(
typeid(std::vector<Real>)) <<
" not found";
459 throw EssentiaException(msg);
465 inline const std::vector<std::string>&
Pool::value(
const std::string& name)
const {
466 std::map<std::string, std::vector<std::string> >::const_iterator result;
471 return result->second;
479 return result->second;
483 std::ostringstream msg;
484 msg <<
"Descriptor name '" << name <<
"' of type "
485 <<
nameOfType(
typeid(std::vector<std::string>)) <<
" not found";
486 throw EssentiaException(msg);
490 #define SPECIALIZE_CONTAINS(type, tname) \
492 inline bool Pool::contains<type>(const std::string& name) const { \
493 MutexLocker lock(mutex##tname); \
494 std::map<std::string,type >::const_iterator result = _pool##tname.find(name);\
495 if (result == _pool##tname.end()) { \
501 SPECIALIZE_CONTAINS(
Real, SingleReal);
502 SPECIALIZE_CONTAINS(std::string, SingleString);
504 SPECIALIZE_CONTAINS(std::vector<std::vector<Real> >, VectorReal);
505 SPECIALIZE_CONTAINS(std::vector<std::vector<std::string> >, VectorString);
507 SPECIALIZE_CONTAINS(std::vector<Tensor<Real> >, TensorReal);
508 SPECIALIZE_CONTAINS(Tensor<Real> , SingleTensorReal);
509 SPECIALIZE_CONTAINS(std::vector<StereoSample>,
StereoSample);
514 inline bool Pool::contains<std::vector<Real> >(
const std::string& name)
const {
515 std::map<std::string, std::vector<Real> >::const_iterator result;
517 MutexLocker lock(mutexReal);
518 result = _poolReal.find(name);
519 if (result != _poolReal.end()) {
525 MutexLocker lock(mutexSingleVectorReal);
526 result = _poolSingleVectorReal.find(name);
527 if (result != _poolSingleVectorReal.end()) {
539 inline bool Pool::contains<std::vector<std::string> >(
const std::string& name)
const {
540 std::map<std::string, std::vector<std::string> >::const_iterator result;
542 MutexLocker lock(mutexString);
543 result = _poolString.find(name);
544 if (result != _poolString.end()) {
550 MutexLocker lock(mutexSingleVectorString);
551 result = _poolSingleVectorString.find(name);
552 if (result != _poolSingleVectorString.end()) {
562 #define GLOBAL_LOCK \
563 MutexLocker lockReal(mutexReal); \
564 MutexLocker lockVectorReal(mutexVectorReal); \
565 MutexLocker lockString(mutexString); \
566 MutexLocker lockVectorString(mutexVectorString); \
567 MutexLocker lockArray2DReal(mutexArray2DReal); \
568 MutexLocker lockTensorReal(mutexTensorReal); \
569 MutexLocker lockStereoSample(mutexStereoSample); \
570 MutexLocker lockSingleReal(mutexSingleReal); \
571 MutexLocker lockSingleString(mutexSingleString); \
572 MutexLocker lockSingleVectorReal(mutexSingleVectorReal); \
573 MutexLocker lockSingleVectorString(mutexSingleVectorString);\
574 MutexLocker lockSingleTensorReal(mutexSingleTensorReal);
579 inline void Pool::append(
const std::string& name,
const std::vector<T>& values) {
580 throw EssentiaException(
"Pool::append not implemented for type: ",
nameOfType(
typeid(T)));
583 #define SPECIALIZE_APPEND(type, tname) \
585 inline void Pool::append(const std::string& name, const std::vector<type>& values) { \
587 MutexLocker lock(mutex##tname); \
588 PoolOf(type)::iterator result = _pool##tname.find(name); \
589 if (result != _pool##tname.end()) { \
591 std::vector<type>& v = result->second; \
592 int vsize = v.size(); \
593 v.resize(vsize + values.size()); \
594 fastcopy(&v[vsize], &values[0], values.size()); \
601 _pool##tname[name] = values; \
606 SPECIALIZE_APPEND(std::vector<Real>, VectorReal);
607 SPECIALIZE_APPEND(std::string, String);
608 SPECIALIZE_APPEND(std::vector<std::string>, VectorString);
Definition: threading.h:51
Definition: threading.h:45
Mutex mutexReal
Definition: pool.h:127
Mutex mutexTensorReal
Definition: pool.h:130
std::vector< std::string > descriptorNames(const std::string &ns) const
void add(const std::string &name, const TNT::Array2D< Real > &value, bool validityCheck=false)
std::map< std::string, std::vector< Tensor< Real > > > _poolTensorReal
Definition: pool.h:112
void merge(const std::string &name, const std::vector< std::vector< Real > > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
void mergeSingle(const std::string &name, const std::string &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
std::map< std::string, std::vector< std::string > > _poolString
Definition: pool.h:109
const std::map< std::string, std::vector< std::string > > & getSingleVectorStringPool() const
Definition: pool.h:380
void merge(const std::string &name, const std::vector< Tensor< Real > > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
void mergeSingle(const std::string &name, const Real &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
void append(const std::string &name, const std::vector< T > &values)
const std::map< std::string, std::vector< std::vector< Real > > > & getVectorRealPool() const
Definition: pool.h:326
Mutex mutexString
Definition: pool.h:127
const T & value(const std::string &name) const
std::map< std::string, std::vector< TNT::Array2D< Real > > > _poolArray2DReal
Definition: pool.h:111
const std::map< std::string, std::vector< TNT::Array2D< Real > > > & getArray2DRealPool() const
Definition: pool.h:344
std::map< std::string, std::vector< Real > > _poolSingleVectorReal
Definition: pool.h:102
const std::map< std::string, std::vector< std::string > > & getStringPool() const
Definition: pool.h:332
std::map< std::string, std::vector< std::vector< Real > > > _poolVectorReal
Definition: pool.h:108
void set(const std::string &name, const std::string &value, bool validityCheck=false)
Sets the value of a descriptor name.
std::map< std::string, Tensor< Real > > _poolSingleTensorReal
Definition: pool.h:104
Mutex mutexStereoSample
Definition: pool.h:128
void remove(const std::string &name)
void checkIntegrity() const
void add(const std::string &name, const Real &value, bool validityCheck=false)
std::vector< std::string > descriptorNamesNoLocking() const
Mutex mutexArray2DReal
Definition: pool.h:128
std::map< std::string, std::vector< StereoSample > > _poolStereoSample
Definition: pool.h:113
const std::map< std::string, Real > & getSingleRealPool() const
Definition: pool.h:362
void set(const std::string &name, const Real &value, bool validityCheck=false)
Sets the value of a descriptor name.
std::map< std::string, std::vector< std::string > > _poolSingleVectorString
Definition: pool.h:103
std::map< std::string, std::vector< Real > > _poolReal
Definition: pool.h:107
std::map< std::string, std::string > _poolSingleString
Definition: pool.h:101
void mergeSingle(const std::string &name, const Tensor< Real > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
Mutex mutexSingleTensorReal
Definition: pool.h:130
void add(const std::string &name, const std::string &value, bool validityCheck=false)
void mergeSingle(const std::string &name, const std::vector< std::string > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
void set(const std::string &name, const std::vector< Real > &value, bool validityCheck=false)
Sets the value of a descriptor name.
void merge(const std::string &name, const std::vector< TNT::Array2D< Real > > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
void merge(const std::string &name, const std::vector< std::string > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
void add(const std::string &name, const StereoSample &value, bool validityCheck=false)
void validateKey(const std::string &name)
Mutex mutexSingleReal
Definition: pool.h:129
std::vector< std::string > descriptorNames() const
void mergeSingle(const std::string &name, const std::vector< Real > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
std::map< std::string, Real > _poolSingleReal
Definition: pool.h:100
const std::map< std::string, std::vector< std::vector< std::string > > > & getVectorStringPool() const
Definition: pool.h:338
void set(const std::string &name, const std::vector< std::string > &value, bool validityCheck=false)
Sets the value of a descriptor name.
Mutex mutexVectorReal
Definition: pool.h:127
void set(const std::string &name, const Tensor< Real > &value, bool validityCheck=false)
const std::map< std::string, std::vector< Real > > & getSingleVectorRealPool() const
Definition: pool.h:374
Mutex mutexSingleVectorString
Definition: pool.h:130
Mutex mutexSingleVectorReal
Definition: pool.h:129
void merge(Pool &p, const std::string &type="")
Merges the current pool with the given one p.
void merge(const std::string &name, const std::vector< std::vector< std::string > > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
const std::map< std::string, std::vector< Real > > & getRealPool() const
Definition: pool.h:320
void add(const std::string &name, const std::vector< std::string > &value, bool validityCheck=false)
Mutex mutexVectorString
Definition: pool.h:127
bool isSingleValue(const std::string &name)
void removeNamespace(const std::string &ns)
Mutex mutexSingleString
Definition: pool.h:129
const std::map< std::string, std::string > & getSingleStringPool() const
Definition: pool.h:368
void merge(const std::string &name, const std::vector< StereoSample > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
void merge(const std::string &name, const std::vector< Real > &value, const std::string &type="")
Merges the values given in value into the current pool's descriptor given by name.
bool contains(const std::string &name) const
const std::map< std::string, Tensor< Real > > & getSingleTensorRealPool() const
Definition: pool.h:386
std::map< std::string, std::vector< std::vector< std::string > > > _poolVectorString
Definition: pool.h:110
const std::map< std::string, std::vector< StereoSample > > & getStereoSamplePool() const
Definition: pool.h:356
const std::map< std::string, std::vector< Tensor< Real > > > & getTensorRealPool() const
Definition: pool.h:350
void add(const std::string &name, const Tensor< Real > &value, bool validityCheck=false)
void add(const std::string &name, const std::vector< Real > &value, bool validityCheck=false)
Definition: algorithm.h:28
std::string nameOfType(const std::type_info &type)
Tuple2< Real > StereoSample
Definition: types.h:371
std::string DescriptorName
Definition: pool.h:35
float Real
Definition: types.h:69
Eigen::Tensor< T, 4, Eigen::RowMajor > Tensor
Definition: types.h:384
#define PoolOf(type)
Definition: pool.h:33