nds2-client - ClientDeveloper  0.16.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nds_parameter_block.hh
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 
3 #ifndef SWIG__COMMON__NDS_PARAMS_HH
4 #define SWIG__COMMON__NDS_PARAMS_HH
5 
6 #include <string>
7 #include <vector>
8 #include <unordered_map>
9 #include <memory>
10 
11 #include "nds_gap_handler.hh"
12 #include "nds_connection.hh"
13 
14 namespace NDS
15 {
16  namespace detail
17  {
23  bool str_to_bool( const std::string& input, bool& dest );
24 
26  {
27  std::string name;
28  std::unique_ptr< gap_handler > handler;
29 
31  : name( "ABORT_HANDLER" ),
32  handler(
33  NDS::detail::make_unique< detail::abort_gap_handler >( ) )
34  {
35  }
36  param_gap_handler( std::string handler_name,
37  std::unique_ptr< gap_handler > handler_ptr )
38  : name( std::move( handler_name ) ),
39  handler( std::move( handler_ptr ) )
40  {
41  }
43  : name( other.name ), handler( other.handler->clone( ) )
44  {
45  }
46  param_gap_handler( param_gap_handler&& other ) = default;
48  operator=( const param_gap_handler& other )
49  {
50  if ( this != &other )
51  {
52  std::unique_ptr< gap_handler > tmp(
53  other.handler->clone( ) );
54  name = other.name;
55  handler = std::move( tmp );
56  }
57  return *this;
58  }
59  param_gap_handler& operator=( param_gap_handler&& other ) = default;
60  ~param_gap_handler( ) = default;
61  };
62 
64  {
65  NDS::connection::host_type hostname;
66  NDS::connection::port_type port;
67  NDS::connection::protocol_type protocol;
68 
70  : hostname( "localhost" ),
71  port( NDS::connection::DEFAULT_PORT ),
72  protocol( NDS::connection::PROTOCOL_TRY )
73  {
74  }
75  param_net_conn_info( NDS::connection::host_type Hostname,
76  NDS::connection::port_type Port,
77  NDS::connection::protocol_type Protocol )
78  : hostname( std::move( Hostname ) ), port( Port ),
79  protocol( Protocol )
80  {
81  }
82  param_net_conn_info( const param_net_conn_info& other ) = default;
83  param_net_conn_info( param_net_conn_info&& other ) noexcept =
84  default;
85 
87  operator=( const param_net_conn_info& other ) = default;
89  operator=( param_net_conn_info&& other ) = delete;
90  };
91 
92  //-----------------------------------------------------------------
95  //-----------------------------------------------------------------
96 
98  {
99  public:
100  parameter_block( );
101  explicit parameter_block( const param_net_conn_info& conn_info );
102 
103  parameter_block( const parameter_block& other ) = default;
104  parameter_block( parameter_block&& other ) = default;
105 
106  parameter_block&
107  operator=( const parameter_block& other ) = default;
108  parameter_block&
109  operator=( parameter_block&& other ) noexcept = delete;
110 
111  // Get the string representation of the given parameter, or ""
112  // if the parameter does not exist
113  std::string get( const std::string& parameter ) const;
114 
115  // Set the string representation of a parameter
116  // @param[in] parameter - The name of the parameter to set
117  // @param[in] value - The string representation of the value
118  // @returns - true if the value could be set, else false
119  bool set( const std::string& parameter, const std::string& value );
120 
121  // Return a sequence of strings listing all the parameters
122  // that can be set
123  //
124  // @returns std::vector<std::string> contianing parameter names
125  std::vector< std::string > parameters( ) const;
126 
127  // Return the standard prefix that should be applied to
128  // the parameter name when reading it from the environment
129  std::string env_prefix( ) const;
130 
131  // After how many commands should we cycle an nds1 connection
132  int
134  {
135  return _max_nds1_command_count;
136  }
137 
138  // Are requests allowed to read data from tape?
139  bool
141  {
142  return _allow_data_on_tape;
143  };
144 
145  // Retrieve gap handler
146  std::unique_ptr< NDS::detail::gap_handler >
147  gap_handler( ) const
148  {
149  return _gap_handler.handler->clone( );
150  }
151 
152  // Should iterate use the gap handler
153  bool
155  {
156  return _iterate_uses_gap_handler;
157  }
158 
159  param_net_conn_info& conn_info( );
160 
161  const param_net_conn_info& conn_info( ) const;
162 
163  private:
169 
170  bool set_gap_handler( const std::string& handler_str );
171  };
172 
178  {
179  public:
180  explicit parameter_accessor( NDS::parameters& params )
181  : params_( params )
182  {
183  }
184  parameter_accessor( const parameter_accessor& other ) = default;
185  parameter_accessor( parameter_accessor&& other ) = delete;
186 
188  operator( )( ) const
189  {
190  return *( params_.p_ );
191  }
192 
193  private:
194  NDS::parameters& params_;
195  };
196  }
197 }
198 
199 #endif // SWIG__COMMON__NDS_PARAMS_HH
bool _allow_data_on_tape
Definition: nds_parameter_block.hh:165
param_net_conn_info()
Definition: nds_parameter_block.hh:69
param_net_conn_info(NDS::connection::host_type Hostname, NDS::connection::port_type Port, NDS::connection::protocol_type Protocol)
Definition: nds_parameter_block.hh:75
NDS::connection::host_type hostname
Definition: nds_parameter_block.hh:65
A parameter block describes parameters affecting the behavior of the NDS::connection.
Definition: nds_parameter_block.hh:97
parameter_accessor(NDS::parameters &params)
Definition: nds_parameter_block.hh:180
param_gap_handler(std::string handler_name, std::unique_ptr< gap_handler > handler_ptr)
Definition: nds_parameter_block.hh:36
Definition: nds_parameter_block.hh:63
std::unique_ptr< NDS::detail::gap_handler > gap_handler() const
Definition: nds_parameter_block.hh:147
param_gap_handler & operator=(const param_gap_handler &other)
Definition: nds_parameter_block.hh:48
param_gap_handler()
Definition: nds_parameter_block.hh:30
NDS::parameters & params_
Definition: nds_parameter_block.hh:194
std::unique_ptr< gap_handler > handler
Definition: nds_parameter_block.hh:28
bool allow_data_on_tape() const
Definition: nds_parameter_block.hh:140
NDS::connection::protocol_type protocol
Definition: nds_parameter_block.hh:67
int _max_nds1_command_count
Definition: nds_parameter_block.hh:164
bool iterate_uses_gap_handler() const
Definition: nds_parameter_block.hh:154
std::string name
Definition: nds_parameter_block.hh:27
std::unique_ptr< T > make_unique(Ts &&...params)
Definition: nds_memory.hh:24
param_net_conn_info & operator=(const param_net_conn_info &other)=default
param_gap_handler _gap_handler
Definition: nds_parameter_block.hh:167
bool _iterate_uses_gap_handler
Definition: nds_parameter_block.hh:166
int max_nds1_command_count() const
Definition: nds_parameter_block.hh:133
A parameter_accessor allows internal code to access the detail::parameter_block in a NDS::connection:...
Definition: nds_parameter_block.hh:177
NDS::connection::port_type port
Definition: nds_parameter_block.hh:66
Definition: nds_gap_handler.hh:122
param_gap_handler(const param_gap_handler &other)
Definition: nds_parameter_block.hh:42
Definition: nds_parameter_block.hh:25
param_net_conn_info _net_conn_info
Definition: nds_parameter_block.hh:168
bool str_to_bool(const std::string &input, bool &dest)
Given a std::string extract a boolean value.
Definition: nds_parameter_block.cc:242