MyTestData

Macros

Line Code
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#ifndef mytestdata_H
#define mytestdata_H

#include <iostream>
#include <string>

#include "CondFormats/Serialization/interface/Serializable.h"

class MyTestData {
public:
  MyTestData() : a(0), b(0.), s(" ") {
    for (size_t i = 0; i < 2; i++)
      for (size_t j = 0; j < 2; j++) {
        d[i][j] = 0;
        f[i][j] = 0;
      }
  }
  MyTestData(int seed) : a(seed), b(seed + 1.1), s("Bla bla") {
    for (size_t i = 0; i < 2; i++)
      for (size_t j = 0; j < 2; j++) {
        d[i][j] = 0;
        f[i][j] = 0;
      }
    d[0][0] = 1;
    d[0][1] = 2;
    d[1][0] = 3;
    d[1][1] = 4;
    f[0][0] = 5;
    f[0][1] = 6;
    f[1][0] = 7;
    f[1][1] = 8;
  }
  void print() {
    std::cout << "MyTestData: a=" << a << " b=" << b << " s=" << s << std::endl;
    for (size_t i = 0; i < 2; i++)
      for (size_t j = 0; j < 2; j++) {
        std::cout << "d[" << i << "][" << j << "]=" << d[i][j] << std::endl;
      }
    for (size_t i = 0; i < 2; i++)
      for (size_t j = 0; j < 2; j++) {
        std::cout << "f[" << i << "][" << j << "]=" << f[i][j] << std::endl;
      }
  }

  bool operator==(const MyTestData& rhs) const {
    if (a != rhs.a) {
      return false;
    }
    if (b != rhs.b) {
      return false;
    }
    for (size_t i = 0; i < 2; i++)
      for (size_t j = 0; j < 2; j++) {
        if (d[i][j] != rhs.d[i][j]) {
          return false;
        }
        if (f[i][j] != rhs.f[i][j]) {
          return false;
        }
      }
    if (s != rhs.s) {
      return false;
    }
    return true;
  }
  bool operator!=(const MyTestData& rhs) const { return !operator==(rhs); }

private:
  int a;
  float b;
  std::string s;
  int d[2][2];
  float f[2][2];

  COND_SERIALIZABLE;
};

#if !defined(__GCCXML__)

#include <boost/serialization/nvp.hpp>

template <class Archive>
void MyTestData::serialize(Archive& ar, const unsigned int) {
  ar& BOOST_SERIALIZATION_NVP(a);
  ar& BOOST_SERIALIZATION_NVP(b);
  ar& BOOST_SERIALIZATION_NVP(s);
  ar& BOOST_SERIALIZATION_NVP(d);
  ar& BOOST_SERIALIZATION_NVP(f);
}

#endif /* !defined(__GCCXML__) */

#endif