[5284] | 1 | // to_string_v.hpp, created on 30.06.2009 by Sebastian Mies
|
---|
| 2 |
|
---|
| 3 | #ifndef TO_STRING_V_HPP_
|
---|
| 4 | #define TO_STRING_V_HPP_
|
---|
| 5 |
|
---|
| 6 | #include <string>
|
---|
| 7 | #include "vfacade.hpp"
|
---|
| 8 |
|
---|
| 9 | using namespace std;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * TODO: Doc
|
---|
| 13 | *
|
---|
| 14 | * @author Sebastian Mies <mies@tm.uka.de>
|
---|
| 15 | */
|
---|
| 16 | /// a to to string interface
|
---|
| 17 | class to_string_v {
|
---|
| 18 | public:
|
---|
| 19 | //--- to_string_v ---------------------------------------------------------
|
---|
| 20 |
|
---|
| 21 | /// convert address to a string that can be used to reconstruct the address
|
---|
| 22 | virtual string to_string() const = 0;
|
---|
| 23 |
|
---|
| 24 | /// Assigns an address using a human-readable
|
---|
| 25 | virtual bool assign(const std::string& text) = 0;
|
---|
| 26 |
|
---|
| 27 | /// convenience method for assignment of a c-strings
|
---|
| 28 | inline to_string_v& assign(const char* text) {
|
---|
| 29 | to_string_v::assign(std::string(text));
|
---|
| 30 | return *this;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | /// convenience method for assignment of strings
|
---|
| 34 | inline to_string_v& operator=(const std::string& text) {
|
---|
| 35 | assign(text);
|
---|
| 36 | return *this;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | /// convenience method for assignment of strings
|
---|
| 40 | inline to_string_v& operator=(const char* text) {
|
---|
| 41 | assign(text);
|
---|
| 42 | return *this;
|
---|
| 43 | }
|
---|
| 44 | };
|
---|
| 45 |
|
---|
| 46 | typedef vfacade<to_string_v> to_string_vf;
|
---|
| 47 |
|
---|
| 48 | /// the object hull for to_string interfaces
|
---|
| 49 | template<class NonVirtual, class AdaptorType>
|
---|
| 50 | class vobject_hull<NonVirtual, to_string_v, AdaptorType> : public to_string_v {
|
---|
| 51 | private:
|
---|
| 52 | typename AdaptorType::template adaptor_type<NonVirtual> obj;
|
---|
| 53 |
|
---|
| 54 | public:
|
---|
| 55 | template<typename T>
|
---|
| 56 | explicit vobject_hull(T& obj) :
|
---|
| 57 | obj(obj) {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | explicit vobject_hull() :
|
---|
| 61 | obj() {
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | //--- to_string_v ---------------------------------------------------------
|
---|
| 65 |
|
---|
| 66 | /// convert address to a string that can be used to reconstruct the address
|
---|
| 67 | virtual string to_string() const {
|
---|
| 68 | return obj->to_string();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /// Assigns an address using a human-readable
|
---|
| 72 | virtual bool assign(const std::string& text) {
|
---|
| 73 | return obj->assign(text);
|
---|
| 74 | }
|
---|
| 75 | };
|
---|
| 76 |
|
---|
| 77 | #endif /* TO_STRING_V_HPP_ */
|
---|