core/vil/file_formats/vil_nitf2_index_vector.h
Go to the documentation of this file.
00001 // vil_nitf2: Written by Harry Voorhees (hlv@) and Rob Radtke (rob@) of
00002 // Stellar Science Ltd. Co. (stellarscience.com) for
00003 // Air Force Research Laboratory, 2005.
00004 
00005 #ifndef VIL_NITF2_INDEX_VECTOR_H
00006 #define VIL_NITF2_INDEX_VECTOR_H
00007 
00008 #include <vcl_ostream.h>
00009 #include <vcl_vector.h>
00010 
00011 // A wrapper for a vector of ints that represents an index into
00012 // a repeating field. This class serves two simple purposes: it
00013 // provides some convenient constructors from scalars (remember the
00014 // lisp function "list"?), and it defines operator<< (vcl_ostream&).
00015 
00016 class vil_nitf2_index_vector : public vcl_vector<int>
00017 {
00018  public:
00019   // Convenience constructors: empty vector, 1 element, etc.
00020   vil_nitf2_index_vector() : vcl_vector<int>() {}
00021   vil_nitf2_index_vector(int i): vcl_vector<int>(1) {
00022     (*this)[0] = i; }
00023   vil_nitf2_index_vector(int i, int j) : vcl_vector<int>(2) {
00024     (*this)[0] = i; (*this)[1] = j; }
00025   vil_nitf2_index_vector(int i, int j, int k) : vcl_vector<int>(3) {
00026     (*this)[0] = i; (*this)[1] = j; (*this)[2] = k; }
00027   vil_nitf2_index_vector(int i, int j, int k, int l) : vcl_vector<int>(4) {
00028     (*this)[0] = i; (*this)[1] = j; (*this)[2] = k; (*this)[3] = l; }
00029 
00030   // General-purpose constructor
00031   vil_nitf2_index_vector(const vcl_vector<int>& v) : vcl_vector<int>(v) {}
00032 
00033   // Destructor
00034   virtual ~vil_nitf2_index_vector() {}
00035 };
00036 
00037 inline vcl_ostream& operator << (vcl_ostream& os, const vil_nitf2_index_vector& vec)
00038 {
00039   os << '(';
00040   for (vil_nitf2_index_vector::const_iterator it = vec.begin(); it != vec.end(); ++it) {
00041     if (it != vec.begin()) os << ", ";
00042     os << *it;
00043   }
00044   os << ')';
00045   return os;
00046 }
00047 
00048 #endif // VIL_NITF2_INDEX_VECTOR_H