types.hpp File Reference

Type definitions for Exiv2 and related functionality. More...

#include "exv_conf.h"
#include "version.hpp"
#include <string>
#include <iosfwd>
#include <utility>
#include <algorithm>
#include <sstream>
#include <stdint.h>

Include dependency graph for types.hpp:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Namespaces

namespace  Exiv2

Classes

struct  Exiv2::TypeInfoTable
 Information pertaining to the defined types. More...
class  Exiv2::TypeInfo
 Type information lookup functions. Implemented as a static class. More...
struct  Exiv2::DataBufRef
 Auxiliary type to enable copies and assignments, similar to std::auto_ptr_ref. See http://www.josuttis.com/libbook/auto_ptr.html for a discussion. More...
class  Exiv2::DataBuf
 Utility class containing a character array. All it does is to take care of memory allocation and deletion. Its primary use is meant to be as a stack variable in functions that need a temporary data buffer. Todo: this should be some sort of smart pointer, essentially an std::auto_ptr for a character array. But it isn't... More...

Defines

#define EXV_CALL_MEMBER_FN(object, ptrToMember)   ((object).*(ptrToMember))
 Macro to make calls to member functions through a pointer more readable. See the C++ FAQ LITE, item [33.5] How can I avoid syntax errors when calling a member function using a pointer-to-member-function?.
#define EXV_COUNTOF(a)   (sizeof(Exiv2::sizer(a)))
 Macro to determine the size of an array.

Typedefs

typedef uint8_t byte
 1 byte unsigned integer type.
typedef std::pair< uint32_t,
uint32_t > 
URational
 8 byte unsigned rational type.
typedef std::pair< int32_t,
int32_t > 
Rational
 8 byte signed rational type.

Enumerations

enum  ByteOrder { invalidByteOrder, littleEndian, bigEndian }
 Type to express the byte order (little or big endian).
enum  MetadataId {
  mdNone = 0, mdExif = 1, mdIptc = 2, mdComment = 4,
  mdXmp = 8
}
 An identifier for each type of metadata.
enum  AccessMode { amNone = 0, amRead = 1, amWrite = 2, amReadWrite = 3 }
 An identifier for each mode of metadata support.
enum  TypeId {
  invalidTypeId, unsignedByte, asciiString, unsignedShort,
  unsignedLong, unsignedRational, signedByte, undefined,
  signedShort, signedLong, signedRational, string,
  date, time, comment, directory,
  xmpText, xmpAlt, xmpBag, xmpSeq,
  langAlt, lastTypeId
}
 Type identifiers for IFD format types.
enum  IfdId {
  ifdIdNotSet, ifd0Id, exifIfdId, gpsIfdId,
  iopIfdId, ifd1Id, canonIfdId, canonCsIfdId,
  canonSiIfdId, canonCfIfdId, canonPiIfdId, canonPaIfdId,
  fujiIfdId, minoltaIfdId, minoltaCs5DIfdId, minoltaCs7DIfdId,
  minoltaCsOldIfdId, minoltaCsNewIfdId, nikon1IfdId, nikon2IfdId,
  nikon3IfdId, olympusIfdId, panasonicIfdId, pentaxIfdId,
  sigmaIfdId, sonyIfdId, lastIfdId
}
 Type to specify the IFD to which a metadata belongs.
enum  DataLocId { invalidDataLocId, valueData, directoryData, lastDataLocId }
 Type to identify where the data is stored in a directory.

Functions

uint16_t getUShort (const byte *buf, ByteOrder byteOrder)
 Read a 2 byte unsigned short value from the data buffer.
uint32_t getULong (const byte *buf, ByteOrder byteOrder)
 Read a 4 byte unsigned long value from the data buffer.
URational getURational (const byte *buf, ByteOrder byteOrder)
 Read an 8 byte unsigned rational value from the data buffer.
int16_t getShort (const byte *buf, ByteOrder byteOrder)
 Read a 2 byte signed short value from the data buffer.
int32_t getLong (const byte *buf, ByteOrder byteOrder)
 Read a 4 byte signed long value from the data buffer.
Rational getRational (const byte *buf, ByteOrder byteOrder)
 Read an 8 byte signed rational value from the data buffer.
long us2Data (byte *buf, uint16_t s, ByteOrder byteOrder)
 Convert an unsigned short to data, write the data to the buffer, return number of bytes written.
long ul2Data (byte *buf, uint32_t l, ByteOrder byteOrder)
 Convert an unsigned long to data, write the data to the buffer, return number of bytes written.
long ur2Data (byte *buf, URational l, ByteOrder byteOrder)
 Convert an unsigned rational to data, write the data to the buffer, return number of bytes written.
long s2Data (byte *buf, int16_t s, ByteOrder byteOrder)
 Convert a signed short to data, write the data to the buffer, return number of bytes written.
long l2Data (byte *buf, int32_t l, ByteOrder byteOrder)
 Convert a signed long to data, write the data to the buffer, return number of bytes written.
long r2Data (byte *buf, Rational l, ByteOrder byteOrder)
 Convert a signed rational to data, write the data to the buffer, return number of bytes written.
void hexdump (std::ostream &os, const byte *buf, long len, long offset=0)
 Print len bytes from buf in hex and ASCII format to the given stream, prefixed with the position in the buffer adjusted by offset.
