diff --git a/src/value.hpp b/src/value.hpp index e05059a9..f0354959 100644 --- a/src/value.hpp +++ b/src/value.hpp @@ -21,7 +21,7 @@ /*! @file value.hpp @brief Value interface and concrete subclasses - @version $Name: $ $Revision: 1.3 $ + @version $Name: $ $Revision: 1.4 $ @author Andreas Huggel (ahu) ahuggel@gmx.net @date 09-Jan-04, ahu: created @@ -113,6 +113,22 @@ namespace Exif { @return The converted value. */ virtual long toLong(long n =0) const =0; + /*! + @brief Convert the n-th component of the value to a float. The + behaviour of this method may be undefined if there is no + n-th component. + + @return The converted value. + */ + virtual float toFloat(long n =0) const =0; + /*! + @brief Convert the n-th component of the value to a Rational. The + behaviour of this method may be undefined if there is no + n-th component. + + @return The converted value. + */ + virtual Rational toRational(long n =0) const =0; /*! @brief Return the value as a string. Implemented in terms of write(std::ostream& os) const of the concrete class. @@ -171,6 +187,8 @@ namespace Exif { public: //! Default constructor. DataValue(TypeId typeId =undefined) : Value(typeId) {} + //! Virtual destructor. + virtual ~DataValue() {} //! Assignment operator. DataValue& operator=(const DataValue& rhs); /*! @@ -201,6 +219,9 @@ namespace Exif { virtual Value* clone() const; virtual std::ostream& write(std::ostream& os) const; virtual long toLong(long n =0) const { return value_[n]; } + virtual float toFloat(long n =0) const { return value_[n]; } + virtual Rational toRational(long n =0) const + { return Rational(value_[n], 1); } private: std::string value_; @@ -212,6 +233,8 @@ namespace Exif { public: //! Default constructor. AsciiValue() : Value(asciiString) {} + //! Virtual destructor. + virtual ~AsciiValue() {} //! Assignment operator. AsciiValue& operator=(const AsciiValue& rhs); /*! @@ -251,6 +274,9 @@ namespace Exif { */ virtual std::ostream& write(std::ostream& os) const; virtual long toLong(long n =0) const { return value_[n]; } + virtual float toFloat(long n =0) const { return value_[n]; } + virtual Rational toRational(long n =0) const + { return Rational(value_[n], 1); } private: std::string value_; @@ -285,6 +311,8 @@ namespace Exif { public: //! Default constructor. ValueType() : Value(getType()) {} + //! Virtual destructor. + virtual ~ValueType() {} //! Assignment operator. ValueType& operator=(const ValueType& rhs); virtual void read(const char* buf, long len, ByteOrder byteOrder); @@ -301,6 +329,8 @@ namespace Exif { virtual Value* clone() const; virtual std::ostream& write(std::ostream& os) const; virtual long toLong(long n =0) const; + virtual float toFloat(long n =0) const; + virtual Rational toRational(long n =0) const; //! Container for values typedef std::vector ValueList; @@ -533,6 +563,42 @@ namespace Exif { { return value_[n].first / value_[n].second; } + // Default implementation + template + inline float ValueType::toFloat(long n) const + { + return value_[n]; + } + // Specialization for rational + template<> + inline float ValueType::toFloat(long n) const + { + return (float)value_[n].first / value_[n].second; + } + // Specialization for unsigned rational + template<> + inline float ValueType::toFloat(long n) const + { + return (float)value_[n].first / value_[n].second; + } + // Default implementation + template + inline Rational ValueType::toRational(long n) const + { + return Rational(value_[n], 1); + } + // Specialization for rational + template<> + inline Rational ValueType::toRational(long n) const + { + return Rational(value_[n].first, value_[n].second); + } + // Specialization for unsigned rational + template<> + inline Rational ValueType::toRational(long n) const + { + return Rational(value_[n].first, value_[n].second); + } } // namespace Exif