<commit_before>/*ckwg +5
 * Copyright 2011-2012 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#include <vistk/pipeline/stamp.h>

#include <boost/python/class.hpp>
#include <boost/python/def.hpp>
#include <boost/python/module.hpp>

/**
 * \file stamp.cxx
 *
 * \brief Python bindings for \link vistk::stamp\endlink.
 */

using namespace boost::python;

static bool stamp_eq(vistk::stamp_t const& self, vistk::stamp_t const& other);
static bool stamp_lt(vistk::stamp_t const& self, vistk::stamp_t const& other);

BOOST_PYTHON_MODULE(stamp)
{
  def("new_stamp", &vistk::stamp::new_stamp
    , "Creates a new stamp.");
  def("incremented_stamp", &vistk::stamp::incremented_stamp
    , (arg("stamp"))
    , "Creates a stamp that is greater than the given stamp.");

  /// \todo Wrap with @total_ordering decorator.
  class_<vistk::stamp_t>("Stamp"
    , "An identifier to help synchronize data within the pipeline."
    , no_init)
    .def("__eq__", stamp_eq)
    .def("__lt__", stamp_lt)
  ;
}

bool
stamp_eq(vistk::stamp_t const& self, vistk::stamp_t const& other)
{
  return (*self == *other);
}

bool
stamp_lt(vistk::stamp_t const& self, vistk::stamp_t const& other)
{
  return (*self < *other);
}<commit_msg>Decorate the stamp class with total_ordering<commit_after>/*ckwg +5
 * Copyright 2011-2012 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#include <vistk/pipeline/stamp.h>

#include <boost/python/class.hpp>
#include <boost/python/def.hpp>
#if PY_VERSION_HEX >= 0x02070000
#include <boost/python/import.hpp>
#endif
#include <boost/python/module.hpp>
#if PY_VERSION_HEX >= 0x02070000
#include <boost/python/scope.hpp>
#endif

/**
 * \file stamp.cxx
 *
 * \brief Python bindings for \link vistk::stamp\endlink.
 */

using namespace boost::python;

static bool stamp_eq(vistk::stamp_t const& self, vistk::stamp_t const& other);
static bool stamp_lt(vistk::stamp_t const& self, vistk::stamp_t const& other);

BOOST_PYTHON_MODULE(stamp)
{
  def("new_stamp", &vistk::stamp::new_stamp
    , "Creates a new stamp.");
  def("incremented_stamp", &vistk::stamp::incremented_stamp
    , (arg("stamp"))
    , "Creates a stamp that is greater than the given stamp.");

  class_<vistk::stamp_t>("Stamp"
    , "An identifier to help synchronize data within the pipeline."
    , no_init)
    .def("__eq__", stamp_eq)
    .def("__lt__", stamp_lt)
  ;

  // Equivalent to:
  //   @total_ordering
  //   class Stamp(object):
  //       ...
#if PY_VERSION_HEX >= 0x02070000
  object const functools = import("functools");
  object const total_ordering = functools.attr("total_ordering");

  object const stamp = scope().attr("Stamp");

  scope().attr("Stamp") = total_ordering(stamp);
#endif
}

bool
stamp_eq(vistk::stamp_t const& self, vistk::stamp_t const& other)
{
  return (*self == *other);
}

bool
stamp_lt(vistk::stamp_t const& self, vistk::stamp_t const& other)
{
  return (*self < *other);
}
{'fraction_non_alphanumeric': 0.1432152930115951, 'fraction_numerical': 0.018489501723597618, 'mean_word_length': 4.512953367875648, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, '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': '5926882', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1158, 'n_words': 285}