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

StringList.h

Go to the documentation of this file.
00001 #ifndef Impala_Basis_StringList_h
00002 #define Impala_Basis_StringList_h
00003 
00004 #include <list>
00005 #include <vector>
00006 #include "Basis/String.h"
00007 
00008 namespace Impala
00009 {
00010 
00011 
00015 class StringList : public std::list<String>
00016 {
00017 public:
00018 
00019     StringList()
00020     {
00021     }
00022 
00023     StringList(const String& s)
00024     {
00025         push_back(s);
00026     }
00027 
00028     StringList(const String& s, char separator, bool includeEmptyStrings = false)
00029     {
00030         String element = "";
00031         for (String::const_iterator p = s.begin() ; p != s.end() ; p++)
00032         {
00033             if (*p == separator)
00034             {
00035                 if (!element.empty() || includeEmptyStrings)
00036                 {
00037                     push_back(element);
00038                     element = "";
00039                 }
00040             }
00041             else
00042             {
00043                 element += *p;
00044             }
00045         }
00046         if (!element.empty())
00047             push_back(element);
00048         if (size() == 0) // in case the empty string is passed
00049             push_back("");
00050     }
00051 
00052     StringList(const std::list<String>& l)
00053     {
00054         std::copy(l.begin(), l.end(), std::back_inserter(*this));
00055     }
00056 
00057     StringList(const std::vector<String>& v)
00058     {
00059         std::copy(v.begin(), v.end(), std::back_inserter(*this));
00060     }
00061 
00063     typedef std::back_insert_iterator<StringList>  back_insert_iterator;
00064 
00066     StringList&
00067     operator<<(const String& s)
00068     {
00069         push_back(s);
00070         return *this;
00071     }
00072 
00074     void
00075     EraseAll()
00076     {
00077         erase(begin(), end());
00078     }
00079 
00080     String
00081     ToString(char separator = ' ')
00082     {
00083         String result;
00084         for (StringList::const_iterator i=begin() ; i!=end() ; i++)
00085         {
00086             if (i != begin())
00087                 result += separator;
00088             result += *i;
00089         }
00090         return result;
00091     }
00092 
00093 };
00094 
00096 typedef StringList::iterator              StringListI;
00097 
00099 typedef StringList::const_iterator        StringListCI;
00100 
00102 typedef StringList::back_insert_iterator  StringListBI;
00103 
00104 
00105 } // namespace Impala
00106 
00107 #endif

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