<commit_before>///////////////////////////////////////////////////////////////////////////////
// \author (c) <NAME> (<EMAIL>)
//             2011-2017, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// This file is part of the decom library.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief decom base class
// This class is the lowest base class of the decom library
// It represents and abstracts any layer of the OSI model.
// All other classes are derived from this class.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef _DECOM_LAYER_H_
#define _DECOM_LAYER_H_

#include <cstdint>
#include <cstddef>    // for size_t

// decom configuration file
#include "decom_cfg.h"

#include "msg.h"
#include "log.h"

// common utils
#include "util/util.h"
#include "util/event.h"

///////////////////////////////////////////////////////////////////////////////

// IMPL_HEADER macro for including platform specific implementations
// usage:
// #include IMPL_HEADER(util/timer.h)
#define STRINGIFY(x) #x
#define XSTRINGIFY(d) STRINGIFY(d)
#define PATH(header, platform) XSTRINGIFY(platform ## header)
#define IMPL(s) ./impl/s/
#define IMPL_HEADER(header) PATH(header, IMPL(PLATFORM))


///////////////////////////////////////////////////////////////////////////////

namespace decom {

/**
 * endpoint identifier
 * An endpoint consists of a 16 byte address and a 32 bit port
 */
struct eid
{
  union addr_type {
    std::uint8_t  addr[16];
    std::uint32_t addr32[4];
    std::uint64_t addr64[2];
  };


  // ctor
  eid()
  {
    addr_.addr64[0] = addr_.addr64[1] = 0U;
    port_                             = 0U;
  }


  // port ctor
  eid(std::uint32_t port)
    : port_(port)
  {
    addr_.addr64[0] = addr_.addr64[1] = 0U;
  }


  // addr access
  inline addr_type const& addr() const { return addr_; }
  inline addr_type& addr() { return addr_; }


  // port access
  inline std::uint32_t port() const { return port_; }
  inline void port(std::uint32_t val) { port_ = val; }


  // is_any test
  inline bool is_any() const
  { return (port_ == 0U) && (addr_.addr64[0] == 0U) && (addr_.addr64[1] == 0U); }


  // assignment operator
  eid& operator=(eid const& id)
  {
    addr_ = id.addr();
    port_ = id.port();
    return *this;
  }


  // comparisons
  inline bool operator==(eid const& other) const
  {
    return (port_ == other.port())                &&
      (addr_.addr64[0] == other.addr().addr64[0]) &&
      (addr_.addr64[1] == other.addr().addr64[1]);
  }


  inline bool operator!=(eid const& other) const
  { return !(*this == other); }


private:
  addr_type     addr_;
  std::uint32_t port_;
};


/**
 * Static definition of eid_any - used when the eid doesn't care
 */
static const eid eid_any;


// decom base class
// This class abstracts a (any) layer of the OSI model<commit_msg>feat(layer): added eid < operator<commit_after>///////////////////////////////////////////////////////////////////////////////
// \author (c) <NAME> (<EMAIL>)
//             2011-2017, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// This file is part of the decom library.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief decom base class
// This class is the lowest base class of the decom library
// It represents and abstracts any layer of the OSI model.
// All other classes are derived from this class.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef _DECOM_LAYER_H_
#define _DECOM_LAYER_H_

#include <cstdint>
#include <cstddef>    // for size_t

// decom configuration file
#include "decom_cfg.h"

#include "msg.h"
#include "log.h"

// common utils
#include "util/util.h"
#include "util/event.h"

///////////////////////////////////////////////////////////////////////////////

// IMPL_HEADER macro for including platform specific implementations
// usage:
// #include IMPL_HEADER(util/timer.h)
#define STRINGIFY(x) #x
#define XSTRINGIFY(d) STRINGIFY(d)
#define PATH(header, platform) XSTRINGIFY(platform ## header)
#define IMPL(s) ./impl/s/
#define IMPL_HEADER(header) PATH(header, IMPL(PLATFORM))


///////////////////////////////////////////////////////////////////////////////

namespace decom {

/**
 * endpoint identifier
 * An endpoint consists of a 16 byte address and a 32 bit port
 */
struct eid
{
  union addr_type {
    std::uint8_t  addr[16];
    std::uint32_t addr32[4];
    std::uint64_t addr64[2];
  };


  // ctor
  eid()
  {
    addr_.addr64[0] = addr_.addr64[1] = 0U;
    port_                             = 0U;
  }


  // port ctor
  eid(std::uint32_t port)
    : port_(port)
  {
    addr_.addr64[0] = addr_.addr64[1] = 0U;
  }


  // addr access
  inline addr_type const& addr() const { return addr_; }
  inline addr_type& addr() { return addr_; }


  // port access
  inline std::uint32_t port() const { return port_; }
  inline void port(std::uint32_t val) { port_ = val; }


  // is_any test
  inline bool is_any() const
  { return (port_ == 0U) && (addr_.addr64[0] == 0U) && (addr_.addr64[1] == 0U); }


  // assignment operator
  eid& operator=(eid const& id)
  {
    addr_ = id.addr();
    port_ = id.port();
    return *this;
  }


  // comparisons
  inline bool operator==(eid const& other) const
  {
    return (port_ == other.port())                &&
      (addr_.addr64[0] == other.addr().addr64[0]) &&
      (addr_.addr64[1] == other.addr().addr64[1]);
  }


  inline bool operator!=(eid const& other) const
  { return !(*this == other); }


  inline bool operator<(eid const& other) const
  {
    return (port_ < other.port())                 &&
      ((addr_.addr64[1] < other.addr().addr64[1]) ||
       (addr_.addr64[1] == other.addr().addr64[1] && addr_.addr64[0] < other.addr().addr64[0])
      );
  }


private:
  addr_type     addr_;
  std::uint32_t port_;
};


/**
 * Static definition of eid_any - used when the eid doesn't care
 */
static const eid eid_any;


// decom base class
// This class abstracts a (any) layer of the OSI model
{'fraction_non_alphanumeric': 0.18942948876265744, 'fraction_numerical': 0.019264015806371944, 'mean_word_length': 2.2855983772819473, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4237229', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2341, 'n_words': 857}