Scarab  v2.2.1
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 
17 namespace scarab
18 {
19 
21  param(),
22  f_contents()
23  {
24  }
25 
27  param( orig ),
28  f_contents( orig.f_contents.size() )
29  {
30  for( unsigned ind = 0; ind < f_contents.size(); ++ind )
31  {
32  f_contents[ind] = orig.f_contents[ ind ]->clone();
33  }
34  }
35 
37  param( std::move(orig) ),
38  f_contents( orig.f_contents.size() )
39  {
40  for( unsigned ind = 0; ind < f_contents.size(); ++ind )
41  {
42  f_contents[ind] = orig.f_contents[ ind ]->move_clone();
43  }
44  orig.clear();
45  }
46 
48  {
49  }
50 
52  {
53  this->param::operator=( rhs );
54  clear();
55  resize( rhs.size()) ;
56  for( unsigned ind = 0; ind < rhs.f_contents.size(); ++ind )
57  {
58  f_contents[ind] = rhs.f_contents[ ind ]->clone();
59  }
60  return *this;
61  }
62 
64  {
65  this->param::operator=( std::move(rhs) );
66  clear();
67  resize( rhs.size()) ;
68  for( unsigned ind = 0; ind < rhs.f_contents.size(); ++ind )
69  {
70  f_contents[ind] = rhs.f_contents[ ind ]->move_clone();
71  }
72  rhs.clear();
73  return *this;
74  }
75 
76  bool param_array::has_subset( const param& a_subset ) const
77  {
78  if( ! a_subset.is_array() ) return false;
79  const param_array& t_subset_array = a_subset.as_array();
80  if( t_subset_array.size() > f_contents.size() ) return false;
81  contents::const_iterator t_this_it = f_contents.begin();
82  contents::const_iterator t_that_it = t_subset_array.f_contents.begin();
83  while( t_that_it != t_subset_array.f_contents.end() ) // loop condition is on a_subset because it's smaller or equal to this
84  {
85  if( ! (*t_this_it)->has_subset( **t_that_it ) ) return false;
86  ++t_this_it;
87  ++t_that_it;
88  }
89  return true;
90  }
91 
92  std::string param_array::to_string() const
93  {
94  stringstream out;
95  string indentation;
96  for ( unsigned i=0; i<param::s_indent_level; ++i )
97  indentation += " ";
98  out << '\n' << indentation << "[\n";
99  param::s_indent_level++;
100  for( contents::const_iterator it = f_contents.begin(); it != f_contents.end(); ++it )
101  {
102  out << indentation << " " << **it << '\n';
103  }
104  param::s_indent_level--;
105  out << indentation << "]\n";
106  return out.str();
107  }
108 
109 
110  SCARAB_API std::ostream& operator<<(std::ostream& out, const param_array& a_value)
111  {
112  return out << a_value.to_string();
113  }
114 
115 } /* namespace scarab */
param & operator=(const param &rhs)
virtual bool has_subset(const param &a_subset) const
Definition: param_array.cc:76
param_array & operator=(const param_array &rhs)
Definition: param_array.cc:51
virtual std::string to_string() const
Definition: param_array.cc:92
virtual ~param_array()
Definition: param_array.cc:47
#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:157
SCARAB_API std::ostream & operator<<(std::ostream &out, const param_array &a_value)
Definition: param_array.cc:110
param_array & as_array()
virtual bool is_array() const
void resize(unsigned a_size)
Definition: param_array.hh:166