20 #ifndef ESSENTIA_TYPES_H
21 #define ESSENTIA_TYPES_H
33 #include <unsupported/Eigen/CXX11/Tensor>
53 typedef unsigned __int16
uint16;
54 typedef unsigned __int32
uint32;
55 typedef unsigned __int64
uint64;
84 template <
typename T,
typename U>
86 std::ostringstream oss; oss << a << b;
_msg = oss.str();
89 template <
typename T,
typename U,
typename V>
91 std::ostringstream oss; oss << a << b << c;
_msg = oss.str();
94 template <
typename T,
typename U,
typename V,
typename W>
96 std::ostringstream oss; oss << a << b << c << d;
_msg = oss.str();
100 virtual const char*
what()
const throw() {
return _msg.c_str(); }
112 return std::tolower(a) < std::tolower(b);
119 :
public std::binary_function<const std::string&, const std::string&, bool> {
120 bool operator()(
const std::string& str1,
const std::string& str2)
const {
121 return std::lexicographical_compare(str1.begin(), str1.end(),
122 str2.begin(), str2.end(),
129 class OrderedMap :
public std::vector<std::pair<std::string, T*> > {
131 typedef typename std::vector<std::pair<std::string, T*> >
BaseClass;
133 int size()
const {
return (
int)BaseClass::size(); }
136 return BaseClass::operator[](idx);
140 return BaseClass::operator[](idx);
146 if (charptr_cmp((*
this)[i].first.c_str(), str) == 0) {
147 return (*
this)[i].second;
155 return const_cast<T*
>(
const_cast<const OrderedMap<T>*
>(
this)->
operator[](str));
166 std::vector<std::string>
keys()
const {
167 std::vector<std::string> result(this->
size());
168 for (
int i=0; i<this->
size(); i++) {
169 result[i] = this->at(i).first;
174 void insert(
const std::string& key, T* value) {
175 this->push_back(std::make_pair(key, value));
189 template <
typename KeyType,
typename ValueType,
typename Compare = std::less<KeyType> >
190 class EssentiaMap :
public std::map<KeyType, ValueType, Compare> {
193 typedef std::map<KeyType, ValueType, Compare>
BaseClass;
199 typename BaseClass::iterator it = this->find(key);
200 if (it == BaseClass::end()) {
212 typename BaseClass::const_iterator it = this->find(key);
213 if (it == BaseClass::end()) {
219 std::pair<typename BaseClass::iterator, bool>
insert(
const KeyType& key,
const ValueType& value) {
220 return BaseClass::insert(std::make_pair(key, value));
223 std::vector<std::string>
keys()
const {
224 std::vector<std::string> result;
225 result.reserve(BaseClass::size());
226 std::ostringstream stream;
227 typename BaseClass::const_iterator it = this->begin();
228 for (; it != this->end(); ++it) {
231 result.push_back(stream.str());
250 #if SAFE_TYPE_COMPARISONS
254 inline bool sameType(
const std::type_info& t1,
const std::type_info& t2) {
255 return strcmp(t1.name(), t2.name()) == 0;
260 inline bool sameType(
const std::type_info& t1,
const std::type_info& t2) {
288 const std::type_info& expected)
const {
289 if (!
sameType(received, expected)) {
290 std::ostringstream msg;
291 msg <<
"Error when checking types. Expected: " <<
nameOfType(expected)
297 template <
typename Type>
310 virtual const std::type_info&
typeInfo()
const = 0;
332 #define USE_TYPE_INFO(TokenType) \
333 virtual const std::type_info& typeInfo() const { \
334 return typeid(TokenType); \
336 virtual const std::type_info& vectorTypeInfo() const { \
337 return typeid(std::vector<TokenType>); \
351 template <
typename T>
384 using Tensor = Eigen::Tensor<T, TENSORRANK, Eigen::RowMajor>;
400 using Tensor1D = Eigen::Tensor<Real, 1, Eigen::RowMajor>;
405 using Tensor2D = Eigen::Tensor<Real, 2, Eigen::RowMajor>;
410 using Tensor3D = Eigen::Tensor<Real, 3, Eigen::RowMajor>;
413 namespace streaming {
429 namespace BufferUsage {
EssentiaException(const T &a, const U &b)
Definition: types.h:85
EssentiaException(const std::ostringstream &msg)
Definition: types.h:82
std::string _msg
Definition: types.h:103
EssentiaException(const std::string &msg)
Definition: types.h:81
EssentiaException(const T &a, const U &b, const V &c, const W &d)
Definition: types.h:95
EssentiaException(const char *msg)
Definition: types.h:80
virtual ~EssentiaException()
Definition: types.h:99
EssentiaException(const T &a, const U &b, const V &c)
Definition: types.h:90
virtual const char * what() const
Definition: types.h:100
const ValueType & operator[](const KeyType &key) const
Definition: types.h:211
std::pair< typename BaseClass::iterator, bool > insert(const KeyType &key, const ValueType &value)
Definition: types.h:219
std::vector< std::string > keys() const
Definition: types.h:223
std::map< KeyType, ValueType, Compare > BaseClass
Definition: types.h:193
ValueType & operator[](const KeyType &key)
Definition: types.h:198
T * operator[](const char *str)
Definition: types.h:154
std::pair< std::string, T * > & operator[](uint idx)
Definition: types.h:139
std::vector< std::string > keys() const
Definition: types.h:166
const T * operator[](const std::string &str) const
Definition: types.h:158
const T * operator[](const char *str) const
Definition: types.h:143
T * operator[](const std::string &str)
Definition: types.h:162
void insert(const std::string &key, T *value)
Definition: types.h:174
const std::pair< std::string, T * > & operator[](uint idx) const
Definition: types.h:135
std::vector< std::pair< std::string, T * > > BaseClass
Definition: types.h:131
int size() const
Definition: types.h:133
T second
Definition: types.h:355
const T & y() const
Definition: types.h:360
const T & right() const
Definition: types.h:358
T & right()
Definition: types.h:363
T & y()
Definition: types.h:365
T & left()
Definition: types.h:362
T first
Definition: types.h:354
const T & x() const
Definition: types.h:359
const T & left() const
Definition: types.h:357
T & x()
Definition: types.h:364
void checkVectorSameTypeAs(const TypeProxy &obj) const
Definition: types.h:306
void checkSameTypeAs(const TypeProxy &obj) const
Definition: types.h:302
void checkType(const std::type_info &received, const std::type_info &expected) const
Definition: types.h:287
virtual ~TypeProxy()
Definition: types.h:282
virtual const std::type_info & vectorTypeInfo() const =0
virtual const std::type_info & typeInfo() const =0
TypeProxy(const std::string &name)
Definition: types.h:280
void setName(const std::string &name)
Definition: types.h:285
TypeProxy()
Definition: types.h:279
std::string _name
Definition: types.h:276
const std::string & name() const
Definition: types.h:284
void checkType() const
Definition: types.h:298
int maxContiguousElements
Definition: types.h:423
int size
Definition: types.h:422
BufferInfo(int size=0, int contiguous=0)
Definition: types.h:425
BufferUsageType
Definition: types.h:436
@ forMultipleFrames
Definition: types.h:438
@ forLargeAudioStream
Definition: types.h:440
@ forAudioStream
Definition: types.h:439
@ forSingleFrames
Definition: types.h:437
Definition: algorithm.h:28
Real AudioSample
Definition: types.h:349
bool sameType(const std::type_info &t1, const std::type_info &t2)
Definition: types.h:260
Eigen::TensorMap< Tensor< T >, 0 > TensorMap
Definition: types.h:390
Eigen::Tensor< Real, 1, Eigen::RowMajor > Tensor1D
Definition: types.h:400
Eigen::Tensor< Real, 2, Eigen::RowMajor > Tensor2D
Definition: types.h:405
Eigen::Tensor< Real, 3, Eigen::RowMajor > Tensor3D
Definition: types.h:410
std::string nameOfType(const std::type_info &type)
int ReaderID
Definition: types.h:344
Tuple2< Real > StereoSample
Definition: types.h:371
bool case_insensitive_char_cmp(char a, char b)
Definition: types.h:111
EssentiaMap< std::string, std::string, string_cmp > DescriptionMap
Definition: types.h:242
float Real
Definition: types.h:69
Eigen::Tensor< Real, 0, Eigen::RowMajor > TensorScalar
Definition: types.h:395
Eigen::Tensor< T, 4, Eigen::RowMajor > Tensor
Definition: types.h:384
bool operator()(const std::string &str1, const std::string &str2) const
Definition: types.h:120
int64_t sint64
Definition: types.h:47
int32_t sint32
Definition: types.h:46
unsigned int uint
Definition: types.h:49
int16_t sint16
Definition: types.h:45
uint64_t uint64
Definition: types.h:44
uint16_t uint16
Definition: types.h:42
uint32_t uint32
Definition: types.h:43