XdmfGraph.cpp 5.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfGraph.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.                                                 */
/*                                                                           */
/*****************************************************************************/

#include "XdmfAttribute.hpp"
#include "XdmfGraph.hpp"

XDMF_CHILDREN_IMPLEMENTATION(XdmfGraph, XdmfAttribute, Attribute, Name)

shared_ptr<XdmfGraph>
XdmfGraph::New(const unsigned int numberNodes)
{
  shared_ptr<XdmfGraph> p(new XdmfGraph(numberNodes));
  return p;
}

XdmfGraph::XdmfGraph(const unsigned int numberNodes) :
  XdmfSparseMatrix(numberNodes,
38 39
                   numberNodes),
  mTime(shared_ptr<XdmfTime>())
40 41 42
{
}

43 44 45 46 47 48 49
XdmfGraph::XdmfGraph(XdmfGraph & refGraph) :
  XdmfSparseMatrix(refGraph),
  mAttributes(refGraph.mAttributes),
  mTime(refGraph.mTime)
{
}

50 51 52 53 54 55 56 57 58 59 60 61
XdmfGraph::~XdmfGraph()
{
}

const std::string XdmfGraph::ItemTag = "Graph";

std::string
XdmfGraph::getItemTag() const
{
  return ItemTag;
}

62 63 64
shared_ptr<XdmfTime>
XdmfGraph::getTime()
{
65
  return boost::const_pointer_cast<XdmfTime>
66 67 68 69 70 71 72 73 74
    (static_cast<const XdmfGraph &>(*this).getTime());
}

shared_ptr<const XdmfTime>
XdmfGraph::getTime() const
{
  return mTime;
}

75 76 77
unsigned int
XdmfGraph::getNumberNodes() const
{
78
  // The number of nodes is equal to the number of rows or columns. Either will work.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  return this->getNumberRows();
}

void
XdmfGraph::populateItem(const std::map<std::string, std::string> & itemProperties,
                        const std::vector<shared_ptr<XdmfItem> > & childItems,
                        const XdmfCoreReader * const reader)
{
  XdmfSparseMatrix::populateItem(itemProperties,
                                 childItems,
                                 reader);
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
        childItems.begin();
      iter != childItems.end();
      ++iter) {
    if(shared_ptr<XdmfAttribute> attribute =
       shared_dynamic_cast<XdmfAttribute>(*iter)) {
      this->insert(attribute);
    }
  }
}

101 102 103 104
void
XdmfGraph::setTime(const shared_ptr<XdmfTime> time)
{
  mTime = time;
105
  this->setIsChanged(true);
106 107
}

108 109 110 111
void
XdmfGraph::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
{
  XdmfSparseMatrix::traverse(visitor);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  for (unsigned int i = 0; i < mAttributes.size(); ++i)
  {
    mAttributes[i]->accept(visitor);
  }
}

// C Wrappers

XDMFGRAPH * XdmfGraphNew(unsigned int numberNodes)
{
  try
  {
    shared_ptr<XdmfGraph> generatedGraph = XdmfGraph::New(numberNodes);
    return (XDMFGRAPH *)((void *)(new XdmfGraph(*generatedGraph.get())));
  }
  catch (...)
  {
    shared_ptr<XdmfGraph> generatedGraph = XdmfGraph::New(numberNodes);
    return (XDMFGRAPH *)((void *)(new XdmfGraph(*generatedGraph.get())));
  }
}

XDMFATTRIBUTE * XdmfGraphGetAttribute(XDMFGRAPH * graph, unsigned int index)
{
  return (XDMFATTRIBUTE *)((void *)(((XdmfGraph *)(graph))->getAttribute(index).get()));
}

XDMFATTRIBUTE * XdmfGraphGetAttributeByName(XDMFGRAPH * graph, char * Name)
{
  return (XDMFATTRIBUTE *)((void *)(((XdmfGraph *)(graph))->getAttribute(std::string(Name)).get()));
}

unsigned int XdmfGraphGetNumberAttributes(XDMFGRAPH * graph)
{
  return ((XdmfGraph *)graph)->getNumberAttributes();
}

void XdmfGraphInsertAttribute(XDMFGRAPH * graph, XDMFATTRIBUTE * Attribute, int passControl)
{
  if (passControl) {
    ((XdmfGraph *)(graph))->insert(shared_ptr<XdmfAttribute>((XdmfAttribute *)Attribute));
  }
  else {
    ((XdmfGraph *)(graph))->insert(shared_ptr<XdmfAttribute>((XdmfAttribute *)Attribute, XdmfNullDeleter()));
156 157
  }
}
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

void XdmfGraphRemoveAttribute(XDMFGRAPH * graph, unsigned int index)
{
  ((XdmfGraph *)graph)->removeAttribute(index);
}

void XdmfGraphRemoveAttributeByName(XDMFGRAPH * graph, char * Name)
{
  ((XdmfGraph *)graph)->removeAttribute(std::string(Name));
}

unsigned int XdmfGraphGetNumberNodes(XDMFGRAPH * graph)
{
  return ((XdmfGraph *)graph)->getNumberNodes();
}

XDMF_ITEM_C_CHILD_WRAPPER(XdmfGraph, XDMFGRAPH)
XDMF_SPARSEMATRIX_C_CHILD_WRAPPER(XdmfGraph, XDMFGRAPH)