TestXdmfVisitorValueCounter.cpp 1.2 KB
Newer Older
1
#include "XdmfTestDataGenerator.hpp"
2 3
#include "XdmfVisitor.hpp"
#include "XdmfGrid.hpp"
4
#include <iostream>
5
#include <assert.h>
6 7

// Make a new XdmfVisitor that simply counts number of values
8
class XdmfVisitorValueCounter : public XdmfVisitor,
9
                                public Loki::Visitor<XdmfArray> {
10

11 12
public:

13 14 15 16 17
  /**
   * Create a new XdmfVisitorValueCounter.
   *
   * @return constructed XdmfVisitorValueCounter.
   */
18
  static shared_ptr<XdmfVisitorValueCounter>
19 20
  New()
  {
21
    shared_ptr<XdmfVisitorValueCounter> p(new XdmfVisitorValueCounter());
22 23 24 25 26 27 28 29 30 31 32 33 34
    return p;
  };

  ~XdmfVisitorValueCounter()
  {
  };

  int
  getCount()
  {
    return mCount;
  }

35 36
  using XdmfVisitor::visit;

37
  void
38 39
  visit(XdmfArray & array, 
        const shared_ptr<XdmfBaseVisitor>)
40 41 42
  {
    mCount += array.getSize();
  }
43 44 45

protected:

46 47 48 49
  XdmfVisitorValueCounter() :
    mCount(0)
  {
  }
50 51 52

private:

53
  int mCount;
54 55
};

56
int main(int, char **)
57
{
58 59
  shared_ptr<XdmfVisitorValueCounter> visitor = XdmfVisitorValueCounter::New();
  shared_ptr<XdmfGrid> grid = XdmfTestDataGenerator::createHexahedron();
60

61
  grid->accept(visitor);
62

63 64
  std::cout << visitor->getCount() << " ?= " << 71 << std::endl;

65
  assert(visitor->getCount() == 71);
66

67
  return 0;
68
}