libiqxmlrpc  0.12.4
 All Classes Namespaces Files Functions Typedefs Enumerations
value.h
1 // Libiqxmlrpc - an object-oriented XML-RPC solution.
2 // Copyright (C) 2011 Anton Dedov
3 
4 #ifndef _iqxmlrpc_value_h_
5 #define _iqxmlrpc_value_h_
6 
7 #include <iosfwd>
8 #include <string>
9 #include <typeinfo>
10 #include <vector>
11 
12 #include "except.h"
13 #include "value_type.h"
14 
15 namespace iqxmlrpc {
16 
18 
19 class LIBIQXMLRPC_API Value {
20 public:
23  class Bad_cast: public Exception {
24  public:
25  Bad_cast();
26  };
27 
28 private:
29  Value_type* value;
30 
31 public:
32  Value( Value_type* );
33  Value( const Value& );
34  Value( Nil );
35  Value( int );
36  Value( bool );
37  Value( double );
38  Value( std::string );
39  Value( const char* );
40  Value( const Binary_data& );
41  Value( const Date_time& );
42  Value( const struct tm* );
43  Value( const Array& );
44  Value( const Struct& );
45 
46  virtual ~Value();
47 
48  const Value& operator =( const Value& );
49 
52  bool is_nil() const;
53  bool is_int() const;
54  bool is_bool() const;
55  bool is_double() const;
56  bool is_string() const;
57  bool is_binary() const;
58  bool is_datetime() const;
59  bool is_array() const;
60  bool is_struct() const;
61 
62  const std::string& type_name() const;
64 
67  int get_int() const;
68  bool get_bool() const;
69  double get_double() const;
70  std::string get_string() const;
71  Binary_data get_binary() const;
72  Date_time get_datetime() const;
73 
74  operator int() const;
75  operator bool() const;
76  operator double() const;
77  operator std::string() const;
78  operator Binary_data() const;
79  operator struct tm() const;
81 
85  Array& the_array();
86  const Array& the_array() const;
87 
88  size_t size() const;
89  const Value& operator []( int ) const;
90  Value& operator []( int );
91 
92  void push_back( const Value& v );
93 
94  Array::const_iterator arr_begin() const;
95  Array::const_iterator arr_end() const;
97 
101  Struct& the_struct();
102  const Struct& the_struct() const;
103 
104  bool has_field( const std::string& f ) const;
105 
106  const Value& operator []( const char* ) const;
107  Value& operator []( const char* );
108  const Value& operator []( const std::string& ) const;
109  Value& operator []( const std::string& );
110 
111  void insert( const std::string& n, const Value& v );
113 
114  void apply_visitor(Value_type_visitor&) const;
115 
116 private:
117  template <class T> T* cast() const;
118  template <class T> bool can_cast() const;
119 };
120 
121 class XmlBuilder;
122 void LIBIQXMLRPC_API value_to_xml(XmlBuilder&, const Value&);
123 void LIBIQXMLRPC_API print_value(const Value&, std::ostream&);
124 
125 } // namespace iqxmlrpc
126 
127 #include "value_type.inl"
128 
129 #endif