MusicBrainz::Relation Class Reference

Represents a relation between two Entities. More...

List of all members.

Public Types

enum  Direction { DIR_BOTH, DIR_FORWARD, DIR_BACKWARD }
typedef std::vector< std::string > Attributes
 A vector of strings (attributes).

Public Member Functions

 Relation (const std::string &relationType=std::string(), const std::string &targetType=std::string(), const std::string &targetId=std::string(), const Direction direction=DIR_BOTH, const Attributes &attributes=Attributes(), const std::string &beginDate=std::string(), const std::string &endDate=std::string(), Entity *target=NULL)
 Constructor.
virtual ~Relation ()
 Destructor.
std::string getType () const
 Returns this relation's type.
void setType (const std::string &type)
 Sets this relation's type.
std::string getTargetId () const
 Returns the target's ID.
void setTargetId (const std::string &targetId)
 Sets the target's ID.
std::string getTargetType () const
 Returns the target's type.
void setTargetType (const std::string &targetType)
 Sets the target's type.
std::string getBeginDate () const
 Returns the begin date.
void setBeginDate (const std::string &dateStr)
 Sets the begin date.
std::string getEndDate () const
 Returns the end date.
void setEndDate (const std::string &dateStr)
 Sets the end date.
Direction getDirection () const
 Returns the reading direction.
void setDirection (const Direction direction)
 Sets the reading direction.
AttributesgetAttributes ()
 Returns a list of attributes describing this relation.
int getNumAttributes () const
 Returns number of attributes.
std::string getAttribute (int index) const
 Returns an attribute specified by index.
void addAttribute (const std::string &attribute)
 Adds an attribute to the list.
EntitygetTarget () const
 Returns this relation's target object.
void setTarget (Entity *target)
 Sets this relation's target object.

Static Public Attributes

static const std::string TO_ARTIST
 Identifies relations linking to an artist.
static const std::string TO_RELEASE
 Identifies relations linking to a release.
static const std::string TO_TRACK
 Identifies relations linking to a track.
static const std::string TO_URL
 Identifies relations linking to an URL.

Detailed Description

Represents a relation between two Entities.

There may be an arbitrary number of relations between all first class objects in MusicBrainz. The Relation itself has multiple attributes, which may or may not be used for a given relation type.

Note that a Relation object only contains the target but not the source end of the relation.


Member Typedef Documentation

typedef std::vector<std::string> MusicBrainz::Relation::Attributes

A vector of strings (attributes).


Member Enumeration Documentation

Enumerator:
DIR_BOTH 

Relation reading direction doesn't matter.

DIR_FORWARD 

Relation reading direction is from source to target.

DIR_BACKWARD 

Relation reading direction is from target to source.


Constructor & Destructor Documentation

MusicBrainz::Relation::Relation ( const std::string &  relationType = std::string(),
const std::string &  targetType = std::string(),
const std::string &  targetId = std::string(),
const Direction  direction = DIR_BOTH,
const Attributes attributes = Attributes(),
const std::string &  beginDate = std::string(),
const std::string &  endDate = std::string(),
Entity target = NULL 
)

Constructor.

Parameters:
relationType a string containing an absolute URI
targetType a string containing an absolute URI
targetId a string containing an absolute URI
direction one of Relation::DIR_FORWARD, Relation::DIR_BACKWARD, or Relation::DIR_BOTH
attributes a list of strings containing absolute URIs
beginDate a string containing a date
endDate a string containing a date
target an instance of a subclass of Entity, or NULL
virtual MusicBrainz::Relation::~Relation (  )  [virtual]

Destructor.


Member Function Documentation

void MusicBrainz::Relation::addAttribute ( const std::string &  attribute  ) 

Adds an attribute to the list.

Parameters:
attribute a string containing an absolute URI
std::string MusicBrainz::Relation::getAttribute ( int  index  )  const

Returns an attribute specified by index.

This is equivalent to getAttributes()[index]

Returns:
a string containing the attribute
See also:
getAttributes
Attributes& MusicBrainz::Relation::getAttributes (  ) 