bool isHex (const std::string &str, size_t size=0, const std::string &prefix="")
 Return true if str is a hex number starting with prefix followed by size hex digits, false otherwise. If size is 0, any number of digits is allowed and all are checked.
int exifTime (const char *buf, struct tm *tm)
 Converts a string in the form "%Y:%m:%d %H:%M:%S", e.g., "2007:05:24 12:31:55" to broken down time format, returns 0 if successful, else 1.
const char * exvGettext (const char *str)
 Translate a string using the gettext framework. This wrapper hides all the implementation details from the interface.
long parseLong (const std::string &s, bool &ok)
 Return a long set to the value represented by s.
float parseFloat (const std::string &s, bool &ok)
 Return a float set to the value represented by s.
Rational parseRational (const std::string &s, bool &ok)
 Return a Rational set to the value represented by s.
Rational floatToRationalCast (float f)
 Very simple conversion of a float to a Rational.
template<typename T, typename K, int N>
const T * find (T(&src)[N], const K &key)
 Find an element that matches key in the array src.
template<typename T, int N>
 char (&sizer(T(&)[N]))[N]
 Template used in the COUNTOF macro to determine the size of an array.
template<typename T>
std::string toString (const T &arg)
 Utility function to convert the argument of any type to a string.
template<typename T>
stringTo (const std::string &s, bool &ok)
 Utility function to convert a string to a value of type T.
template<>
bool stringTo< bool > (const std::string &s, bool &ok)
 Specialization of stringTo(const std::string& s, bool& ok) for bool.
template<typename IntType>
IntType gcd (IntType n, IntType m)
 Return the greatest common denominator of n and m. (Implementation from Boost rational.hpp).

Detailed Description

Type definitions for Exiv2 and related functionality.

Version:
Rev
1404
Author:
Andreas Huggel (ahu) ahuggel@gmx.net
Date:
09-Jan-04, ahu: created
11-Feb-04, ahu: isolated as a component 31-Jul-04, brad: added Time, Data and String values

Function Documentation

template<typename T, typename K, int N>
const T* find T &  src[N],
const K &  key
 

Find an element that matches key in the array src.

Designed to be used with lookup tables as shown in the example below. Requires a Key structure (ideally in the array) and a comparison operator to compare a key with an array element. The size of the array is determined automagically. Thanks to Stephan Broennimann for this nifty implementation.

      struct Bar {
          int i;
          int k;
          const char* data;

          struct Key;
          bool operator==(const Bar::Key& rhs) const;
      };

      struct Bar::Key {
          Key(int a, int b) : i(a), k(b) {}
          int i;
          int k;
      };

      bool Bar::operator==(const Bar::Key& key) const // definition
      {
          return i == key.i && k == key.k;
      }

      const Bar bars[] = {
          { 1, 1, "bar data 1" },
          { 1, 2, "bar data 2" },
          { 1, 3, "bar data 3" }
      };

      int main ( void ) {
          const Bar* bar = find(bars, Bar::Key(1, 3));
          if (bar) std::cout << bar->data << "\n";
          else std::cout << "Key not found.\n";
          return 0;
      }

Rational floatToRationalCast float  f  ) 
 

Very simple conversion of a float to a Rational.

Test it with the values that you expect and check the implementation to see if this is really what you want!

template<typename IntType>
IntType gcd IntType  n,
IntType  m
 

Return the greatest common denominator of n and m. (Implementation from Boost rational.hpp).

Note:
We use n and m as temporaries in this function, so there is no value in using const IntType& as we would only need to make a copy anyway...

float parseFloat const std::string &  s,
bool &  ok
 

Return a float set to the value represented by s.

Besides strings that represent float values, the function also handles long, Rational and boolean (see also: stringTo(const std::string& s, bool& ok)).

Parameters:
s String to parse
ok Output variable indicating the success of the operation.
Returns:
Returns the float value represented by s and sets ok to true if the conversion was successful or false if not.

long parseLong const std::string &  s,
bool &  ok
 

Return a long set to the value represented by s.

Besides strings that represent long values, the function also handles float, Rational and boolean (see also: stringTo(const std::string& s, bool& ok)).

Parameters:
s String to parse
ok Output variable indicating the success of the operation.
Returns:
Returns the long value represented by s and sets ok to true if the conversion was successful or false if not.

Rational parseRational const std::string &  s,
bool &  ok
 

Return a Rational set to the value represented by s.

Besides strings that represent Rational values, the function also handles long, float and boolean (see also: stringTo(const std::string& s, bool& ok)). Uses floatToRationalCast(float f) if the string can be parsed into a float.

Parameters:
s String to parse
ok Output variable indicating the success of the operation.
Returns:
Returns the Rational value represented by s and sets ok to true if the conversion was successful or false if not.

template<typename T>
T stringTo const std::string &  s,
bool &  ok
 

Utility function to convert a string to a value of type T.

The string representation of the value must match that recognized by the input operator for T for this function to succeed.

Parameters:
s String to convert
ok Output variable indicating the success of the operation.
Returns:
Returns the converted value and sets ok to true if the conversion was successful or false if not.

template<>
bool stringTo< bool > const std::string &  s,
bool &  ok
 

Specialization of stringTo(const std::string& s, bool& ok) for bool.

Handles the same string values as the XMP SDK. Converts the string to lowercase and returns true if it is "true", "t" or "1", and false if it is "false", "f" or "0".


Generated on Sun Jun 22 13:06:27 2008 for Exiv2 by  doxygen 1.3.9.1