]> git.tdb.fi Git - libs/core.git/commitdiff
Throw from LexicalConverter::get if no conversion was performed
authorMikko Rasa <tdb@tdb.fi>
Sat, 1 Dec 2012 20:57:35 +0000 (22:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 1 Dec 2012 20:57:35 +0000 (22:57 +0200)
source/strings/lexicalcast.cpp
source/strings/lexicalcast.h

index ab83b110b432ba408f8bdfa3bd2fb53d3e848c8f..f4b58302fe154447753f399bf81e80d86ce091cd 100644 (file)
@@ -471,6 +471,7 @@ namespace Msp {
 
 void LexicalConverter::result(const string &s)
 {
+       filled = true;
        if(s.size()<fmt.get_width())
        {
                if(fmt.get_align()==Fmt::RIGHT)
@@ -482,6 +483,13 @@ void LexicalConverter::result(const string &s)
                buf = s;
 }
 
+const string &LexicalConverter::get() const
+{
+       if(!filled)
+               throw lexical_error("conversion not performed");
+       return buf;
+}
+
 
 /*** operator<< ***/
 
index 80963f44dd3a233ff2d16b01ec007935d01e73c9..25e3268126bde5d65cf19dca35d188c96dcebb5e 100644 (file)
@@ -35,14 +35,15 @@ class LexicalConverter
 {
 private:
        Fmt fmt;
+       bool filled;
        std::string buf;
 
 public:
-       LexicalConverter(const Fmt &f): fmt(f) { }
-       LexicalConverter(const std::string &s, const Fmt &f): fmt(f), buf(s) { }
+       LexicalConverter(const Fmt &f): fmt(f), filled(false) { }
+       LexicalConverter(const std::string &s, const Fmt &f): fmt(f), filled(true), buf(s) { }
 
        const Fmt &get_fmt() const { return fmt; }
-       const std::string &get() const { return buf; }
+       const std::string &get() const;
        void result(const std::string &);
 };