Returns a list of attributes describing this relation.

The attributes permitted depend on the relation type.

Returns:
a list of strings containing absolute URIs
std::string MusicBrainz::Relation::getBeginDate (  )  const

Returns the begin date.

The definition depends on the relation's type. It may for example be the day of a marriage or the year an artist joined a band. For other relation types this may be undefined.

Returns:
a string containing a date
Direction MusicBrainz::Relation::getDirection (  )  const

Returns the reading direction.

The direction may be one of Relation::DIR_FORWARD, Relation::DIR_BACKWARD, or Relation::DIR_BOTH, depending on how the relation should be read. For example, if direction is Relation::DIR_FORWARD for a cover relation, it is read as "X is a cover of Y". Some relations are bidirectional, like marriages. In these cases, the direction is Relation::DIR_BOTH.

Returns:
Relation::DIR_FORWARD, Relation::DIR_BACKWARD, or Relation::DIR_BOTH
std::string MusicBrainz::Relation::getEndDate (  )  const

Returns the end date.

As with the begin date, the definition depends on the relation's type. Depending on the relation type, this may or may not be defined.

Returns:
a string containing a date
See also:
getBeginDate
int MusicBrainz::Relation::getNumAttributes (  )  const

Returns number of attributes.

This is equivalent to getAttributes().size()

Returns:
an int containing number of attributes
See also:
getAttributes
Entity* MusicBrainz::Relation::getTarget (  )  const

Returns this relation's target object.

Note that URL relations never have a target object. Use the getTargetId method to get the URL.

Returns:
a subclass of Entity, or NULL
std::string MusicBrainz::Relation::getTargetId (  )  const

Returns the target's ID.

This is the ID the relation points to. It is an absolute URI, and in case of an URL relation, it is a URL.

Returns:
a string containing an absolute URI
std::string MusicBrainz::Relation::getTargetType (  )  const

Returns the target's type.

For MusicBrainz data, the following target types are defined:

Returns:
a string containing an absolute URI
std::string MusicBrainz::Relation::getType (  )  const

Returns this relation's type.

Returns:
a string containing an absolute URI
void MusicBrainz::Relation::setBeginDate ( const std::string &  dateStr  ) 

Sets the begin date.

Parameters:
dateStr a string containing a date
See also:
getBeginDate
void MusicBrainz::Relation::setDirection ( const Direction  direction  ) 

Sets the reading direction.

Parameters:
direction Relation::DIR_FORWARD, Relation::DIR_BACKWARD, or Relation::DIR_BOTH
See also:
getDirection
void MusicBrainz::Relation::setEndDate ( const std::string &  dateStr  ) 

Sets the end date.

Parameters:
dateStr,: a string containing a date
See also:
getBeginDate
void MusicBrainz::Relation::setTarget ( Entity target  ) 

Sets this relation's target object.

Note that URL relations never have a target object, they are set using setTargetId.

Parameters:
target a subclass of Entity, or NULL
void MusicBrainz::Relation::setTargetId ( const std::string &  targetId  ) 

Sets the target's ID.

Parameters:
targetId a string containing an absolute URI
See also:
getTargetId
void MusicBrainz::Relation::setTargetType ( const std::string &  targetType  ) 

Sets the target's type.

Parameters:
targetType a string containing an absolute URI
See also:
getTargetType
void MusicBrainz::Relation::setType ( const std::string &  type  ) 

Sets this relation's type.

Parameters:
type a string containing an absolute URI

Member Data Documentation

const std::string MusicBrainz::Relation::TO_ARTIST [static]

Identifies relations linking to an artist.

const std::string MusicBrainz::Relation::TO_RELEASE [static]

Identifies relations linking to a release.

const std::string MusicBrainz::Relation::TO_TRACK [static]

Identifies relations linking to a track.

const std::string MusicBrainz::Relation::TO_URL [static]

Identifies relations linking to an URL.


Generated on 9 Jan 2011 for libmusicbrainz3 by  doxygen 1.6.1