Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Friends
omni::LengthUnit Class Reference

An encapsulation for length units. More...

#include <LengthUnit.h>

Public Types

enum  Type {
  METER, MILLIMETER, CENTIMETER, INCH,
  FOOT, NUM_UNIT_TYPES, INVALID_UNIT = -1
}
 Supported unit types. More...
 

Public Member Functions

 LengthUnit (Type=METER)
 Make a new unit with a certain type. More...
 
 LengthUnit (QString const &)
 Make a new unit from abbreviation type. More...
 
QString abbreviation () const
 Return abbreviation of unit. More...
 
Type type () const
 Return type of unit. More...
 
void setType (Type)
 Set type of unit. More...
 
QString nameSingular () const
 Return singular name of unit. More...
 
QString namePlural () const
 Return plural name of unit. More...
 
void fromStream (QDataStream &)
 Deserialize from stream. More...
 
void toStream (QDataStream &) const
 Serialize to stream. More...
 

Static Public Member Functions

static QString abbreviation (Type)
 Return abbreviation for unit with type. More...
 
static Type type (QString const &abbr)
 Get unit type from abbreviation. More...
 
static QString nameSingular (Type)
 Return singular name of unit with type. More...
 
static QString namePlural (Type)
 Return plural name of unit with type. More...
 

Private Types

typedef std::map< Type, QString > map_type
 

Private Attributes

Type type_
 

Friends

bool operator== (LengthUnit const &, LengthUnit const &)
 Test for equality. ScreenSetup is ignored. More...
 

Detailed Description

An encapsulation for length units.

Member Typedef Documentation

typedef std::map<Type, QString> omni::LengthUnit::map_type
private

Member Enumeration Documentation

Supported unit types.

Enumerator
METER 
MILLIMETER 
CENTIMETER 
INCH 
FOOT 
NUM_UNIT_TYPES 
INVALID_UNIT 
31  {
34  INVALID_UNIT = -1
35  };
Definition: LengthUnit.h:32
Definition: LengthUnit.h:34
Definition: LengthUnit.h:33
Definition: LengthUnit.h:33
Definition: LengthUnit.h:32
Definition: LengthUnit.h:32
Definition: LengthUnit.h:33

Constructor & Destructor Documentation

omni::LengthUnit::LengthUnit ( Type  _type = METER)

Make a new unit with a certain type.

25  :
26  type_(_type)
27  {}
Type type_
Definition: LengthUnit.h:83
omni::LengthUnit::LengthUnit ( QString const &  _abbr)

Make a new unit from abbreviation type.

30  {
31  type_ = type(_abbr);
32  }
Type type_
Definition: LengthUnit.h:83
Type type() const
Return type of unit.
Definition: LengthUnit.cpp:78

Member Function Documentation

QString omni::LengthUnit::abbreviation ( Type  _type)
static

Return abbreviation for unit with type.

34  {
35  static map_type abbrMap_;
36 
37  if (abbrMap_.empty()) {
38  abbrMap_ = map_type({
39  { METER, "m" },
40  { MILLIMETER, "mm" },
41  { CENTIMETER, "cm" },
42  { INCH, "in" },
43  { FOOT, "ft" }
44  });
45  }
46 
47  if (abbrMap_.count(_type) == 0) {
48  return "INVALID_UNIT";
49  }
50  return abbrMap_.at(_type);
51  }
Definition: LengthUnit.h:32
Definition: LengthUnit.h:33
std::map< Type, QString > map_type
Definition: LengthUnit.h:81
Definition: LengthUnit.h:32
Definition: LengthUnit.h:32
Definition: LengthUnit.h:33
QString omni::LengthUnit::abbreviation ( ) const

Return abbreviation of unit.

53  {
54  return abbreviation(type_);
55  }
Type type_
Definition: LengthUnit.h:83
QString abbreviation() const
Return abbreviation of unit.
Definition: LengthUnit.cpp:53
void omni::LengthUnit::fromStream ( QDataStream &  _is)

Deserialize from stream.

