]> git.tdb.fi Git - libs/core.git/blobdiff - source/stringcodec/codec.h
Add move semantics to Variant
[libs/core.git] / source / stringcodec / codec.h
index e0e0a96de235f906cda8c875963f3a1f399acf5e..f53bae5ba1d8ee86de0d469629ff21daad4b57d1 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_STRINGCODEC_CODEC_H_
 
 #include <string>
+#include <msp/core/mspcore_api.h>
 #include "except.h"
 #include "ustring.h"
 
@@ -25,7 +26,7 @@ Unicode strings are represented as ustrings.  An std::string is considered to
 be an encoded sequence of bytes.  A codec is able to determine if an encoded
 string could be decoded with it.
 */
-class Codec
+class MSPCORE_API Codec
 {
 public:
        /**
@@ -36,14 +37,14 @@ public:
        may find it useful or necessary to implement some other functions too
        (particularly sync and reset for stateful codecs).
        */
-       class Encoder
+       class MSPCORE_API Encoder
        {
        protected:
-               ErrorMode err_mode;
+               ErrorMode err_mode = THROW_ON_ERROR;
 
-               Encoder(ErrorMode em): err_mode(em) { }
+               Encoder(ErrorMode em): err_mode(em==DEFAULT ? THROW_ON_ERROR : em) { }
        public:
-               virtual ~Encoder() { }
+               virtual ~Encoder() = default;
 
                /** Encodes a single unicode character.  If the character can't be
                represented in this encoding, error() should be called. */
@@ -87,14 +88,14 @@ public:
 
        Each codec class should contain an Decoder class derived from this.
        */
-       class Decoder
+       class MSPCORE_API Decoder
        {
        protected:
-               ErrorMode err_mode;
+               ErrorMode err_mode = THROW_ON_ERROR;
 
-               Decoder(ErrorMode em): err_mode(em) { }
+               Decoder(ErrorMode em): err_mode(em==DEFAULT ? THROW_ON_ERROR : em) { }
        public:
-               virtual ~Decoder() { }
+               virtual ~Decoder() = default;
 
                /** Decodes a single character from a string.  The iterator is advanced
                to the next character.  For stateful codecs, -1 may be returned if a
@@ -131,9 +132,9 @@ public:
        };
 
 protected:
-       Codec() { }
+       Codec() = default;
 public:
-       virtual ~Codec() { }
+       virtual ~Codec() = default;
 
        /** Returns the name of the encoding handled by this codec. */
        virtual const char *get_name() const = 0;
@@ -162,17 +163,20 @@ template<typename C>
 class StandardCodec: public Codec
 {
 private:
-       ErrorMode err_mode;
+       ErrorMode err_mode = THROW_ON_ERROR;
 
 protected:
        StandardCodec(ErrorMode em): err_mode(em==DEFAULT ? THROW_ON_ERROR : em) { }
 
+       ErrorMode get_error_mode(ErrorMode em = DEFAULT) const
+       { return (em==DEFAULT ? err_mode : em); }
+
 public:
-       virtual Encoder *create_encoder(ErrorMode em = DEFAULT) const
-       { return new typename C::Encoder(em==DEFAULT ? err_mode : em); }
+       Encoder *create_encoder(ErrorMode em = DEFAULT) const override
+       { return new typename C::Encoder(get_error_mode(em)); }
 
-       virtual Decoder *create_decoder(ErrorMode em = DEFAULT) const
-       { return new typename C::Decoder(em==DEFAULT ? err_mode : em); }
+       Decoder *create_decoder(ErrorMode em = DEFAULT) const override
+       { return new typename C::Decoder(get_error_mode(em)); }
 };
 
 
@@ -201,11 +205,11 @@ std::string transcode(const std::string &s)
 
 /** Creates a codec for an encoding by name.  The caller is responsible for
 deleting the codec when it's no longer needed. */
-Codec *create_codec(const std::string &);
+MSPCORE_API Codec *create_codec(const std::string &);
 
 /** Automatically detects the encoding of a string and creates a codec for it.
 The codec must be deleted when it's no longer needed. */
-Codec *detect_codec(const std::string &);
+MSPCORE_API Codec *detect_codec(const std::string &);
 
 } // namespace StringCodec
 } // namespace Msp