Dripline-Cpp  v2.4.2
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  virtual ~throw_reply() noexcept;
48 
49  throw_reply& operator=( const throw_reply& a_orig );
50 
51  template< class x_streamable >
52  throw_reply& operator<<( x_streamable a_fragment );
53  throw_reply& operator<<( const std::string& a_fragment );
54  throw_reply& operator<<( const char* a_fragment );
55 
56  const std::string& return_message() const noexcept;
57  std::string& return_message();
58 
59  const return_code& ret_code() const noexcept;
60  void set_return_code( const return_code& a_code );
61 
62  const scarab::param& payload() const noexcept;
63  scarab::param& payload();
64  void set_payload( scarab::param_ptr_t a_payload );
65  const scarab::param_ptr_t& get_payload_ptr() const noexcept;
66 
67 #ifdef DL_PYTHON
68  mv_referrable_static( std::string, py_throw_reply_keyword );
69 #endif
70 
71  protected:
72  std::string f_return_message;
73  std::shared_ptr< return_code > f_return_code;
74  scarab::param_ptr_t f_payload;
75  };
76 
77 
78  template< class x_streamable >
79  throw_reply& throw_reply::operator<<( x_streamable a_fragment )
80  {
81  std::stringstream stream;
82  stream << a_fragment;
83  f_return_message += stream.str();
84  return *this;
85  }
86 
87  inline throw_reply& throw_reply::operator<<( const std::string& a_fragment )
88  {
89  f_return_message += a_fragment;
90  return *this;
91  }
92 
93  inline throw_reply& throw_reply::operator<<( const char* a_fragment )
94  {
95  f_return_message += std::string( a_fragment );
96  return *this;
97  }
98 
99  inline const std::string& throw_reply::return_message() const noexcept
100  {
101  return f_return_message;
102  }
103 
104  inline std::string& throw_reply::return_message()
105  {
106  return f_return_message;
107  }
108 
109  inline const return_code& throw_reply::ret_code() const noexcept
110  {
111  return *f_return_code;
112  }
113 
114  inline void throw_reply::set_return_code( const return_code& a_code )
115  {
116  f_return_code.reset( new copy_code( a_code ) );
117  return;
118  }
119 
120  inline const scarab::param& throw_reply::payload() const noexcept
121  {
122  return *f_payload;
123  }
124 
125  inline scarab::param& throw_reply::payload()
126  {
127  return *f_payload;
128  }
129 
130  inline void throw_reply::set_payload( scarab::param_ptr_t a_payload )
131  {
132  f_payload = std::move( a_payload );
133  return;
134  }
135 
136  inline const scarab::param_ptr_t& throw_reply::get_payload_ptr() const noexcept
137  {
138  return f_payload;
139  }
140 
141 }
142 
143 #endif /* DRIPLINE_THROW_REPLY_HH_ */
Base class for return codes.
Definition: return_codes.hh:39
const return_code & ret_code() const noexcept
Definition: throw_reply.hh:109
const scarab::param_ptr_t & get_payload_ptr() const noexcept
Definition: throw_reply.hh:136
scarab::param_ptr_t f_payload
Definition: throw_reply.hh:74
Stores a copy of the return-code value, name, and description, either as a custom return-code or copy...
Definition: return_codes.hh:52
std::ostream & operator<<(std::ostream &a_os, op_t an_op)
Pass the integer-equivalent of a message-operation enum to an ostream.
#define DRIPLINE_API
Definition: dripline_api.hh:34
throw_reply & operator<<(x_streamable a_fragment)
Definition: throw_reply.hh:79
const scarab::param & payload() const noexcept
Definition: throw_reply.hh:120
std::string f_return_message
Definition: throw_reply.hh:72
Object that can be thrown while processing a request to send a reply.
Definition: throw_reply.hh:41
std::shared_ptr< return_code > f_return_code
Definition: throw_reply.hh:73
const std::string & return_message() const noexcept
Definition: throw_reply.hh:99
void set_return_code(const return_code &a_code)
Definition: throw_reply.hh:114
void set_payload(scarab::param_ptr_t a_payload)
Definition: throw_reply.hh:130