ATLAS Offline Software
TestClassSimpleContainers.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TESTCLASSSIMPLECONTAINERS_H
6 #define TESTCLASSSIMPLECONTAINERS_H
7 
8 #include <string>
9 #include <vector>
10 #include <list>
11 #include <map>
12 #include <set>
13 #include <deque>
14 #include <ostream>
15 
17 
18 public:
25  {}
26 
28 
29  void setNonZero();
30  bool operator==( const TestClassSimpleContainers& rhs ) const;
31  bool operator!=( const TestClassSimpleContainers& rhs ) const;
32  std::ostream& streamOut( std::ostream& os ) const;
33 
34  std::vector< int > m_vector_of_int;
35  std::list< double > m_list_of_double;
36  std::map< std::string, long > m_map_of_string_to_long;
37  std::set< unsigned short > m_set_of_ushort;
38  std::deque< float > m_deque_of_float;
39 };
40 
41 
42 inline void
44 {
45  m_vector_of_int.clear();
46  m_vector_of_int.push_back( 1 );
47  m_list_of_double.clear();
48  m_list_of_double.push_back( 2 );
49  m_list_of_double.push_back( 3 );
51  m_map_of_string_to_long.insert( std::make_pair( std::string( "key1" ), 4L ) );
52  m_map_of_string_to_long.insert( std::make_pair( std::string( "key2" ), 5L ) );
53  m_set_of_ushort.clear();
54  m_set_of_ushort.insert( 6 );
55  m_set_of_ushort.insert( 7 );
56  m_set_of_ushort.insert( 8 );
57  m_deque_of_float.clear();
58  m_deque_of_float.push_back( 9 );
59  m_deque_of_float.push_front( 10 );
60 }
61 
62 inline std::ostream&
64 {
65  os << "m_vector_of_int( " << m_vector_of_int.size() << " ) :";
66  for ( std::vector< int >::const_iterator i = m_vector_of_int.begin();
67  i != m_vector_of_int.end(); ++i ) {
68  os << " " << *i;
69  }
70  os << std::endl;
71  os << "m_list_of_double( " << m_list_of_double.size() << " ) :";
72  for ( std::list< double >::const_iterator i = m_list_of_double.begin();
73  i != m_list_of_double.end(); ++i ) {
74  os << " " << *i;
75  }
76  os << std::endl;
77  os << "m_map_of_string_to_long( " << m_map_of_string_to_long.size() << " ) :";
78  for ( std::map< std::string, long >::const_iterator i = m_map_of_string_to_long.begin();
79  i != m_map_of_string_to_long.end(); ++i ) {
80  os << " (" << i->first << "," << i->second << ")";
81  }
82  os << std::endl;
83  os << "m_set_of_ushort( " << m_set_of_ushort.size() << " ) :";
84  for ( std::set< unsigned short >::const_iterator i = m_set_of_ushort.begin();
85  i != m_set_of_ushort.end(); ++i ) {
86  os << " " << *i;
87  }
88 
89  os << std::endl;
90  os << "m_deque_of_float( " << m_deque_of_float.size() << " ) :";
91  for ( std::deque< float >::const_iterator i = m_deque_of_float.begin();
92  i != m_deque_of_float.end(); ++i ) {
93  os << " " << *i;
94  }
95 
96  return os;
97 }
98 
99 inline bool
101 {
102  // Check first the sizes of the containers
103  if ( m_vector_of_int.size() != rhs.m_vector_of_int.size() ) return false;
104  if ( m_list_of_double.size() != rhs.m_list_of_double.size() ) return false;
105  if ( m_map_of_string_to_long.size() != rhs.m_map_of_string_to_long.size() ) return false;
106  if ( m_set_of_ushort.size() != rhs.m_set_of_ushort.size() ) return false;/*
107  if ( m_deque_of_float.size() != rhs.m_deque_of_float.size() ) return false;*/
108 
109  // Check element by element.
110  std::vector< int >::const_iterator this_i_vector_of_int = m_vector_of_int.begin();
111  std::vector< int >::const_iterator rhs_i_vector_of_int = rhs.m_vector_of_int.begin();
112  while ( this_i_vector_of_int != m_vector_of_int.end() ) {
113  if ( *this_i_vector_of_int != *rhs_i_vector_of_int ) return false;
114  ++this_i_vector_of_int;
115  ++rhs_i_vector_of_int;
116  }
117 
118  std::list< double >::const_iterator this_i_list_of_double = m_list_of_double.begin();
119  std::list< double >::const_iterator rhs_i_list_of_double = rhs.m_list_of_double.begin();
120  while ( this_i_list_of_double != m_list_of_double.end() ) {
121  if ( *this_i_list_of_double != *rhs_i_list_of_double ) return false;
122  ++this_i_list_of_double;
123  ++rhs_i_list_of_double;
124  }
125 
126  std::map< std::string, long >::const_iterator this_i_map_of_string_to_long = m_map_of_string_to_long.begin();
127  std::map< std::string, long >::const_iterator rhs_i_map_of_string_to_long = rhs.m_map_of_string_to_long.begin();
128  while ( this_i_map_of_string_to_long != m_map_of_string_to_long.end() ) {
129  if ( this_i_map_of_string_to_long->first != rhs_i_map_of_string_to_long->first ||
130  this_i_map_of_string_to_long->second != rhs_i_map_of_string_to_long->second ) return false;
131  ++this_i_map_of_string_to_long;
132  ++rhs_i_map_of_string_to_long;
133  }
134 
135  std::set< unsigned short >::const_iterator this_i_set_of_ushort = m_set_of_ushort.begin();
136  std::set< unsigned short >::const_iterator rhs_i_set_of_ushort = rhs.m_set_of_ushort.begin();
137  while ( this_i_set_of_ushort != m_set_of_ushort.end() ) {
138  if ( *this_i_set_of_ushort != *rhs_i_set_of_ushort ) return false;
139  ++this_i_set_of_ushort;
140  ++rhs_i_set_of_ushort;
141  }
142 
143  std::deque< float >::const_iterator this_i_deque_of_float = m_deque_of_float.begin();
144  std::deque< float >::const_iterator rhs_i_deque_of_float = rhs.m_deque_of_float.begin();
145  while ( this_i_deque_of_float != m_deque_of_float.end() ) {
146  if ( *this_i_deque_of_float != *rhs_i_deque_of_float ) return false;
147  ++this_i_deque_of_float;
148  ++rhs_i_deque_of_float;
149  }
150 
151  return true;
152 }
153 
154 inline bool
156 {
157  return ( ( (*this) == rhs ) ? false : true );
158 }
159 
160 
161 #endif
TestClassSimpleContainers::operator!=
bool operator!=(const TestClassSimpleContainers &rhs) const
Definition: TestClassSimpleContainers.h:155
TestClassSimpleContainers::streamOut
std::ostream & streamOut(std::ostream &os) const
Definition: TestClassSimpleContainers.h:63
TestClassSimpleContainers::setNonZero
void setNonZero()
Definition: TestClassSimpleContainers.h:43
TestClassSimpleContainers::m_set_of_ushort
std::set< unsigned short > m_set_of_ushort
Definition: TestClassSimpleContainers.h:37
TestClassSimpleContainers::m_list_of_double
std::list< double > m_list_of_double
Definition: TestClassSimpleContainers.h:35
lumiFormat.i
int i
Definition: lumiFormat.py:85
TestClassSimpleContainers::~TestClassSimpleContainers
~TestClassSimpleContainers()
Definition: TestClassSimpleContainers.h:27
TestClassSimpleContainers::m_vector_of_int
std::vector< int > m_vector_of_int
Definition: TestClassSimpleContainers.h:34
TestClassSimpleContainers::operator==
bool operator==(const TestClassSimpleContainers &rhs) const
Definition: TestClassSimpleContainers.h:100
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
TestClassSimpleContainers::TestClassSimpleContainers
TestClassSimpleContainers()
Definition: TestClassSimpleContainers.h:19
TestClassSimpleContainers::m_map_of_string_to_long
std::map< std::string, long > m_map_of_string_to_long
Definition: TestClassSimpleContainers.h:36
TestClassSimpleContainers::m_deque_of_float
std::deque< float > m_deque_of_float
Definition: TestClassSimpleContainers.h:38
TestClassSimpleContainers
Definition: TestClassSimpleContainers.h:16