XdmfGridCollectionType.cpp 4.51 KB
Newer Older
Kenneth Leiter's avatar
Kenneth Leiter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfGridCollectionType.cpp                                          */
/*                                                                           */
/*  Author:                                                                  */
/*     Kenneth Leiter                                                        */
/*     kenneth.leiter@arl.army.mil                                           */
/*     US Army Research Laboratory                                           */
/*     Aberdeen Proving Ground, MD                                           */
/*                                                                           */
/*     Copyright @ 2011 US Army Research Laboratory                          */
/*     All Rights Reserved                                                   */
/*     See Copyright.txt for details                                         */
/*                                                                           */
/*     This software is distributed WITHOUT ANY WARRANTY; without            */
/*     even the implied warranty of MERCHANTABILITY or FITNESS               */
/*     FOR A PARTICULAR PURPOSE.  See the above copyright notice             */
/*     for more information.                                                 */
/*                                                                           */
/*****************************************************************************/
23

24
#include <utility>
25
#include "XdmfError.hpp"
26
#include "XdmfGridCollectionType.hpp"
27

28 29 30
std::map<std::string, shared_ptr<const XdmfGridCollectionType>(*)()>
  XdmfGridCollectionType::mGridCollectionDefinitions;

31
// Supported XdmfGridCollectionTypes
32
shared_ptr<const XdmfGridCollectionType>
33
XdmfGridCollectionType::NoCollectionType()
34
{
35
  static shared_ptr<const XdmfGridCollectionType>
36 37
    p(new XdmfGridCollectionType("None"));
  return p;
38 39
}

40
shared_ptr<const XdmfGridCollectionType>
41
XdmfGridCollectionType::Spatial()
42
{
43
  static shared_ptr<const XdmfGridCollectionType>
44 45
    p(new XdmfGridCollectionType("Spatial"));
  return p;
46 47
}

48
shared_ptr<const XdmfGridCollectionType>
49
XdmfGridCollectionType::Temporal()
50
{
51
  static shared_ptr<const XdmfGridCollectionType>
52 53
    p(new XdmfGridCollectionType("Temporal"));
  return p;
54 55
}

56 57 58 59 60 61 62 63
void
XdmfGridCollectionType::InitTypes()
{
  mGridCollectionDefinitions["NONE"] = NoCollectionType;
  mGridCollectionDefinitions["SPATIAL"] = Spatial;
  mGridCollectionDefinitions["TEMPORAL"] = Temporal;
}

64
XdmfGridCollectionType::XdmfGridCollectionType(const std::string & name) :
65
  mName(name)
66 67 68
{
}

69 70 71 72
XdmfGridCollectionType::~XdmfGridCollectionType()
{
}

73
shared_ptr<const XdmfGridCollectionType>
74
XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemProperties)
75
{
76 77
  InitTypes();

78 79
  std::map<std::string, std::string>::const_iterator type =
    itemProperties.find("CollectionType");
80
  if(type == itemProperties.end()) {
81 82 83
    XdmfError::message(XdmfError::FATAL, 
                       "'CollectionType' not in itemProperties in "
                       "XdmfGridCollectionType::New");
84 85
  }

86
  const std::string & typeVal = ConvertToUpper(type->second);
87 88 89 90 91 92 93 94

  std::map<std::string, shared_ptr<const XdmfGridCollectionType>(*)()>::const_iterator returnType
    = mGridCollectionDefinitions.find(typeVal);

  if (returnType == mGridCollectionDefinitions.end()) {
    XdmfError::message(XdmfError::FATAL,
                       "'CollectionType' not of 'None', 'Spatial', or "
                       "'Temporal' in XdmfGridCollectionType::New");
95
  }
96 97
  else {
    return (*(returnType->second))();
98 99
  }

100 101 102
  XdmfError::message(XdmfError::FATAL, 
                     "'CollectionType' not of 'None', 'Spatial', or "
                     "'Temporal' in XdmfGridCollectionType::New");
103

104
  // unreachable
105
  return shared_ptr<const XdmfGridCollectionType>();
106 107
}

108 109
void
XdmfGridCollectionType::getProperties(std::map<std::string, std::string> & collectedProperties) const
110
{
111
  collectedProperties.insert(std::make_pair("CollectionType", mName));
112
}
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

// C Wrappers

int XdmfGridCollectionTypeNoCollectionType()
{
  return XDMF_GRID_COLLECTION_TYPE_NO_COLLECTION_TYPE;
}

int XdmfGridCollectionTypeSpatial()
{
  return XDMF_GRID_COLLECTION_TYPE_SPATIAL;
}

int XdmfGridCollectionTypeTemporal()
{
  return XDMF_GRID_COLLECTION_TYPE_TEMPORAL;
}