Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions

mitk::EnumerationProperty Class Reference
[Data Management Classes]

#include <mitkEnumerationProperty.h>

Inheritance diagram for mitk::EnumerationProperty:
Inheritance graph
[legend]
Collaboration diagram for mitk::EnumerationProperty:
Collaboration graph
[legend]

List of all members.

Public Types

typedef EnumerationProperty Self
typedef BaseProperty Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer
typedef unsigned int IdType
typedef std::map< IdType,
std::string > 
EnumIdsContainerType
typedef std::map< std::string,
IdType
EnumStringsContainerType
typedef
EnumIdsContainerType::const_iterator 
EnumConstIterator

Public Member Functions

virtual const char * GetClassName () const
virtual bool AddEnum (const std::string &name, const IdType &id)
virtual bool SetValue (const std::string &name)
virtual bool SetValue (const IdType &id)
virtual IdType GetValueAsId () const
virtual std::string GetValueAsString () const
virtual void Clear ()
virtual
EnumIdsContainerType::size_type 
Size () const
virtual EnumConstIterator Begin () const
virtual EnumConstIterator End () const
virtual std::string GetEnumString (const IdType &id) const
virtual IdType GetEnumId (const std::string &name) const
virtual bool IsValidEnumerationValue (const IdType &val) const
virtual bool IsValidEnumerationValue (const std::string &val) const
virtual bool operator== (const BaseProperty &property) const
 Subclasses must implement this operator==. Operator== which is used by PropertyList to check whether a property has been changed.
const EnumIdsContainerTypeGetEnumIds () const
const EnumStringsContainerTypeGetEnumStrings () const
EnumIdsContainerTypeGetEnumIds ()
EnumStringsContainerTypeGetEnumStrings ()

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 EnumerationProperty ()

Detailed Description

This class may be used to store properties similar to enumeration values. Each enumeration value is identified via a string representation and a id. Note, that both string representation and id MUST be unique. This is checked when inserting a new enumeration value. Please note that you have to add valid enumeration values before you may use the Get/SetValue methods.

To use the class enumeration property you have 2 choices:

1. Directly use the class and add your possible enumeration values via AddEnum(name, id). NOte that the ids do not have to be in any order, they just have to be unique. The current value is set via SetValue(...) and retrieved via GetValueAsId() or GetValueAsString(). 2. Create a subclass, which adds the possible enumeration values in its constructor and maybe adds some additional convenience functions to set/get the value. NOte that you should override AddEnum(...) as protected so that the user may not add additional invalid enumeration values. As example see mitk::VtkRepresentationProperty or mitk::VtkInterpolationProperty

Definition at line 49 of file mitkEnumerationProperty.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::EnumerationProperty::ConstPointer
typedef EnumIdsContainerType::const_iterator mitk::EnumerationProperty::EnumConstIterator

Type used for iterators over all defined enumeration values.

Definition at line 77 of file mitkEnumerationProperty.h.

Type used to store a mapping from enumeration id to enumeration string/ description

Definition at line 66 of file mitkEnumerationProperty.h.

Type used to store a mapping from enumeration string/description to enumeration id

Definition at line 72 of file mitkEnumerationProperty.h.

typedef unsigned int mitk::EnumerationProperty::IdType

Represents the unique id which is asigned to each enumeration value

Definition at line 55 of file mitkEnumerationProperty.h.

typedef itk::SmartPointer<Self> mitk::EnumerationProperty::Pointer

Constructor & Destructor Documentation

mitk::EnumerationProperty::EnumerationProperty (  ) [protected]

Default constructor. The current value of the enumeration is undefined.

Definition at line 26 of file mitkEnumerationProperty.cpp.

{
  m_CurrentValue = 0;
}

Member Function Documentation

bool mitk::EnumerationProperty::AddEnum ( const std::string &  name,
const IdType id 
) [virtual]

Adds an enumeration value into the enumeration. The name and id provided must be unique. This is checked while adding the new enumeration value. If it is not unique, false is returned. If addition was successful, true is returned.

Parameters:
namethe unique string representation of the enumeration value
idthe unique integer representation of the enumeration value
Returns:
true, if the name/id combination was successfully added to the enumeration values or true otherwise

