Jean-Marc Lasgouttes wrote: > Note that implementing this `latexostream' can begin with any one of > the features enumerated above, since they do not depend on each other. > Basically, the big work is to write the class (probably easy, but I do > not know ostream interface well enough to know which method(s) should > be reimplemented) and change all of our latex() methods to take a > latexostream as argument instead of std::ostream. > > After this is done, the changes can be done gradually. > > Do this look like a plan? Now, we only have to find someone to > implement it :)
It looks like a good plan indeed. It looks to me like you're describing formatting flags (iomanip thingies) rather than member functions as they affect only the next piece of input rather than everything thereafter. #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::ios; using std::setw; int main() { // A formatting flag. Affects only '10'. cout << "'" << setw(10) << 10 << "' '" << 20 << '\'' << endl; // Member functions. Affect everything thereafter. cout.setf(ios::fixed); cout.precision(3); cout << 3.0 << " " << 3.01 << " " << 3.001 << '\n' << 3.0004 << " " << 3.0005 << " " << 3.0006 << endl; return 0; } Outputs: ' 10' '20' 3.000 3.010 3.001 3.000 3.001 3.001 They are actually dead easy to implement. Below is the g++ implementation of 'setw' struct _Setw { int _M_n; }; /** * @brief Manipulator for @c width. * @param n The new width. * * Sent to a stream object, this manipulator calls @c width(n) for * that object. */ inline _Setw setw(int __n) { _Setw __x; __x._M_n = __n; return __x; } template<typename _CharT, typename _Traits> inline basic_ostream<_CharT,_Traits>& operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f) { __os.width(__f._M_n); return __os; } The next operation after 'setw' (operator<<(cout, 10), above) interrogates cout.width() and then resets it to 0 before returning. However, I don't think that we need to define a new olatexstream with member functions unwantedligature() etc. That would be difficult because sometimes we'd want olatexstream to derive from ofstream, sometimes from ostringstream, etc. For the way forward, see http://www.awprofessional.com/articles/article.asp?p=171014&seqNum=2 for how to define new manipulators for existing streams. Specifically: <quote> User-defined manipulators often require the use of user-defined format flags; the stream classes have a storage area for such flags. This storage is dynamically allocated for the stream classes. This storage area is accessed by the iword(), pword(), and xalloc() functions: * The xalloc() function returns an index to the next unused flag. The flag is represented by a long. Each time xalloc() is called, a new index is returned. * The iword() and pword() methods are used to set the value or query the value of the flag. </quote> HTH, Angus