text: /**
   * Copyright 2013 JDSU
   * File: field_value_integer_be.h
   * Author: Andy Lai (Andy.Lai@jdsu.com)
   * Purpose: definition of class FieldValueIntegerBE
   * the value to compare is in big_endian
   */
  #ifndef XTREME_COMMON_PUBSUB_FILTER_FIELD_VALUE_INTEGER_BE_H_
  #define XTREME_COMMON_PUBSUB_FILTER_FIELD_VALUE_INTEGER_BE_H_
  #include <endian.h>
  #include "xtreme/common/pubsub_filter/field_value.h"
  #include "xtreme/common/pubsub_filter/field_value_exception.h"
  namespace xtreme {
  namespace filter {
  // T includes: int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t,int64_t, uint64_t
  template<typename T>
  class FieldValueIntegerBE : public FieldValue {
   public:
    FieldValueIntegerBE(T value, FieldValueType type) : FieldValue(type),
      value_(value) {
  #if __BYTE_ORDER == __LITTLE_ENDIAN
      if (sizeof(T) == 2)
        value_ = htobe16(value_);
      else if (sizeof(T) == 4)
        value_ = htobe32(value_);
      else if (sizeof(T) == 8)
        value_ = htobe64(value_);
  #endif
    }
    virtual bool operator ==(const FieldValue& b) const {
      if (b.GetFieldValueType() != GetFieldValueType())
        return false;
      return value_ == ((FieldValueIntegerBE&)b).value_;
    }
    virtual bool operator ==(const T& b) const {
      return value_ == b;
    }
    virtual bool operator <(const FieldValue& b) const throw(InvalidFieldValueException) {
      if (b.GetFieldValueType() != GetFieldValueType())
        throw InvalidFieldValueException("Type of both FieldValue"
            " is not same, so they can't do comparison");
      T value_b = ((FieldValueIntegerBE&)b).value_;
      return memcmp(&value_ , &value_b, sizeof(T)) < 0;
    }
    virtual bool operator <(const T& b) const {
      return memcmp(&value_, &b, sizeof(T)) < 0;
    }
    virtual bool operator >(const FieldValue& b) const throw(InvalidFieldValueException) {
      if (b.GetFieldValueType() != GetFieldValueType())
        throw InvalidFieldValueException("Type of both FieldValue"
            " is not same, so they can't do comparison");
      T value_b = ((FieldValueIntegerBE&)b).value_;
      return memcmp(&value_, &value_b, sizeof(T)) > 0;
    }
    virtual bool operator >(const T& b) const {
      return memcmp(&value_, &b, sizeof(T)) > 0;
    }
    T ToInteger() const {
      return value_;
    }
    virtual ~FieldValueIntegerBE() {
    }
  
   protected:
    T value_;
  };
  }
  }
  #endif  // XTREME_COMMON_PUBSUB_FILTER_FIELD_VALUE_INTEGER_BE_H_
  