Scarab  v2.2.3
Project 8 C++ Utility Library
param_array.cc
Go to the documentation of this file.
1 /*
2  * param_array.cc
3  *
4  * Created on: Jan 14, 2014
5  * Author: nsoblath
6  */
7 
8 #define SCARAB_API_EXPORTS
9 
10 #include <sstream>
11 using std::string;
12 using std::stringstream;
13 
14 #include "param_array.hh"
15 
16 #include "param_base_impl.hh"
17 
18 
19 namespace scarab
20 {
21 
23  param(),
24  f_contents()
25  {
26  }
27 
29  param( orig ),
30  f_contents( orig.f_contents.size() )
31  {
32  for( unsigned ind = 0; ind < f_contents.size(); ++ind )
33  {
34  f_contents[ind] = orig.f_contents[ ind ]->clone();
35  }
36  }
37 
39  param( std::move(orig) ),
40  f_contents( orig.f_contents.size() )
41  {
42  for( unsigned ind = 0; ind < f_contents.size(); ++ind )
43  {
44  f_contents[ind] = orig.f_contents[ ind ]->move_clone();
45  }
46  orig.clear();
47  }
48 
50  {
51  }
52 
54  {
55  this->param::operator=( rhs );
56  clear();
57  resize( rhs.size()) ;
58  for( unsigned ind = 0; ind < rhs.f_contents.size(); ++ind )
59  {
60  f_contents[ind] = rhs.f_contents[ ind ]->clone();
61  }
62  return *this;
63  }
64 
66  {
67  this->param::operator=( std::move(rhs) );
68  clear();
69  resize( rhs.size()) ;
70  for( unsigned ind = 0; ind < rhs.f_contents.size(); ++ind )
71  {
72  f_contents[ind] = rhs.f_contents[ ind ]->move_clone();
73  }
74  rhs.clear();
75  return *this;
76  }
77 
78  bool param_array::has_subset( const param& a_subset ) const
79  {
80  if( ! a_subset.is_array() ) return false;
81  const param_array& t_subset_array = a_subset.as_array();
82  if( t_subset_array.size() > f_contents.size() ) return false;
83  contents::const_iterator t_this_it = f_contents.begin();
84  contents::const_iterator t_that_it = t_subset_array.f_contents.begin();
85  while( t_that_it != t_subset_array.f_contents.end() ) // loop condition is on a_subset because it's smaller or equal to this
86  {
87  if( ! (*t_this_it)->has_subset( **t_that_it ) ) return false;
88  ++t_this_it;
89  ++t_that_it;
90  }
91  return true;
92  }
93 
94  std::string param_array::to_string() const
95  {
96  stringstream out;
97  string indentation;
98  for ( unsigned i=0; i<param::s_indent_level; ++i )
99  indentation += " ";
100  out << '\n' << indentation << "[\n";
101  param::s_indent_level++;
102  for( contents::const_iterator it = f_contents.begin(); it != f_contents.end(); ++it )
103  {
104  out << indentation << " " << **it << '\n';
105  }
106  param::s_indent_level--;
107  out << indentation << "]\n";
108  return out.str();
109  }
110 
111 
112  SCARAB_API std::ostream& operator<<(std::ostream& out, const param_array& a_value)
113  {
114  return out << a_value.to_string();
115  }
116 
117 } /* namespace scarab */
param & operator=(const param &rhs)
virtual bool has_subset(const param &a_subset) const
Definition: param_array.cc:78
param_array & operator=(const param_array &rhs)
Definition: param_array.cc:53
virtual std::string to_string() const
Definition: param_array.cc:94
virtual ~param_array()
Definition: param_array.cc:49
#define SCARAB_API
Definition: scarab_api.hh:24
STL namespace.
static unsigned s_indent_level
Definition: param_base.hh:98
unsigned size() const
Definition: param_array.hh:160
SCARAB_API std::ostream & operator<<(std::ostream &out, const param_array &a_value)
Definition: param_array.cc:112
param_array & as_array()
virtual bool is_array() const
void resize(unsigned a_size)
Definition: param_array.hh:169