109 struct Any :
public std::string{
120 inline Any(
const T &t):std::string(
str(t)){}
128 inline operator T()
const{
147 return parse<T>(*
this);
152 return s << (
const std::string&)any;
157 return s >> (std::string&)any;
162 Any(
size_t n,
char c):std::string(n,c){}
170 return *(T**)(&any[0]);
177 Any any(std::string(
sizeof(
void*),
'\0'));
178 *((
const void**)&any[0]) = p;
186 inline std::vector<float> Any::as<std::vector<float> >()
const{
187 const size_t l = std::string::length();
188 if(l <
sizeof(
int))
throw ICLException(
"cannot convert Any to std::vector<float> size must be at least sizeof(int)");
189 const icl8u *p = (
const icl8u*)&std::string::operator[](0);
190 int size = *((
const int*)p);
192 if(l !=
sizeof(
int) +
sizeof(float) * size){
193 throw ICLException(
"error converting Any to std::vector<float> unexpected size");
195 return std::vector<float>((
const float*)p, ((
const float*)p) + size);
199 inline Any::Any(
const std::vector<float> &v){
200 std::string::resize(
sizeof(
int) + v.size() *
sizeof(float));
201 icl8u *p = (
icl8u*)&std::string::operator[](0);
202 *((
int*)p) = v.size();
203 memcpy(p+
sizeof(
int),v.data(), v.size()*
sizeof(float));
207 inline std::vector<int> Any::as<std::vector<int> >()
const{
208 const size_t l = std::string::length();
209 if(l <
sizeof(
int))
throw ICLException(
"cannot convert Any to std::vector<int> size must be at least sizeof(int)");
210 const icl8u *p = (
const icl8u*)&std::string::operator[](0);
211 int size = *((
const int*)p);
213 if(l !=
sizeof(
int) +
sizeof(int) * size){
214 throw ICLException(
"error converting Any to std::vector<int> unexpected size");
216 return std::vector<int>((
const int*)p, ((
const int*)p) + size);
220 inline Any::Any(
const std::vector<int> &v){
221 std::string::resize(
sizeof(
int) + v.size() *
sizeof(int));
222 icl8u *p = (
icl8u*)&std::string::operator[](0);
223 *((
int*)p) = v.size();
224 memcpy(p+
sizeof(
int),v.data(), v.size()*
sizeof(int));
Any()
Empty constructor.
Definition: Any.h:111
Any(size_t n, char c)
for direct creation of the parent string (used in the static ptr methods)
Definition: Any.h:162
undocument this line if you encounter any issues!
Definition: Any.h:37
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
T as() const
explict cast method (if implicit cast is ambiguous)
Definition: Any.h:146
Any(const T &t)
real constructor with any given source type
Definition: Any.h:120
friend std::istream & operator>>(std::istream &s, Any &any)
remembers the istream-operator<< that Any is of type std::string
Definition: Any.h:156
static Any ptr(const T *p)
this method can be used to create an any that contains a binary encoded pointer
Definition: Any.h:176
static T * ptr(const Any &any)
this method can be used to extract a pointer that was encoded as Any
Definition: Any.h:169
std::string str(const T &t)
convert a data type into a string using an std::ostringstream instance
Definition: StringUtils.h:136
Base class for Exception handling in the ICL.
Definition: Exception.h:42
friend std::ostream & operator<<(std::ostream &s, const Any &any)
remembers the ostream-operator<< that Any is of type std::string
Definition: Any.h:151
Simple generic data type implementation that uses a string based data representation.
Definition: Any.h:109