Reimplemented in mitk::PlaneOrientationProperty, mitk::VtkInterpolationProperty, mitk::VtkRepresentationProperty, mitk::VtkResliceInterpolationProperty, mitk::VtkScalarModeProperty, mitk::VtkVolumeRenderingProperty, mitk::OdfNormalizationMethodProperty, mitk::OdfScaleByProperty, mitk::GridRepresentationProperty, mitk::GridVolumeMapperProperty, and mitk::PlanarFigureControlPointStyleProperty.

Definition at line 32 of file mitkEnumerationProperty.cpp.

{
  if ( ( ! IsValidEnumerationValue( name ) ) && ( ! IsValidEnumerationValue( id ) ) )
  {
    GetEnumIds().insert( std::make_pair( id, name ) );
    GetEnumStrings().insert( std::make_pair( name, id ) );
    return true;
  }
  else
  {
    return false;
  }
}
mitk::EnumerationProperty::EnumConstIterator mitk::EnumerationProperty::Begin (  ) const [virtual]

Provides access to the set of known enumeration values. The string representation may be accessed via iterator->second, the id may be access via iterator->first

Returns:
an iterator over all enumeration values.

Definition at line 101 of file mitkEnumerationProperty.cpp.

Referenced by QmitkDataManagerView::SurfaceRepresentationMenuAboutToShow().

{
  return GetEnumIds().begin();
}
void mitk::EnumerationProperty::Clear (  ) [virtual]

Clears all possible enumeration values and the current enumeration value.

Definition at line 86 of file mitkEnumerationProperty.cpp.

{
  GetEnumIds().clear();
  GetEnumStrings().clear();
  m_CurrentValue = 0;
}
mitk::EnumerationProperty::EnumConstIterator mitk::EnumerationProperty::End (  ) const [virtual]

Specifies the end of the range of the known enumeration values.

Returns:
an iterator pointing past the last known element of the possible enumeration values.

Definition at line 107 of file mitkEnumerationProperty.cpp.

Referenced by QmitkDataManagerView::SurfaceRepresentationMenuAboutToShow().

{
  return GetEnumIds().end();
}
virtual const char* mitk::EnumerationProperty::GetClassName (  ) const [virtual]
mitk::EnumerationProperty::IdType mitk::EnumerationProperty::GetEnumId ( const std::string &  name ) const [virtual]

Returns the integer representation for the given string.

Parameters:
namethe enumeration name for which the integer representation should be determined if the name is invalid, the return value is unspecified.
Returns:
the integer representation of the given enumeration value

Definition at line 126 of file mitkEnumerationProperty.cpp.

{
  if ( IsValidEnumerationValue( name ) )
  {
    return  GetEnumStrings().find( name )->second;
  }
  else
  {
    return 0;
  }
}
const mitk::EnumerationProperty::EnumIdsContainerType & mitk::EnumerationProperty::GetEnumIds (  ) const

Definition at line 175 of file mitkEnumerationProperty.cpp.

{
  std::string className = this->GetNameOfClass(); // virtual!
  return s_IdMapForClassName[ className ];
}
mitk::EnumerationProperty::EnumIdsContainerType & mitk::EnumerationProperty::GetEnumIds (  )

Definition at line 168 of file mitkEnumerationProperty.cpp.

{
  std::string className = this->GetNameOfClass(); // virtual!
  return s_IdMapForClassName[ className ];
}
std::string mitk::EnumerationProperty::GetEnumString ( const IdType id ) const [virtual]

Returns the string representation for the given id.

Parameters:
idthe id for which the string representation should be determined if id is invalid, the return value is unspecified.
Returns:
the string representation of the given enumeration value

Definition at line 113 of file mitkEnumerationProperty.cpp.

{
  if ( IsValidEnumerationValue( id ) )
  {
    return GetEnumIds().find( id )->second;
  }
  else
  {
    return "invalid enum id or enums empty";
  }
}
const mitk::EnumerationProperty::EnumStringsContainerType & mitk::EnumerationProperty::GetEnumStrings (  ) const

Definition at line 189 of file mitkEnumerationProperty.cpp.

