]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/lexicalcast.h
Comment changes
[libs/core.git] / source / strings / lexicalcast.h
index 80963f44dd3a233ff2d16b01ec007935d01e73c9..2ed0621291858c0d0f4d40fb37036fd5decc5700 100644 (file)
@@ -10,7 +10,7 @@
 namespace Msp {
 
 /**
-Thrown for errors in lexical conversions
+Thrown for errors in lexical conversions.
 */
 class lexical_error: public std::runtime_error
 {
@@ -20,6 +20,9 @@ public:
 };
 
 
+/**
+Thrown when the format is unsuitable for the type being converted.
+*/
 class format_mismatch: public lexical_error
 {
 public:
@@ -35,14 +38,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 &);
 };
 
@@ -140,8 +144,9 @@ operator>>(const LexicalConverter &c, T &v)
                throw lexical_error("conversion failure");
 }
 
-// Helper struct to provide partial template specialization
-
+/**
+Helper struct to provide partial template specialization.
+*/
 template<typename T, typename F>
 struct LexicalCast;
 
@@ -179,8 +184,10 @@ struct LexicalCast<std::string, std::string>
        }
 };
 
-// The main interface to the lexical conversion machinery
-
+/** Perform a lexical conversion between a string and another type.  The source
+type can normally be deduced by the compiler, so this can be used just like the
+standard C++ casts.  A format may additionally be specified to force a specific
+interpretation. */
 template<typename T, typename F>
 inline T lexical_cast(const F &v, const Fmt &f = Fmt())
 {