libmusicbrainz3  3.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MusicBrainz::Relation Class Reference

Represents a relation between two Entities. More...

Public Types

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

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. More...
 
virtual ~Relation ()
 Destructor. More...
 
std::string getType () const
 Returns this relation's type. More...
 
void setType (const std::string &type)
 Sets this relation's type. More...
 
std::string getTargetId () const
 Returns the target's ID. More...
 
void setTargetId (const std::string &targetId)
 Sets the target's ID. More...
 
std::string getTargetType () const
 Returns the target's type. More...
 
void setTargetType (const std::string &targetType)
 Sets the target's type. More...
 
std::string getBeginDate () const
 Returns the begin date. More...
 
void setBeginDate (const std::string &dateStr)
 Sets the begin date. More...
 
std::string getEndDate () const
 Returns the end date. More...
 
void setEndDate (const std::string &dateStr)
 Sets the end date. More...
 
Direction getDirection () const
 Returns the reading direction. More...
 
void setDirection (const Direction direction)
 Sets the reading direction. More...
 
AttributesgetAttributes ()
 Returns a list of attributes describing this relation. More...
 
int getNumAttributes () const
 Returns number of attributes. More...
 
std::string getAttribute (int index) const
 Returns an attribute specified by index. More...
 
void addAttribute (const std::string &attribute)
 Adds an attribute to the list. More...
 
EntitygetTarget () const
 Returns this relation's target object. More...
 
void setTarget (Entity *target)
 Sets this relation's target object. More...
 

Static Public Attributes

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

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
relationTypea string containing an absolute URI
targetTypea string containing an absolute URI
targetIda string containing an absolute URI
directionone of Relation::DIR_FORWARD, Relation::DIR_BACKWARD, or Relation::DIR_BOTH
attributesa list of strings containing absolute URIs
beginDatea string containing a date
endDatea string containing a date
targetan 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
attributea 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
dateStra string containing a date
See also
getBeginDate
void MusicBrainz::Relation::setDirection ( const Direction  direction)

Sets the reading direction.

Parameters
directionRelation::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
dateStra 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
targeta subclass of Entity, or NULL
void MusicBrainz::Relation::setTargetId ( const std::string &  targetId)

Sets the target's ID.

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

Sets the target's type.

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

Sets this relation's type.

Parameters
typea 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.