1 //  Libiqxmlrpc - an object-oriented XML-RPC solution.
2 //  Copyright (C) 2011 Anton Dedov
3 
4 #ifndef _iqxmlrpc_response_h_
5 #define _iqxmlrpc_response_h_
6 
7 #include <boost/shared_ptr.hpp>
8 #include <string>
9 #include "api_export.h"
10 
11 namespace iqxmlrpc {
12 
13 class Response;
14 class Value;
15 
16 #ifdef _MSC_VER
17 #pragma warning(push)
18 #pragma warning(disable: 4251)
19 #endif
20 
21 //! Build response object from XML-formed string.
22 LIBIQXMLRPC_API Response parse_response( const std::string& );
23 
24 //! Dump response to XML.
25 LIBIQXMLRPC_API std::string dump_response( const Response& );
26 
27 //! XML-RPC response.
28 class LIBIQXMLRPC_API Response {
29 public:
30   Response( Value* );
31   Response( int fault_code, const std::string& fault_string );
32 
33   //! Returns response value or throws iqxmlrpc::Fault in case of fault.
34   const Value& value() const;
35 
36   //! Check whether response is an XML-RPC Fault Reponse.
is_fault()37   bool is_fault()   const { return !value_; }
38   //! Returns fault code of Fault Response.
fault_code()39   int  fault_code() const { return fault_code_; }
40   //! Returns fault string of Fault Response.
fault_string()41   const std::string& fault_string() const { return fault_string_; }
42 
43 private:
44   boost::shared_ptr<Value> value_;
45   int fault_code_;
46   std::string fault_string_;
47 };
48 
49 #ifdef _MSC_VER
50 #pragma warning(pop)
51 #endif
52 
53 } // namespace iqxmlrpc
54 
55 #endif
56