Source-highlight Library
/home/bettini/work/source-highlight/src-highlite/lib/srchilite/bufferedoutput.h
00001 //
00002 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004-2008
00003 //
00004 // Copyright: See COPYING file that comes with this distribution
00005 //
00006 
00007 #ifndef BUFFEREDOUTPUT_H_
00008 #define BUFFEREDOUTPUT_H_
00009 
00010 #include <ostream>
00011 #include <string>
00012 #include <set>
00013 
00014 namespace srchilite {
00015 
00017 typedef std::set<std::string> PostContents;
00018 
00028 class BufferedOutput {
00030     std::ostream &outputBuff;
00031 
00033     bool alwaysFlush;
00034 
00036     PostContents postLineContents;
00037 
00039     PostContents postDocContents;
00040 
00046     void writePostInfo(PostContents &post, const std::string &prefix = "");
00047 
00048 public:
00052     BufferedOutput(std::ostream &os);
00053     ~BufferedOutput();
00054 
00059     void setAlwaysFlush(bool a = true) {
00060         alwaysFlush = a;
00061     }
00062 
00067     void output(const std::string &s);
00068 
00073     void postLineInsert(const std::string &s);
00074 
00079     void postDocInsert(const std::string &s);
00080 
00086     template<typename T> void postLineInsertFrom(const T &s) {
00087         for (typename T::const_iterator it = s.begin(); it != s.end(); ++it)
00088             postLineInsert(*it);
00089     }
00090 
00096     template<typename T> void postDocInsertFrom(const T &s) {
00097         for (typename T::const_iterator it = s.begin(); it != s.end(); ++it)
00098             postDocInsert(*it);
00099     }
00100 
00105     void writePostLine(const std::string &prefix = "");
00106 
00111     void writePostDoc(const std::string &prefix = "");
00112 
00113 };
00114 
00115 }
00116 
00117 #endif /*BUFFEREDOUTPUT_H_*/