glob2-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [glob2-devel] Refactoring


From: Stéphane Magnenat
Subject: Re: [glob2-devel] Refactoring
Date: Mon, 1 May 2006 21:19:35 +0200
User-agent: KMail/1.9.1

Hi everyone,

I'm very happy you're discussed my thoughts ;-)

I suggested to use boost as I thought it was already used elsewhere. Now if 
it's not the case then we can use another way.
The key requierment is that we want to be able to use ("toto %something 
%somethingelse" arg1 arg2)ish syntax but with clean C++.

Now, one solution is to use boost::format

Another one would be to implement a Qt4-like arg in a subclass of std::string. 
Here is my suggestion:

class FormatableString : public std::string
{
        // level of argument, used for nested .arg()
        int argLevel;

        FormatableString(const std::string &s) :
                std::string(s),
                argLevel(0)
        {

        }       

        template <typename T>
        const FormatableString &arg(const T& value)
        {
                // transform value into std::string
                std::ostringstream oss;
                oss << value;

                // from here is pseudo code
                
                // find %argLevel in *this
                // if found,
                        // replace %argLevel by oss.str(), which is value 
transformed into string

                // end of pseuccode 

                // increment argLevel
                argLevel++,

                // return reference to this so that .arg can proceed further
                return *this;
        }
};

Opinions welcome

Steph




reply via email to

[Prev in Thread] Current Thread [Next in Thread]