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
#include "Alignment/Geners/interface/IOException.hh"
#include "Alignment/Geners/interface/ItemLocation.hh"
#include "Alignment/Geners/interface/streamposIO.hh"

namespace gs {
  bool ItemLocation::operator==(const ItemLocation &r) const {
    if (pos_ != r.pos_)
      return false;
    if (URI_ != r.URI_)
      return false;
    // If global URI does not exist, local URI must coincide exactly.
    // If global URI exists, local URI may or may not be defined.
    if (!URI_.empty()) {
      if (!cachedItemURI_.empty() && !r.cachedItemURI_.empty())
        if (cachedItemURI_ != r.cachedItemURI_)
          return false;
    } else if (cachedItemURI_ != r.cachedItemURI_)
      return false;
    return true;
  }

  bool ItemLocation::write(std::ostream &of) const {
    // The code for storing the stream offset is necessarily
    // going to be implementation-dependent. The C++ standard
    // does not specify std::streampos with enough detail.
    write_pod(of, pos_);
    write_pod(of, URI_);
    write_pod(of, cachedItemURI_);
    return !of.fail();
  }

  ItemLocation *ItemLocation::read(const ClassId &id, std::istream &in) {
    static const ClassId current(ClassId::makeId<ItemLocation>());
    current.ensureSameId(id);

    std::streampos pos;
    read_pod(in, &pos);

    std::string globURI;
    read_pod(in, &globURI);

    std::string cachedItemURI;
    read_pod(in, &cachedItemURI);

    if (in.fail())
      throw IOReadFailure("In ItemLocation::read: input stream failure");

    return new ItemLocation(pos, globURI.c_str(), cachedItemURI.c_str());
  }
}  // namespace gs