{
  std::string className = this->GetNameOfClass(); // virtual!
  return s_StringMapForClassName[ className ];
}
mitk::EnumerationProperty::EnumStringsContainerType & mitk::EnumerationProperty::GetEnumStrings (  )

Definition at line 182 of file mitkEnumerationProperty.cpp.

{
  std::string className = this->GetNameOfClass(); // virtual!
  return s_StringMapForClassName[ className ];
}
mitk::EnumerationProperty::IdType mitk::EnumerationProperty::GetValueAsId (  ) const [virtual]

Returns the id of the current enumeration value. If it was not yet set, the return value is unspecified

Definition at line 75 of file mitkEnumerationProperty.cpp.

Referenced by mitk::VolumeDataVtkMapper3D::GenerateData(), mitk::ImageMapperGL2D::GenerateData(), and QmitkRenderWindowMenu::OnCrossHairMenuAboutToShow().

{
  return m_CurrentValue;
}
std::string mitk::EnumerationProperty::GetValueAsString (  ) const [virtual]

Returns the string representation of the current enumeration value. If it was not yet set, the return value is unspecified

Reimplemented from mitk::BaseProperty.

Definition at line 80 of file mitkEnumerationProperty.cpp.

Referenced by mitk::ShaderRepository::ApplyProperties(), QmitkDataManagerView::SurfaceRepresentationActionToggled(), and QmitkDataManagerView::SurfaceRepresentationMenuAboutToShow().

{
  return GetEnumString( m_CurrentValue );
}
bool mitk::EnumerationProperty::IsValidEnumerationValue ( const std::string &  val ) const [virtual]

Determines if a given string representation of an enumeration value is valid or not

Parameters:
valthe string to check
Returns:
true if the given value is valid or false otherwise

Definition at line 162 of file mitkEnumerationProperty.cpp.

{
  return ( GetEnumStrings().find( val ) != GetEnumStrings().end() );
}
bool mitk::EnumerationProperty::IsValidEnumerationValue ( const IdType val ) const [virtual]

Determines if a given integer representation of an enumeration value is valid or not

Parameters:
valthe integer value to check
Returns:
true if the given value is valid or false otherwise

Definition at line 156 of file mitkEnumerationProperty.cpp.

Referenced by QmitkDataManagerView::SurfaceRepresentationActionToggled().

{
  return ( GetEnumIds().find( val ) != GetEnumIds().end() );
}
static Pointer mitk::EnumerationProperty::New (  ) [static]
bool mitk::EnumerationProperty::operator== ( const BaseProperty property ) const [virtual]

Subclasses must implement this operator==. Operator== which is used by PropertyList to check whether a property has been changed.

Implements mitk::BaseProperty.

Definition at line 139 of file mitkEnumerationProperty.cpp.

{
  const Self * other = dynamic_cast<const Self*>( &property );

  if ( other == NULL )
    return false;

  if ( this->Size() != other->Size() )
    return false;

  if ( this->GetValueAsId() != other->GetValueAsId() )
    return false;

  return std::equal( this->Begin(), this->End(), other->Begin() );
}
bool mitk::EnumerationProperty::SetValue ( const std::string &  name ) [virtual]
bool mitk::EnumerationProperty::SetValue ( const IdType id ) [virtual]

Sets the current value of the enumeration

Parameters:
idthe integer representation of the enumeration value to set
Returns:
true if the value was successfully set (i.e. it was valid), or false, if the id provided is invalid.

Definition at line 61 of file mitkEnumerationProperty.cpp.

{
  if ( IsValidEnumerationValue( id ) )
  {
    m_CurrentValue = id;
    Modified();
    return true;
  }
  else
  {
    return false;
  }
}
mitk::EnumerationProperty::EnumIdsContainerType::size_type mitk::EnumerationProperty::Size (  ) const [virtual]

Determines the number of enumeration values which have been added via AddEnum(...).

Returns:
the number of enumeration values associated with this Enumeration Property

Definition at line 94 of file mitkEnumerationProperty.cpp.

Referenced by mitk::OrganTypeProperty::AddEnumerationTypes(), and mitk::ModalityProperty::AddEnumerationTypes().

{
  return GetEnumIds().size();
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines