Source-highlight Library
/home/bettini/work/source-highlight/src-highlite/lib/srchilite/tostringcollection.h
00001 //
00002 // Description: given a collection generates a string representation
00003 //
00004 //
00005 // Author: Lorenzo Bettini, 1999-2007 <http://www.lorenzobettini.it>
00006 //
00007 // Copyright: See COPYING file that comes with this distribution
00008 //
00009 //
00010 
00011 #ifndef TOSTRINGCOLLECTION_H
00012 #define TOSTRINGCOLLECTION_H
00013 
00014 #include <string>
00015 #include <sstream>
00016 
00017 namespace srchilite {
00018 
00026 template <class T>
00027 const std::string toStringCollection(const T *collection, char sep = ' ')
00028 {
00029   std::ostringstream buf;
00030 
00031   for (typename T::const_iterator it = collection->begin();
00032        it != collection->end(); )
00033   {
00034     buf << (*it)->toString();
00035     if (++it != collection->end())
00036       buf << sep;
00037   }
00038 
00039   return buf.str();
00040 }
00041 
00049 template <class T>
00050 const std::string toStringCollection(const T &collection, char sep = ' ')
00051 {
00052   std::ostringstream buf;
00053 
00054   for (typename T::const_iterator it = collection.begin();
00055        it != collection.end(); )
00056   {
00057     buf << (*it);
00058     if (++it != collection.end())
00059       buf << sep;
00060   }
00061 
00062   return buf.str();
00063 }
00064 
00072 template <class T>
00073 const std::string toStringOriginalCollection(const T *collection, char sep = ' ')
00074 {
00075   std::ostringstream buf;
00076 
00077   for (typename T::const_iterator it = collection->begin();
00078        it != collection->end(); )
00079   {
00080     buf << (*it)->toStringOriginal();
00081     if (++it != collection->end())
00082       buf << sep;
00083   }
00084 
00085   return buf.str();
00086 }
00087 
00095 template <class T>
00096 const std::string collectionToString(const T *collection, char sep = ' ')
00097 {
00098   std::ostringstream buf;
00099 
00100   for (typename T::const_iterator it = collection->begin();
00101        it != collection->end(); )
00102   {
00103     buf << (*it);
00104     if (++it != collection->end() && sep)
00105       buf << sep;
00106   }
00107 
00108   return buf.str();
00109 }
00110 
00118 template <class T>
00119 const std::string collectionRefToString(const T &collection, char sep = ' ')
00120 {
00121   std::ostringstream buf;
00122 
00123   for (typename T::const_iterator it = collection.begin();
00124        it != collection.end(); )
00125   {
00126     buf << (*it);
00127     if (++it != collection.end() && sep)
00128       buf << sep;
00129   }
00130 
00131   return buf.str();
00132 }
00133 
00134 }
00135 
00136 #endif // TOSTRINGCOLLECTION_H