libiqxmlrpc  0.12.12
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  static void set_default_int(int);
117  static Int* get_default_int();
118  static void drop_default_int();
119 
120  static void omit_string_tag_in_responses(bool);
121  static bool omit_string_tag_in_responses();
122 
123 private:
124  template <class T> T* cast() const;
125  template <class T> bool can_cast() const;
126 };
127 
128 class XmlBuilder;
129 void LIBIQXMLRPC_API value_to_xml(XmlBuilder&, const Value&);
130 void LIBIQXMLRPC_API print_value(const Value&, std::ostream&);
131 
132 } // namespace iqxmlrpc
133 
134 #include "value_type.inl"
135 
136 #endif
Template for scalar types based on Value_type (e.g. Int, String, etc.)
Definition: value_type.h:29
Proxy class to access XML-RPC values by library users.
Definition: value.h:19
XML-RPC array type. Operates with objects of type Value, not Value_type.
Definition: value_type.h:82
XML-RPC extension: Nil type.
Definition: value_type.h:49
XML-RPC dateTime.iso8601 type.
Definition: value_type.h:306
Const interator for Array.
Definition: value_type.h:160
XML-RPC array type. Operates with objects of type Value, not Value_type.
Definition: value_type.h:203
Definition: value.h:23
The Value_type's visitor base class.
Definition: value_type_visitor.h:17
XML-RPC library.
Definition: auth_plugin.cc:6
Base type for XML-RPC types.
Definition: value_type.h:37
Base class for iqxmlrpc exceptions.
Definition: except.h:23
XML-RPC Base64 type.
Definition: value_type.h:259
Definition: xml_builder.h:15