Dripline-Cpp  v2.10.11
Dripline Implementation in C++
throw_reply.hh
Go to the documentation of this file.
1 /*
2  * throw_reply.hh
3  *
4  * Created on: Jan 2, 2020
5  * Author: N.S. Oblath
6  */
7 
8 #ifndef DRIPLINE_THROW_REPLY_HH_
9 #define DRIPLINE_THROW_REPLY_HH_
10 
11 #include "return_codes.hh"
12 
13 #include "member_variables.hh"
14 #include "param.hh"
15 
16 #include <exception>
17 #include <memory>
18 #include <sstream>
19 
20 
21 namespace dripline
22 {
23 
42  {
43  public:
44  throw_reply();
45  throw_reply( const return_code& a_code, scarab::param_ptr_t a_payload_ptr = scarab::param_ptr_t(new scarab::param()) );
46  throw_reply( const throw_reply& a_orig );
47  throw_reply( throw_reply&& ) = default;
48  virtual ~throw_reply() noexcept = default;
49 
50  throw_reply& operator=( const throw_reply& a_orig );
51  throw_reply& operator=( throw_reply&& ) = default;
52 
53  template< class x_streamable >
54  throw_reply& operator<<( x_streamable a_fragment );
55  throw_reply& operator<<( const std::string& a_fragment );
56  throw_reply& operator<<( const char* a_fragment );
57 
58  const std::string& return_message() const noexcept;
59  std::string& return_message();
60 
61  const return_code& ret_code() const noexcept;
62  void set_return_code( const return_code& a_code );
63 
64  const scarab::param& payload() const noexcept;
65  scarab::param& payload();
66  void set_payload( scarab::param_ptr_t a_payload );
67  const scarab::param_ptr_t& get_payload_ptr() const noexcept;
68 
69 #ifdef DL_PYTHON
70  mv_referrable_static( std::string, py_throw_reply_keyword );
71 #endif
72 
73  protected:
74  std::string f_return_message;
75  std::shared_ptr< return_code > f_return_code;
76  scarab::param_ptr_t f_payload;
77  };
78 
79 
80  template< class x_streamable >
81  throw_reply& throw_reply::operator<<( x_streamable a_fragment )
82  {
83  std::stringstream stream;
84  stream << a_fragment;
85  f_return_message += stream.str();
86  return *this;
87  }
88 
89  inline throw_reply& throw_reply::operator<<( const std::string& a_fragment )
90  {
91  f_return_message += a_fragment;
92  return *this;
93  }
94 
95  inline throw_reply& throw_reply::operator<<( const char* a_fragment )
96  {
97  f_return_message += std::string( a_fragment );
98  return *this;
99  }
100 
101  inline const std::string& throw_reply::return_message() const noexcept
102  {
103  return f_return_message;
104  }
105 
106  inline std::string& throw_reply::return_message()
107  {
108  return f_return_message;
109  }
110 
111  inline const return_code& throw_reply::ret_code() const noexcept
112  {
113  return *f_return_code;
114  }
115 
116  inline void throw_reply::set_return_code( const return_code& a_code )
117  {
118  f_return_code.reset( new copy_code( a_code ) );
119  return;
120  }
121 
122  inline const scarab::param& throw_reply::payload() const noexcept
123  {
124  return *f_payload;
125  }
126 
127  inline scarab::param& throw_reply::payload()
128  {
129  return *f_payload;
130  }
131 
132  inline void throw_reply::set_payload( scarab::param_ptr_t a_payload )
133  {
134  f_payload = std::move( a_payload );
135  return;
136  }
137 
138  inline const scarab::param_ptr_t& throw_reply::get_payload_ptr() const noexcept
139  {
140  return f_payload;
141  }
142 
143 }
144 
145 #endif /* DRIPLINE_THROW_REPLY_HH_ */
Object that can be thrown while processing a request to send a reply.
Definition: throw_reply.hh:42
std::string f_return_message
Definition: throw_reply.hh:74
const return_code & ret_code() const noexcept
Definition: throw_reply.hh:111
const scarab::param_ptr_t & get_payload_ptr() const noexcept
Definition: throw_reply.hh:138
throw_reply & operator<<(x_streamable a_fragment)
Definition: throw_reply.hh:81
const std::string & return_message() const noexcept
Definition: throw_reply.hh:101
scarab::param_ptr_t f_payload
Definition: throw_reply.hh:76
virtual ~throw_reply() noexcept=default
void set_payload(scarab::param_ptr_t a_payload)
Definition: throw_reply.hh:132
throw_reply(throw_reply &&)=default
void set_return_code(const return_code &a_code)
Definition: throw_reply.hh:116
const scarab::param & payload() const noexcept
Definition: throw_reply.hh:122
std::shared_ptr< return_code > f_return_code
Definition: throw_reply.hh:75
#define DRIPLINE_API
Definition: dripline_api.hh:34
Definition: agent.hh:18
Stores a copy of the return-code value, name, and description, either as a custom return-code or copy...
Definition: return_codes.hh:53
Base class for return codes.
Definition: return_codes.hh:40