138  {
139  _is >> type_;
140  }
Type type_
Definition: LengthUnit.h:83
QString omni::LengthUnit::namePlural ( Type  _type)
static

Return plural name of unit with type.

113  {
114  static map_type npMap_;
115 
116  if (npMap_.empty()) {
117  npMap_ = map_type({
118  { METER, "meters" },
119  { MILLIMETER, "millimeters" },
120  { CENTIMETER, "centimeters" },
121  { INCH, "inches" },
122  { FOOT, "feet" }
123  });
124  }
125 
126  if (npMap_.count(_type) == 0) {
127  return "INVALID_UNIT";
128  }
129  return npMap_.at(_type);
130  }
Definition: LengthUnit.h:32
Definition: LengthUnit.h:33
std::map< Type, QString > map_type
Definition: LengthUnit.h:81
Definition: LengthUnit.h:32
Definition: LengthUnit.h:32
Definition: LengthUnit.h:33
QString omni::LengthUnit::namePlural ( ) const

Return plural name of unit.

133  {
134  return namePlural(type_);
135  }
Type type_
Definition: LengthUnit.h:83
QString namePlural() const
Return plural name of unit.
Definition: LengthUnit.cpp:133
QString omni::LengthUnit::nameSingular ( Type  _type)
static

Return singular name of unit with type.

88  {
89  static map_type nsMap_;
90 
91  if (nsMap_.empty()) {
92  nsMap_ = map_type({
93  { METER, "meter" },
94  { MILLIMETER, "millimeter" },
95  { CENTIMETER, "centimeter" },
96  { INCH, "inch" },
97  { FOOT, "foot" }
98  });
99  }
100 
101  if (nsMap_.count(_type) == 0) {
102  return "INVALID_UNIT";
103  }
104  return nsMap_.at(_type);
105  }
Definition: LengthUnit.h:32
Definition: LengthUnit.h:33
std::map< Type, QString > map_type
Definition: LengthUnit.h:81
Definition: LengthUnit.h:32
Definition: LengthUnit.h:32
Definition: LengthUnit.h:33
QString omni::LengthUnit::nameSingular ( ) const

Return singular name of unit.

108  {
109  return nameSingular(type_);
110  }
Type type_
Definition: LengthUnit.h:83
QString nameSingular() const
Return singular name of unit.
Definition: LengthUnit.cpp:108
void omni::LengthUnit::setType ( Type  _type)

Set type of unit.

83  {
84  type_ = _type;
85  }
Type type_
Definition: LengthUnit.h:83
void omni::LengthUnit::toStream ( QDataStream &  _os) const

Serialize to stream.

143  {
144  _os << type_;
145  }
Type type_
Definition: LengthUnit.h:83
LengthUnit::Type omni::LengthUnit::type ( QString const &  abbr)
static

Get unit type from abbreviation.

58  {
59  static std::map<QString, Type> typeMap_;
60 
61  if (typeMap_.empty()) {
62  typeMap_ = std::map<QString, Type>({
63  { "m", METER },
64  { "mm", MILLIMETER },
65  { "cm", CENTIMETER },
66  { "in", INCH },
67  { "ft", FOOT }
68  });
69  }
70 
71  if (typeMap_.count(abbr) == 0) {
72  return INVALID_UNIT;
73  }
74  return typeMap_.at(abbr);
75  }
Definition: LengthUnit.h:32
Definition: LengthUnit.h:34
Definition: LengthUnit.h:33
Definition: LengthUnit.h:32
Definition: LengthUnit.h:32
Definition: LengthUnit.h:33
LengthUnit::Type omni::LengthUnit::type ( ) const

Return type of unit.

78  {
79  return type_;
80  }
Type type_
Definition: LengthUnit.h:83

Friends And Related Function Documentation

bool operator== ( LengthUnit const &  _lhs,
LengthUnit const &  _rhs 
)
friend

Test for equality. ScreenSetup is ignored.

148  {
150  }
Type type_
Definition: LengthUnit.h:83
#define OMNI_TEST_MEMBER_EQUAL(member)
Definition: util.h:125

Field Documentation

Type omni::LengthUnit::type_
private

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