diff options
Diffstat (limited to 'src/mongo/s/bson_serializable.h')
-rw-r--r-- | src/mongo/s/bson_serializable.h | 113 |
1 files changed, 53 insertions, 60 deletions
diff --git a/src/mongo/s/bson_serializable.h b/src/mongo/s/bson_serializable.h index e957701df1c..a1d0695ee5c 100644 --- a/src/mongo/s/bson_serializable.h +++ b/src/mongo/s/bson_serializable.h @@ -34,81 +34,74 @@ namespace mongo { +/** + * "Types" are the interface to a known data structure that will be serialized to and + * deserialized from BSON. + */ +class BSONSerializable { +public: + virtual ~BSONSerializable() {} + /** - * "Types" are the interface to a known data structure that will be serialized to and - * deserialized from BSON. + * Returns true if all the mandatory fields are present and have valid + * representations. Otherwise returns false and fills in the optional 'errMsg' string. */ - class BSONSerializable { - public: - - virtual ~BSONSerializable() {} - - /** - * Returns true if all the mandatory fields are present and have valid - * representations. Otherwise returns false and fills in the optional 'errMsg' string. - */ - virtual bool isValid( std::string* errMsg ) const = 0; - - /** Returns the BSON representation of the entry. */ - virtual BSONObj toBSON() const = 0; + virtual bool isValid(std::string* errMsg) const = 0; - /** - * Clears and populates the internal state using the 'source' BSON object if the - * latter contains valid values. Otherwise sets errMsg and returns false. - */ - virtual bool parseBSON( const BSONObj& source, std::string* errMsg ) = 0; - - /** Clears the internal state. */ - virtual void clear() = 0; - - /** Returns a std::string representation of the current internal state. */ - virtual std::string toString() const = 0; - }; + /** Returns the BSON representation of the entry. */ + virtual BSONObj toBSON() const = 0; /** - * Generic implementation which accepts and stores any BSON object - * - * Generally this should only be used for compatibility reasons - newer requests should be - * fully typed. + * Clears and populates the internal state using the 'source' BSON object if the + * latter contains valid values. Otherwise sets errMsg and returns false. */ - class RawBSONSerializable : public BSONSerializable { - public: + virtual bool parseBSON(const BSONObj& source, std::string* errMsg) = 0; + + /** Clears the internal state. */ + virtual void clear() = 0; - RawBSONSerializable() { - } + /** Returns a std::string representation of the current internal state. */ + virtual std::string toString() const = 0; +}; - explicit RawBSONSerializable(const BSONObj& raw) - : _raw(raw) { - } +/** + * Generic implementation which accepts and stores any BSON object + * + * Generally this should only be used for compatibility reasons - newer requests should be + * fully typed. + */ +class RawBSONSerializable : public BSONSerializable { +public: + RawBSONSerializable() {} - virtual ~RawBSONSerializable() { - } + explicit RawBSONSerializable(const BSONObj& raw) : _raw(raw) {} - virtual bool isValid(std::string* errMsg) const { - return true; - } + virtual ~RawBSONSerializable() {} - virtual BSONObj toBSON() const { - return _raw; - } + virtual bool isValid(std::string* errMsg) const { + return true; + } - virtual bool parseBSON(const BSONObj& source, std::string* errMsg) { - _raw = source.getOwned(); - return true; - } + virtual BSONObj toBSON() const { + return _raw; + } - virtual void clear() { - _raw = BSONObj(); - } + virtual bool parseBSON(const BSONObj& source, std::string* errMsg) { + _raw = source.getOwned(); + return true; + } - virtual std::string toString() const { - return toBSON().toString(); - } + virtual void clear() { + _raw = BSONObj(); + } - private: + virtual std::string toString() const { + return toBSON().toString(); + } - BSONObj _raw; - }; +private: + BSONObj _raw; +}; -} // namespace mongo +} // namespace mongo |