| 1 |
#ifndef INCLUDED_A2X_H_ |
| 2 |
#define INCLUDED_A2X_H_ |
| 3 |
|
| 4 |
#include <sstream> |
| 5 |
#include <string> |
| 6 |
|
| 7 |
//CLASS |
| 8 |
class A2x: public std::istringstream |
| 9 |
{ |
| 10 |
public: |
| 11 |
A2x() = default; |
| 12 |
A2x(char const *txt); |
| 13 |
A2x(std::string const &str); |
| 14 |
|
| 15 |
template <typename Type> |
| 16 |
operator Type(); |
| 17 |
|
| 18 |
template <typename Type> |
| 19 |
Type to(); |
| 20 |
|
| 21 |
A2x &operator=(char const *txt); |
| 22 |
|
| 23 |
A2x &operator=(std::string const &str); |
| 24 |
A2x &operator=(A2x const &other); |
| 25 |
}; |
| 26 |
//= |
| 27 |
|
| 28 |
//CONS |
| 29 |
inline A2x::A2x(char const *txt) // initialize from text |
| 30 |
: |
| 31 |
std::istringstream(txt) |
| 32 |
{} |
| 33 |
|
| 34 |
inline A2x::A2x(std::string const &str) |
| 35 |
: |
| 36 |
std::istringstream(str.c_str()) |
| 37 |
{} |
| 38 |
//= |
| 39 |
//TO |
| 40 |
template <typename Type> |
| 41 |
inline Type A2x::to() |
| 42 |
{ |
| 43 |
Type t; |
| 44 |
|
| 45 |
return (*this >> t) ? t : Type(); |
| 46 |
} |
| 47 |
//= |
| 48 |
//TYPE |
| 49 |
template <typename Type> |
| 50 |
inline A2x::operator Type() |
| 51 |
{ |
| 52 |
return to<Type>(); |
| 53 |
} |
| 54 |
//= |
| 55 |
inline A2x &A2x::operator=(std::string const &str) |
| 56 |
{ |
| 57 |
return operator=(str.c_str()); |
| 58 |
} |
| 59 |
//OP= |
| 60 |
inline A2x &A2x::operator=(A2x const &other) |
| 61 |
{ |
| 62 |
return operator=(other.str()); |
| 63 |
} |
| 64 |
//= |
| 65 |
|
| 66 |
#endif |