Andre Poenitz wrote:
>> Is this just a wild flight of fancy, or does anybody else think
>> that it's a sensible proposal?
> 
> I think this could be handled on a case-by-case base by using some
> helper functions in the insets that really need it.

Actually, I did some reading and I think I have stumbled across 
something very powerful.

The C++ streams allow us to define arbitrary new modifiers --- and 
enable subsequent operations on the stream to be aware of them. For 
example, the code below would be used
        std::ostringstream os;
        os << font::setFamily(font::SERIF) << "André "
           << font::setFamily(font::SANS_SERIF) << "Pönitz\n";

Note that it works on existing stream types!!! Thereafter one would 
need to write a 'decipherer'. For example, something to establish the 
width of the string in this font, or to paint it, but the beauty is 
that this 'mark-up' is entirely separate.

Don't you think that that is beautiful? A built-in stack of string 
modifiers. I can imagine latex output, html output etc, etc, just by 
parsing a stringstream.

namespace font {

enum Family {
        SERIF,
        SANS_SERIF,
        TYPEWRITER
};

class setFamily {
public:
        static int getAlloc() { return xalloc_id_; }

        explicit setFamily(Family family) : family_(family) {}
        friend std::ostream & operator<<(std::ostream &, setFamily const &);
private:
        Family family_;
        static int const xalloc_id_;
};

int const setFamily::xalloc_id_ = std::ios_base::xalloc();

std::ostream & operator<<(std::ostream & os, setFamily const & sf)
{
        os.iword(CName::GetAlloc()) = sf.family_;
        return os;
}

} // namespace font


-- 
Angus

Reply via email to