Logo Search packages:      
Sourcecode: rosegarden version File versions  Download package

Rosegarden::PropertyName Class Reference

#include <PropertyName.h>

List of all members.

Detailed Description

A PropertyName is something that can be constructed from a string, compared quickly as an int, hashed as a key in a hash map, and streamed out again as a string. It must have accompanying functors PropertyNamesEqual and PropertyNameHash which compare and hash PropertyName objects.

The simplest implementation is a string:

typedef std::string PropertyName;

struct PropertyNamesEqual { bool operator() (const PropertyName &s1, const PropertyName &s2) const { return s1 == s2; } };

struct PropertyNameHash { static std::hash<const char *> _H; size_t operator() (const PropertyName &s) const { return _H(s.c_str()); } };

std::hash<const char *> PropertyNameHash::_H;

but our implementation is faster in practice: while it behaves outwardly like a string, for the Event that makes use of it, it performs much like a machine integer. It also shares strings, reducing storage sizes if there are many names in use.

A big caveat with this class is that it is _not_ safe to persist the values of PropertyNames and assume that the original strings can be recovered; they can't. The values are assigned on demand, and there's no guarantee that a given string will always map to the same value (on separate invocations of the program). This is why there's no PropertyName(int) constructor and no mechanism for storing PropertyNames in properties. (Of course, you can store the string representation of a PropertyName in a property; but that's slow.)

Definition at line 77 of file PropertyName.h.

Public Member Functions

const char * c_str () const
std::string getName () const
int getValue () const
bool operator< (const PropertyName &p) const
PropertyNameoperator= (const PropertyName &p)
PropertyNameoperator= (const std::string &s)
PropertyNameoperator= (const char *cs)
bool operator== (const PropertyName &p) const
 PropertyName (const PropertyName &p)
 PropertyName (const std::string &s)
 PropertyName (const char *cs)

Static Public Attributes

static const PropertyName EmptyPropertyName = ""

Private Types

typedef std::map< std::string,
int > 
typedef intern_map::value_type intern_pair
typedef std::map< int,
std::string > 

Static Private Member Functions

static int intern (const std::string &s)

Private Attributes

int m_value

Static Private Attributes

static intern_map * m_interns = 0
static intern_reverse_map * m_internsReversed = 0
static int m_nextValue = 0

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index