Essentia  2.1-beta5-dev
iotypewrappers_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2016 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Essentia
5  *
6  * Essentia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef ESSENTIA_IOTYPEWRAPPERSIMPL_H
21 #define ESSENTIA_IOTYPEWRAPPERSIMPL_H
22 
23 #include "iotypewrappers.h"
24 #include "algorithm.h"
25 
26 namespace essentia {
27 namespace standard {
28 
29 
30 inline std::string InputBase::fullName() const {
31  std::ostringstream fullname;
32  fullname << (_parent ? _parent->name() : "<NoParent>") << "::" << name();
33  return fullname.str();
34 }
35 
36 template <typename Type>
37 void InputBase::set(const Type& data) {
38  try {
39  checkType<Type>();
40  _data = &data;
41  }
42  catch (EssentiaException& e) {
43  throw EssentiaException("In ", fullName(), "::set(): ", e.what());
44  }
45 }
46 
47 
48 template <typename Type>
49 class Input : public InputBase {
51 
52  public:
53  const Type& get() const {
54  if (!_data) {
55  throw EssentiaException("In ", fullName(), "::get(): Input not bound to concrete object");
56  }
57  return *(Type*)_data;
58  }
59 };
60 
61 
62 
63 inline std::string OutputBase::fullName() const {
64  std::ostringstream fullname;
65  fullname << (_parent ? _parent->name() : "<NoParent>") << "::" << name();
66  return fullname.str();
67 }
68 
69 template <typename Type>
70 void OutputBase::set(Type& data) {
71  try {
72  checkType<Type>();
73  _data = &data;
74  }
75  catch (EssentiaException& e) {
76  throw EssentiaException("In ", fullName(), "::set(): ", e.what());
77  }
78 }
79 
80 template <typename Type>
81 class Output : public OutputBase {
83 
84  public:
85  Type& get() {
86  if (!_data) {
87  throw EssentiaException("In ", fullName(), "::set(): Output not bound to concrete object");
88  }
89  return *(Type*)_data;
90  }
91 };
92 
93 
94 } // namespace standard
95 } // namespace essentia
96 
97 #endif // ESSENTIA_IOTYPEWRAPPERSIMPL_H
virtual const char * what() const
Definition: types.h:99
const void * _data
Definition: iotypewrappers.h:61
void set(Type &data)
Definition: iotypewrappers_impl.h:70
const std::string & name() const
Definition: configurable.h:48
Definition: iotypewrappers_impl.h:49
Algorithm * _parent
Definition: iotypewrappers.h:38
#define USE_TYPE_INFO(TokenType)
Definition: types.h:331
std::string fullName() const
Definition: iotypewrappers_impl.h:30
Definition: algorithm.h:28
Definition: iotypewrappers_impl.h:81
Definition: iotypewrappers.h:66
Definition: iotypewrappers.h:35
Definition: types.h:76
std::string fullName() const
Definition: iotypewrappers_impl.h:63
void set(const Type &data)
Definition: iotypewrappers_impl.h:37
const std::string & name() const
Definition: types.h:283