Skip to content

Commit

Permalink
add functions for converting series units to/from strings, use it in …
Browse files Browse the repository at this point in the history
…xml info example
  • Loading branch information
coalsont committed Mar 30, 2015
1 parent 693c535 commit cd6669a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
44 changes: 44 additions & 0 deletions Cifti/CiftiSeriesMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,50 @@
using namespace cifti;
using namespace std;

CiftiSeriesMap::Unit CiftiSeriesMap::stringToUnit(const AString& string, bool& ok)
{
ok = true;
if (string == "SECOND")
{
return SECOND;
} else if (string == "HERTZ") {
return HERTZ;
} else if (string == "METER") {
return METER;
} else if (string == "RADIAN") {
return RADIAN;
}
ok = false;
return SECOND;
}

AString CiftiSeriesMap::unitToString(const CiftiSeriesMap::Unit& theUnit)
{
switch (theUnit)
{
case SECOND:
return "SECOND";
case HERTZ:
return "HERTZ";
case METER:
return "METER";
case RADIAN:
return "RADIAN";
}
CiftiAssert(false);
return "UNKNOWN";
}

vector<CiftiSeriesMap::Unit> CiftiSeriesMap::getAllUnits()
{
vector<Unit> ret;
ret.push_back(SECOND);
ret.push_back(HERTZ);
ret.push_back(METER);
ret.push_back(RADIAN);
return ret;
}

void CiftiSeriesMap::readXML1(XmlReader& xml)
{
vector<AString> mandAttrs(2), optAttrs(1, "TimeStart");
Expand Down
4 changes: 4 additions & 0 deletions Cifti/CiftiSeriesMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ namespace cifti
void setUnit(const Unit& unit) { m_unit = unit; }
void setLength(const int64_t& length) { CiftiAssert(length > 0); m_length = length; }

static Unit stringToUnit(const AString& string, bool& ok);
static AString unitToString(const Unit& theUnit);
static std::vector<Unit> getAllUnits();

CiftiMappingType* clone() const { return new CiftiSeriesMap(*this); }
MappingType getType() const { return SERIES; }
int64_t getLength() const { return m_length; }
Expand Down
17 changes: 1 addition & 16 deletions example/xmlinfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,7 @@ int main(int argc, char** argv)
cout << "Series, length " << myMap.getLength() << endl;
cout << " Start: " << myMap.getStart() << endl;
cout << " Step: " << myMap.getStep() << endl;
cout << " Unit: ";
switch (myMap.getUnit())
{
case CiftiSeriesMap::SECOND:
cout << "Seconds" << endl;
break;
case CiftiSeriesMap::HERTZ:
cout << "Hertz" << endl;
break;
case CiftiSeriesMap::METER:
cout << "Meters" << endl;
break;
case CiftiSeriesMap::RADIAN:
cout << "Radians" << endl;
break;
}
cout << " Unit: " << AString_to_std_string(CiftiSeriesMap::unitToString(myMap.getUnit())) << endl;
break;
}
}
Expand Down

0 comments on commit cd6669a

Please sign in to comment.