vil_nitf2_index_vector.h
Go to the documentation of this file.
1 // vil_nitf2: Written by Harry Voorhees (hlv@) and Rob Radtke (rob@) of
2 // Stellar Science Ltd. Co. (stellarscience.com) for
3 // Air Force Research Laboratory, 2005.
4 
5 #ifndef VIL_NITF2_INDEX_VECTOR_H
6 #define VIL_NITF2_INDEX_VECTOR_H
7 
8 #include <ostream>
9 #include <vector>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 
14 // A wrapper for a vector of ints that represents an index into
15 // a repeating field. This class serves two simple purposes: it
16 // provides some convenient constructors from scalars (remember the
17 // lisp function "list"?), and it defines operator<< (std::ostream&).
18 
19 class vil_nitf2_index_vector : public std::vector<int>
20 {
21  public:
22  // Convenience constructors: empty vector, 1 element, etc.
23  vil_nitf2_index_vector() : std::vector<int>() {}
24  vil_nitf2_index_vector(int i): std::vector<int>(1) {
25  (*this)[0] = i; }
26  vil_nitf2_index_vector(int i, int j) : std::vector<int>(2) {
27  (*this)[0] = i; (*this)[1] = j; }
28  vil_nitf2_index_vector(int i, int j, int k) : std::vector<int>(3) {
29  (*this)[0] = i; (*this)[1] = j; (*this)[2] = k; }
30  vil_nitf2_index_vector(int i, int j, int k, int l) : std::vector<int>(4) {
31  (*this)[0] = i; (*this)[1] = j; (*this)[2] = k; (*this)[3] = l; }
32 
33  // General-purpose constructor
34  vil_nitf2_index_vector(const std::vector<int>& v) : std::vector<int>(v) {}
35 
36  // Destructor
37  virtual ~vil_nitf2_index_vector() = default;
38 };
39 
40 inline std::ostream& operator << (std::ostream& os, const vil_nitf2_index_vector& vec)
41 {
42  os << '(';
43  for (vil_nitf2_index_vector::const_iterator it = vec.begin(); it != vec.end(); ++it) {
44  if (it != vec.begin()) os << ", ";
45  os << *it;
46  }
47  os << ')';
48  return os;
49 }
50 
51 #endif // VIL_NITF2_INDEX_VECTOR_H
vil_nitf2_index_vector(int i, int j, int k)
vil_nitf2_index_vector(int i, int j, int k, int l)
std::ostream & operator<<(std::ostream &os, const vil_nitf2_index_vector &vec)
#define v
virtual ~vil_nitf2_index_vector()=default
vil_nitf2_index_vector(const std::vector< int > &v)