XdmfItem.cpp 5.12 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 23
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfItem.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.                                                 */
/*                                                                           */
/*****************************************************************************/

24
#include "XdmfInformation.hpp"
25
#include "XdmfItem.hpp"
26 27 28
#include "XdmfVisitor.hpp"
#include "XdmfError.hpp"
#include "string.h"
29

30 31
XDMF_CHILDREN_IMPLEMENTATION(XdmfItem, XdmfInformation, Information, Key)

32 33 34 35 36
XdmfItem::XdmfItem() :
  mIsChanged(true)
{
}

37 38 39
XdmfItem::~XdmfItem()
{
}
40

41 42 43 44 45 46 47 48 49 50
bool
XdmfItem::getIsChanged()
{
  return mIsChanged;
}

void
XdmfItem::setIsChanged(bool status)
{
  // No change if status is the same
51
  if (mIsChanged != status) {
52 53
    mIsChanged = status;
    // If it was changed all parents should be alerted
54
    if (status) {
55 56
      for (std::set<XdmfItem *>::iterator iter = mParents.begin();
           iter != mParents.end();
57
           ++iter) {
58 59 60 61 62 63
        (*iter)->setIsChanged(status);
      }
    }
  }
}

64 65
void
XdmfItem::populateItem(const std::map<std::string, std::string> &,
66
                       const std::vector<shared_ptr<XdmfItem > > & childItems,
67
                       const XdmfCoreReader * const)
68
{
69
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
70 71 72
        childItems.begin();
      iter != childItems.end();
      ++iter) {
73 74
    if(shared_ptr<XdmfInformation> information = 
       shared_dynamic_cast<XdmfInformation>(*iter)) {
75 76 77
      this->insert(information);
    }
  }
78 79
}

80
void
81
XdmfItem::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
82
{
83 84 85 86 87 88 89 90 91 92 93
  for (unsigned int i = 0; i < mInformations.size(); ++i)
  {
    mInformations[i]->accept(visitor);
  }
}

// C Wrappers

void XdmfItemAccept(XDMFITEM * item, XDMFVISITOR * visitor, int * status)
{
  XDMF_ERROR_WRAP_START(status)
94 95 96
  shared_ptr<XdmfItem> & refItem = *(shared_ptr<XdmfItem> *)(item);
  shared_ptr<XdmfVisitor> & refVisitor = *(shared_ptr<XdmfVisitor> *)(visitor);
  refItem->accept(refVisitor);
97 98 99 100 101 102
  XDMF_ERROR_WRAP_END(status)
}

void XdmfItemFree(void * item)
{
  if (item != NULL) {
103
    delete ((shared_ptr<XdmfItem> *)item);
104 105 106 107 108 109
    item = NULL;
  }
}

XDMFINFORMATION * XdmfItemGetInformation(XDMFITEM * item, unsigned int index)
{
110 111 112
  shared_ptr<XdmfItem> & refItem = *(shared_ptr<XdmfItem> *)(item);
  shared_ptr<XdmfInformation> * information = new shared_ptr<XdmfInformation>(refItem->getInformation(index));
  return (XDMFINFORMATION *)information;
113 114 115 116
}

XDMFINFORMATION * XdmfItemGetInformationByKey(XDMFITEM * item, char * key)
{
117 118 119
  shared_ptr<XdmfItem> & refItem = *(shared_ptr<XdmfItem> *)(item);
  shared_ptr<XdmfInformation> * information = new shared_ptr<XdmfInformation>(refItem->getInformation(key));
  return (XDMFINFORMATION *)information;
120 121 122 123
}

unsigned int XdmfItemGetNumberInformations(XDMFITEM * item)
{
124 125
  shared_ptr<XdmfItem> & refItem = *(shared_ptr<XdmfItem> *)(item);
  return refItem->getNumberInformations();
126 127 128 129
}

void XdmfItemInsertInformation(XDMFITEM * item, XDMFINFORMATION * information, int passControl)
{
130 131 132
  shared_ptr<XdmfItem> & refItem = *(shared_ptr<XdmfItem> *)(item);
  shared_ptr<XdmfInformation> & refInformation = *(shared_ptr<XdmfInformation> *)(information);
  refItem->insert(refInformation);
133
}
134 135 136

void XdmfItemRemoveInformation(XDMFITEM * item, unsigned int index)
{
137 138
  shared_ptr<XdmfItem> & refItem = *(shared_ptr<XdmfItem> *)(item);
  refItem->removeInformation(index);
139 140 141 142
}

void XdmfItemRemoveInformationByKey(XDMFITEM * item, char * key)
{
143 144
  shared_ptr<XdmfItem> & refItem = *(shared_ptr<XdmfItem> *)(item);
  refItem->removeInformation(key);
145 146 147 148
}

char * XdmfItemGetItemTag(XDMFITEM * item)
{
149 150
  shared_ptr<XdmfItem> & refItem = *(shared_ptr<XdmfItem> *)(item);
  char * returnPointer = strdup(refItem->getItemTag().c_str());
151 152
  return returnPointer;
}