Dripline-Cpp  v2.10.11
Dripline Implementation in C++
specifier.cc
Go to the documentation of this file.
1 /*
2  * specifier.cc
3  *
4  * Created on: Feb 18, 2016
5  * Author: nsoblath
6  */
7 
8 #define DRIPLINE_API_EXPORTS
9 
10 #include "specifier.hh"
11 
12 #include "logger.hh"
13 
14 LOGGER( dlog, "specifier" );
15 
16 namespace dripline
17 {
18 
19  routing_key::routing_key( const std::string& a_rk ) :
20  deque()
21  {
22  if( ! a_rk.empty() ) add_next( a_rk );
23  }
24 
25  void routing_key::parse( const std::string& a_rk )
26  {
27  while( ! empty() ) pop_front();
28 
29  add_next( a_rk );
30  return;
31  }
32 
33  std::string routing_key::to_string() const
34  {
35  std::string t_return;
36  for( container_type::const_iterator t_it = this->begin(); t_it != this->end(); ++t_it )
37  {
38  if( t_it != this->begin() ) t_return += f_node_separator;
39  t_return += *t_it;
40  }
41  return t_return;
42  }
43 
44  void routing_key::add_next( const std::string& a_addr )
45  {
46  size_t t_div_pos = a_addr.find( f_node_separator );
47  if( t_div_pos == a_addr.npos )
48  {
49  push_back( a_addr );
50  return;
51  }
52  push_back( a_addr.substr( 0, t_div_pos ) );
53  add_next( a_addr.substr( t_div_pos + 1 ) );
54  return;
55  }
56 
57 
58  specifier::specifier( const std::string& a_unparsed ) :
60  f_unparsed( a_unparsed )
61  {
62  LTRACE( dlog, "Creating specifier <" << a_unparsed << ">" );
63  if( ! a_unparsed.empty() ) add_next( a_unparsed );
64  }
65 
66  specifier::specifier( const specifier& a_orig ) :
67  container_type( a_orig ),
68  f_unparsed( a_orig.f_unparsed )
69  {}
70 
72  container_type( a_orig ),
73  f_unparsed( std::move( a_orig.f_unparsed ) )
74  {}
75 
77  {
78  }
79 
80  const specifier& specifier::operator=( const specifier& a_orig )
81  {
82  container_type::operator=( a_orig );
83  f_unparsed = a_orig.f_unparsed;
84  return *this;
85  }
86 
88  {
89  container_type::operator=( a_orig );
90  f_unparsed = std::move(a_orig.f_unparsed);
91  return *this;
92  }
93 
94  void specifier::parse( const std::string& a_unparsed )
95  {
96  LTRACE( dlog, "Parsing <" << a_unparsed << ">" );
97 
98  while( ! empty() ) pop_front();
99 
100  f_unparsed = a_unparsed;
101 
102  if( a_unparsed.empty() ) return;
103 
104  add_next( a_unparsed );
105  return;
106  }
107 
108  std::string specifier::to_string() const
109  {
110  std::string t_return;
111  for( container_type::const_iterator t_it = this->begin(); t_it != this->end(); ++t_it )
112  {
113  if( t_it != this->begin() ) t_return += f_node_separator;
114  t_return += *t_it;
115  }
116  return t_return;
117  }
118 
119  void specifier::add_next( const std::string& a_addr )
120  {
121  size_t t_div_pos = a_addr.find( f_node_separator );
122  if( t_div_pos == a_addr.npos )
123  {
124  push_back( a_addr );
125  return;
126  }
127  push_back( a_addr.substr( 0, t_div_pos ) );
128  add_next( a_addr.substr( t_div_pos + 1 ) );
129  return;
130  }
131 
132 
133 } /* namespace dripline */
void parse(const std::string &a_rk)
Parses a routing key.
Definition: specifier.cc:25
std::string to_string() const
Converts the routing-key tokens into a single string.
Definition: specifier.cc:33
void add_next(const std::string &a_addr)
Definition: specifier.cc:44
static const char f_node_separator
Definition: specifier.hh:50
routing_key(const std::string &a_rk="")
Definition: specifier.cc:19
Parses specifiers and stores the tokenized information.
Definition: specifier.hh:61
specifier(const std::string &a_unparsed="")
Definition: specifier.cc:58
virtual ~specifier()
Definition: specifier.cc:76
std::deque< std::string > container_type
Definition: specifier.hh:63
const specifier & operator=(const specifier &a_orig)
Definition: specifier.cc:80
void parse(const std::string &a_unparsed)
Parse a new specifier.
Definition: specifier.cc:94
std::string to_string() const
Converts specifier tokens into a single string.
Definition: specifier.cc:108
void add_next(const std::string &a_addr)
Definition: specifier.cc:119
static const char f_node_separator
Definition: specifier.hh:88
static ::scarab::logger_type< ::scarab::spd_initializer_async_stdout_color_mt > dlog("agent", __FILE_NAME__, __LINE__)
static ::scarab::logger_type< ::scarab::spd_initializer_async_stdout_color_mt > dlog("specifier", __FILE_NAME__, __LINE__)