Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

ArraySet.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Array_ArraySet_h
00002 #define Impala_Core_Array_ArraySet_h
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <iostream>
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 
00015 
00016 // basically a wrapper around std::vector of arrays
00017 // provides access to arrays based on names
00018 template<class ArrayT>
00019 class ArraySet
00020 {
00021 public:
00022 
00023     ArraySet()
00024     {
00025     }
00026 
00027     ArraySet(int nrArray)
00028     {
00029         for (int i=0 ; i<nrArray ; i++)
00030         {
00031             mArrays.push_back(0);
00032             mNames.push_back(std::string(""));
00033         }
00034     }
00035 
00036     ~ArraySet()
00037     {
00038         // no destruction of elements, as std::vector doesn't do it either
00039         //for (int i=0 ; i<mArrays.size() ; i++)
00040         //    delete mArrays[i];
00041     }
00042 
00043     void
00044     Delete() // requires "explicit call to destructor"
00045     {
00046         for (int i=0 ; i<mArrays.size() ; i++)
00047             delete mArrays[i];
00048         mArrays.clear();
00049         mNames.clear();
00050     }
00051 
00052     int
00053     Size()
00054     {
00055         return mNames.size();
00056     }
00057 
00058     std::string
00059     Name(int i)
00060     {
00061         return mNames[i];
00062     }
00063 
00064     ArrayT*&
00065     Array(int i)
00066     {
00067         return mArrays[i];
00068     }
00069 
00070     // return array with given name, allocate a new (empty) one otherwise
00071     ArrayT*&
00072     Array(std::string name)
00073     {
00074         for (int i=0 ; i<mNames.size() ; i++)
00075             if (mNames[i] == name)
00076                 return mArrays[i];
00077         return AllocName(name);
00078     }
00079 
00080     std::vector<ArrayT*>
00081     GetArrays()
00082     {
00083         return mArrays;
00084     }
00085 
00086 private:
00087 
00088     ArrayT*&
00089     AllocName(std::string name)
00090     {
00091         mNames.push_back(name);
00092         mArrays.push_back(0);
00093         return mArrays[mArrays.size()-1];
00094     }
00095 
00096     std::vector<ArrayT*>     mArrays;
00097     std::vector<std::string> mNames;
00098 
00099 };
00100 
00101 } // namespace Array
00102 } // namespace Core
00103 } // namespace Impala
00104 
00105 #endif

Generated on Fri Mar 19 09:30:43 2010 for ImpalaSrc by  doxygen 1.5.1