text:
//            -- basic_request_acceptor.hpp --
//
//            Copyright (c) Darren Garvey 2007.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)
//
////////////////////////////////////////////////////////////////
#ifndef CGI_BASIC_REQUEST_ACCEPTOR_HPP_INCLUDED__
#define CGI_BASIC_REQUEST_ACCEPTOR_HPP_INCLUDED__

#include <boost/noncopyable.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/basic_io_object.hpp>
#include <boost/asio/ip/basic_endpoint.hpp>
#include <boost/asio/ip/tcp.hpp>
///////////////////////////////////////////////////////////
#include "boost/cgi/detail/throw_error.hpp"
#include "boost/cgi/common/basic_protocol_service.hpp"

BOOST_CGI_NAMESPACE_BEGIN
 namespace common {

  /// The interface class for any *BOOST_CGI_NAMESPACE::acceptor.
  template<typename Protocol>
  class basic_request_acceptor
    //: public boost::asio::basic_io_object<RequestAcceptorService>
    : public boost::asio::basic_io_object<
        typename protocol_traits<Protocol>::acceptor_service
      >
    //, private boost::noncopyable
  {
  public:
    //  typedef impl_type;
    typedef Protocol                               protocol_type;
    typedef protocol_traits<protocol_type>         traits;
    typedef typename traits::acceptor_service      service_type;
    typedef typename traits::endpoint_type         endpoint_type;
    typedef typename traits::native_handle_type    native_handle_type;
    typedef typename traits::protocol_service_type protocol_service_type;

    typedef typename
        service_type::accept_handler_type          accept_handler_type;

    template<typename IoContextProvider>
    explicit basic_request_acceptor(
          common::basic_protocol_service<protocol_type, IoContextProvider>& ps)
      : boost::asio::basic_io_object<service_type>(ps.get_io_context())
    {
      this->get_service().set_protocol_service(this->get_implementation(), ps);

      boost::system::error_code ec;
      if (this->get_service().default_init(this->get_implementation(), ec)) {
        detail::throw_error(ec);
      }
    }

    template<typename IoContextProvider, typename InternetProtocol>
    explicit basic_request_acceptor(
          common::basic_protocol_service<protocol_type, IoContextProvider>& ps,
          const boost::asio::ip::basic_endpoint<InternetProtocol>& endpoint,
          bool reuse_addr = true)
      : boost::asio::basic_io_object<service_type>(ps.get_io_context())
    {
      this->get_service().set_protocol_service(this->get_implementation(), ps);

      boost::system::error_code ec;
      open(endpoint.protocol(), ec);
      detail::throw_error(ec);
      if (reuse_addr)
      {
        set_option(boost::asio::socket_base::reuse_address(true), ec);
        detail::throw_error(ec);
      }
      bind(endpoint, ec);
      detail::throw_error(ec);
      listen(boost::asio::socket_base::max_listen_connections, ec);
      detail::throw_error(ec);
    }

    template<typename IoContextProvider, typename InternetProtocol>
    explicit basic_request_acceptor(
          common::basic_protocol_service<protocol_type, IoContextProvider>& ps,
          const InternetProtocol& ip,
          const native_handle_type& native_acceptor)
      : boost::asio::basic_io_object<service_type>(ps.get_io_context())
    {
      this->get_service().set_protocol_service(this->get_implementation(), ps);
      boost::system::error_code ec;
      this->get_service().assign(this->get_implementation(), ip, native_acceptor, ec);
      detail::throw_error(ec);
    }

    ~basic_request_acceptor()
    {
    }

    protocol_service_type& protocol_service() const
    {
      return this->get_service().protocol_service(this->get_implementation());
    }

    /// Check if the acceptor is open
    bool is_open()
    {
      return this->get_service().is_open(this->get_implementation());
    }

    /// Open the acceptor
    template<typename InternetProtocol>
    void open(const InternetProtocol& protocol)
    {
      boost::system::error_code ec;
      this->get_service().open(this->get_implementation(), protocol, ec);
      detail::throw_error(ec);
    }

    /// Open the acceptor
    template<typename InternetProtocol>
    boost::system::error_code
      open(const InternetProtocol& protocol, boost::system::error_code& ec)
    {
      return this->get_service().open(this->get_implementation(), protocol, ec);
    }

    /// Set the acceptor to listen
    void listen(int backlog = boost::asio::socket_base::max_listen_connections)
    {
      boost::system::error_code ec;
      this->get_service().listen(this->get_implementation(), backlog, ec);
      detail::throw_error(ec);
    }

    /// Set the acceptor to listen
    boost::system::error_code
      listen(int backlog, boost::system::error_code& ec)
    {
      return this->get_service().listen(this->get_implementation(), backlog, ec);
    }

    template<typename Endpoint>
    void bind(Endpoint& ep)
    {
      boost::system::error_code ec;
      this->get_service().bind(this->get_implementation(), ep, ec);
      detail::throw_error(ec);
      this->get_implementation().endpoint_ = ep;
    }

    template<typename Endpoint>
    boost::system::error_code
      bind(Endpoint& ep, boost::system::error_code& ec)
    {
      ec = this->get_service().bind(this->get_implementation(), ep, ec);
      this->get_implementation().endpoint_ = ep;
      return ec;
    }

    /// Set socket option
    template<typename SettableSocketOption>
    void set_option(const SettableSocketOption& option)
    {
      boost::system::error_code ec;
      this->get_service().set_option(this->get_implementation(), option, ec);
      detail::throw_error(ec);
    }

    /// Set socket option
    template<typename SettableSocketOption>
    boost::system::error_code
      set_option(const SettableSocketOption& option, boost::system::error_code& ec)
    {
      return this->get_service().set_option(this->get_implementation(), option, ec);
    }

    /// Cancel all asynchronous operations associated with the acceptor.
    boost::system::error_code
      cancel()
    {
      return this->get_service().cancel(this->get_implementation());
    }

    /// Close the acceptor
    void close()
    {
      boost::system::error_code ec;
      this->get_service().close(this->get_implementation(), ec);
      detail::throw_error(ec);
    }

    /// Close the acceptor
    boost::system::error_code
      close(boost::system::error_code& ec)
    {
      return this->get_service().close(this->get_implementation(), ec);
    }

    template<typename InternetProtocol>
    void assign(InternetProtocol protocol, const native_handle_type& native_acceptor)
    {
      boost::system::error_code ec;
      this->get_service().assign(this->get_implementation(), protocol, native_acceptor, ec);
      detail::throw_error(ec);
    }

    template<typename InternetProtocol>
    boost::system::error_code
      assign(InternetProtocol protocol, const native_handle_type& native_acceptor
            , boost::system::error_code& ec)
    {
      return this->get_service().assign(this->get_implementation(), protocol
                                 , native_acceptor, ec);
    }

    /// Accept one request and handle it with `handler`.
    int accept(accept_handler_type handler)
    {
      boost::system::error_code ec;
      int status = this->get_service().accept(this->get_implementation(), handler, &this->get_implementation().endpoint_, ec);
      detail::throw_error(ec);
      return status;
    }

    int accept(accept_handler_type handler, boost::system::error_code& ec)
    {
      return this->get_service().accept(this->get_implementation(), handler, &this->get_implementation().endpoint_, ec);
    }

    void async_accept(accept_handler_type handler)
    {
      this->get_service().async_accept(this->get_implementation(), handler);
    }

    template<typename CommonGatewayRequest>
    void accept(CommonGatewayRequest& request)
    {
      boost::system::error_code ec;
      this->get_service().accept(this->get_implementation(), request, &this->get_implementation().endpoint_, ec);
      detail::throw_error(ec);
    }

    /// Accept one request
    template<typename CommonGatewayRequest>
    boost::system::error_code
      accept(CommonGatewayRequest& request, boost::system::error_code& ec)
    {
      return this->get_service().accept(this->get_implementation(), request, &this->get_implementation().endpoint_, ec);
    }

    template<typename CommonGatewayRequest>
    boost::system::error_code
      accept(CommonGatewayRequest& request, endpoint_type& ep
            , boost::system::error_code& ec)
    {
      return this->get_service().accept(this->get_implementation(), request, &ep, ec);
    }

    /// Asynchronously accept one request
    template<typename CommonGatewayRequest, typename Handler>
    void async_accept(CommonGatewayRequest& request, Handler handler)
    {
      this->get_service().async_accept(this->get_implementation(), request, handler);
    }

    endpoint_type
      local_endpoint()
    {
      boost::system::error_code ec;
      endpoint_type ep(this->get_service().local_endpoint(this->get_implementation(), ec));
      detail::throw_error(ec);
      return ep;
    }

    endpoint_type
      local_endpoint(boost::system::error_code& ec) const
    {
      return this->get_service().local_endpoint(this->get_implementation(), ec);
    }

    native_handle_type
    native()
    {
      return this->get_service().native(this->get_implementation());
    }

    bool is_cgi()
    {
      return this->get_service().is_cgi(this->get_implementation());
    }
  };

 } // namespace common
BOOST_CGI_NAMESPACE_END

#endif // CGI_BASIC_REQUEST_ACCEPTOR_HPP_INCLUDED__

ext: hpp


text:
/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You
 * may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. See accompanying
 * LICENSE file.
 */
#include <iostream>
#include <sstream>
#include <string>

#include <ace/ACE.h>
#undef ACE_SCANDIR_CMP_USES_VOIDPTR
#include <ace/OS.h>
#include <ace/Task.h>
#include <ace/Barrier.h>

//#include <boost/lexical_cast.hpp>

#include "GFXDClient.h"

extern "C"
{
#  include <stdio.h>
}

using namespace com::pivotal::gemfirexd;
using namespace com::pivotal::gemfirexd::client;

extern "C"
{
  extern void ProfilerEnable();
}

class SelectTask: public ACE_Task_Base
{
private:
  std::string& m_host;
  int m_port;
  ACE_Barrier& m_barrier;
  const int m_numRows;
  const int m_numRuns;

public:
  inline SelectTask(std::string& host, int port, ACE_Barrier& barrier,
      int numRows, int numRuns) :
      m_host(host), m_port(port), m_barrier(barrier), m_numRows(numRows), m_numRuns(
          numRuns)
  {
  }

  int svc()
  {
    AutoPtr<PreparedStatement> pstmt;
    Parameters params;
    AutoPtr<ResultSet> rs;
    ResultSet::const_iterator rsIter;

    int status = 0;

    try {
      Connection conn;
      std::map<std::string, std::string> props;
      //props["binary-protocol"] = "true";
      conn.open(m_host, m_port, props);
      pstmt = conn.prepareStatement("SELECT * FROM new_order "
          "WHERE no_d_id = ? AND no_w_id = ? AND no_o_id = ?");

      std::ostringstream msg;
      msg << "Starting timed selects for thread " << ACE_OS::thr_self() << '\n';
      std::cout << msg.str();

      // wait for all threads
      m_barrier.wait();

      int rowNum, w_id;

      for (int i = 1; i <= m_numRuns; i++) {
        rowNum = (i % m_numRows) + 1;
        w_id = (rowNum % 98);
        params.addInt(w_id).addInt(w_id).addInt(rowNum);

        rs = pstmt->executeQuery(params);

        int numResults = 0;
        for (rsIter = rs->begin(); rsIter != rs->end(); ++rsIter) {
          rsIter->getInt(1);
          //rsIter->getString(2);
          numResults++;
        }
        rs->close();
        if (numResults == 0) {
          std::cerr << "unexpected 0 results for w_id, d_id " << w_id
              << std::endl;
          status = -1;
        }
        params.clear();
      }
    } catch (SQLException& sqle) {
      std::cerr << "Failed with " << stack(sqle);
      const SQLException* next = sqle.getNextException();
      if (next != NULL) {
        std::cerr << *next;
      }
      std::cerr << std::endl;
    } catch (std::exception& ex) {
      std::cerr << "ERROR: failed with exception: " << ex << std::endl;
    } catch (...) {
      std::cerr << "ERROR: failed with unknown exception..." << std::endl;
    }
    return status;
  }
};

/**
 * Simple performance test given n threads of execution.
 */
int main(int argc, char** argv)
{
  if (argc != 3 && argc != 4) {
    std::cerr << "Usage: <script> <server> <port> [<threads>]\n";
    return 1;
  }
  std::string server = argv[1];
  //int port = boost::lexical_cast<int>(argv[2]);
  int port = ::atoi(argv[2]);
  int numThreads = 1;
  if (argc == 4) {
    numThreads = ACE_OS::atoi(argv[3]);
    if (numThreads <= 0) {
      std::cerr << "unexpected number of threads " << numThreads << "\n";
      return 1;
    }
  }

  ACE_Time_Value start, end;
  time_t startSecs, endSecs;
  suseconds_t startUSecs, endUSecs;
  SelectTask** tasks = NULL;
  //ProfilerEnable();
  try {
    Connection conn;
    AutoPtr<PreparedStatement> pstmt;
    Parameters params;
    AutoPtr<ResultSet> rs;
    ResultSet::const_iterator rsIter;

    //SystemProperties::setProperty(ClientProperty::LOG_FILE_NAME, "thrift-client.log");
    //SystemProperties::setProperty(ClientProperty::LOG_LEVEL_NAME, "config");

    if (LogWriter::INFO_ENABLED()) {
      LogWriter::INFO() << "Connecting to " << server << ':' << port << LogWriter::NEWLINE;
    }
    std::map<std::string, std::string> props;
    //props["binary-protocol"] = "true";
    //props["log-file"] = "thrift-client.log";
    conn.open(server, port, props);

    conn.executeUpdate("drop table if exists new_order");
    conn.executeUpdate("drop table if exists customer");

    // create the tables
    conn.executeUpdate("create table customer ("
        "c_w_id         integer        not null,"
        "c_d_id         integer        not null,"
        "c_id           integer        not null,"
        "c_discount     decimal(4,4),"
        "c_credit       char(2),"
        "c_last         varchar(16),"
        "c_first        varchar(16),"
        "c_credit_lim   decimal(12,2),"
        "c_balance      decimal(12,2),"
        "c_ytd_payment  float,"
        "c_payment_cnt  integer,"
        "c_delivery_cnt integer,"
        "c_street_1     varchar(20),"
        "c_street_2     varchar(20),"
        "c_city         varchar(20),"
        "c_state        char(2),"
        "c_zip          char(9),"
        "c_phone        char(16),"
        "c_since        timestamp,"
        "c_middle       char(2),"
        "c_data         varchar(500)"
        ") partition by (c_w_id) redundancy 1");
    conn.executeUpdate("create table new_order ("
        "no_w_id  integer   not null,"
        "no_d_id  integer   not null,"
        "no_o_id  integer   not null,"
        "no_name  varchar(100) not null"
        ") partition by (no_w_id) colocate with (customer) redundancy 1");
    conn.executeUpdate("alter table customer add constraint pk_customer "
        "primary key (c_w_id, c_d_id, c_id)");
    conn.executeUpdate("create index ndx_customer_name "
        "on customer (c_w_id, c_d_id, c_last)");
    conn.executeUpdate("alter table new_order add constraint pk_new_order "
        "primary key (no_w_id, no_d_id, no_o_id)");
    conn.executeUpdate("create index ndx_neworder_w_id_d_id "
        "on new_order (no_w_id, no_d_id)");
    conn.execute("create index ndx_neworder_w_id_d_id_o_id "
        "on new_order (no_w_id, no_d_id, no_o_id)");

    std::cout << "Created tables\n";
    std::cout << "Will use " << numThreads << " threads for selects\n";

    const int numRows = 10000;

    pstmt = conn.prepareStatement("insert into new_order values "
        "(?, ?, ?, ?)");

    int id, w_id, count;
    char name[100];

    std::cout << "Starting inserts\n";
    for (id = 1; id <= numRows; id++) {
      w_id = (id % 98);
      ::sprintf(name, "customer-with-order%d%d", id, w_id);
      params.addInt(w_id).addInt(w_id).addInt(id).addString(name);

      count = pstmt->executeUpdate(params);
      if (count != 1) {
        std::cerr << "unexpected count for single insert: " << count << "\n";
        return 2;
      }
      params.clear();
      if ((id % 500) == 0) {
        std::cout << "Completed " << id << " inserts ...\n";
      }
    }

    pstmt = conn.prepareStatement("SELECT * FROM new_order "
        "WHERE no_d_id = ? AND no_w_id = ? AND no_o_id = ?");

    std::cout << "Starting warmup selects\n";
    const int numRuns = 50000;
    int rowNum;

    // warmup for the selects
    for (int i = 1; i <= numRuns; i++) {
      rowNum = (i % numRows) + 1;
      w_id = (rowNum % 98);
      params.addInt(w_id).addInt(w_id).addInt(rowNum);

      rs = pstmt->executeQuery(params);

      int numResults = 0;
      for (rsIter = rs->begin(); rsIter != rs->end(); ++rsIter) {
        rsIter->getInt(1);
        rsIter->getString(2);
        numResults++;
      }
      rs->close();
      params.clear();
      if (numResults == 0) {
        std::cerr << "unexpected 0 results for w_id, d_id " << w_id << "\n";
        return 2;
      }
      if ((i % 500) == 0) {
        std::cout << "Completed " << i << " warmup selects ...\n";
      }
    }

    ACE::init();
    std::cout << "Starting timed selects with " << numThreads << " threads\n";
    // timed runs
    ACE_Barrier barrier(numThreads);

    if (numThreads > 1) {
      // create the other threads
      tasks = new SelectTask*[numThreads - 1];
      for (int i = 0; i < (numThreads - 1); i++) {
        tasks[i] = new SelectTask(server, port, barrier, numRows, numRuns);
        tasks[i]->activate();
      }
    }
    barrier.wait();
    start = ACE_OS::gettimeofday();
    for (int i = 1; i <= numRuns; i++) {
      rowNum = (i % numRows) + 1;
      w_id = (rowNum % 98);
      params.addInt(w_id).addInt(w_id).addInt(rowNum);

      rs = pstmt->executeQuery(params);

      int numResults = 0;
      for (rsIter = rs->begin(); rsIter != rs->end(); ++rsIter) {
        rsIter->getInt(1);
        //rsIter->getString(2);
        numResults++;
      }
      rs->close();
      params.clear();
      if (numResults == 0) {
        std::cerr << "unexpected 0 results for w_id, d_id " << w_id << "\n";
      }
    }
  } catch (SQLException& sqle) {
    std::cerr << "Failed with " << stack(sqle);
    const SQLException* next = sqle.getNextException();
    if (next != NULL) {
      std::cerr << *next;
    }
    std::cerr << std::endl;
  } catch (std::exception& ex) {
    std::cerr << "ERROR: failed with exception: " << ex << std::endl;
  } catch (...) {
    std::cerr << "ERROR: failed with unknown exception..." << std::endl;
  }

  if (numThreads > 1 && tasks != NULL) {
    // wait for other threads to join
    for (int i = 0; i < (numThreads - 1); i++) {
      tasks[i]->wait();
    }
  }
  end = ACE_OS::gettimeofday();

  startSecs = start.sec();
  startUSecs = start.usec();
  endSecs = end.sec();
  endUSecs = end.usec();

  if (startUSecs > endUSecs) {
    endSecs--;
    endUSecs += 1000000;
  }
  std::cout << "Time taken: " << (endSecs - startSecs) << '.'
      << (endUSecs - startUSecs) << "s\n";

  // cleanup
  if (numThreads > 1 && tasks != NULL) {
    for (int i = 0; i < (numThreads - 1); i++) {
      delete tasks[i];
    }
    delete [] tasks;
  }

  ACE::fini();

  return 0;
}

ext: cpp

max_stars_repo_name: xyxiaoyou/snappy-store

max_issues_repo_name: xyxiaoyou/snappy-store

max_forks_repo_name: xyxiaoyou/snappy-store


text:
// Copyright 2022 PingCAP, Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include <boost/program_options.hpp>
#include <Poco/Logger.h>
#include <Poco/ConsoleChannel.h>
#include <Poco/FormattingChannel.h>
#include <Poco/PatternFormatter.h>
#include <Poco/AutoPtr.h>

#include <Common/Config/ConfigProcessor.h>
#include <Common/Exception.h>
#include <Common/Config/TOMLConfiguration.h>

static void setupLogging(const std::string & log_level)
{
    Poco::AutoPtr<Poco::ConsoleChannel> channel(new Poco::ConsoleChannel);
    Poco::AutoPtr<Poco::PatternFormatter> formatter(new Poco::PatternFormatter);
    formatter->setProperty("pattern", "%L%Y-%m-%d %H:%M:%S.%i <%p> %s: %t");
    Poco::AutoPtr<Poco::FormattingChannel> formatting_channel(new Poco::FormattingChannel(formatter, channel));
    Poco::Logger::root().setChannel(formatting_channel);
    Poco::Logger::root().setLevel(log_level);
}

static std::string extractFromConfig(
        const std::string & config_path, const std::string & key, bool try_get = false)
{
    ConfigProcessor processor(config_path, /* log_to_console = */ false);
    auto config_conf = processor.processConfig();
    ConfigurationPtr configuration(new DB::TOMLConfiguration(config_conf));
    // do not throw exception if not found
    if (try_get)
        return configuration->getString(key, "");
    return configuration->getString(key);
}

int mainEntryClickHouseExtractFromConfig(int argc, char ** argv)
{
    bool print_stacktrace = false;
    bool try_get = false;
    std::string log_level;
    std::string config_path;
    std::string key;

    namespace po = boost::program_options;

    po::options_description options_desc("Allowed options");
    options_desc.add_options()
        ("help", "produce this help message")
        ("stacktrace", po::bool_switch(&print_stacktrace), "print stack traces of exceptions")
        ("try", po::bool_switch(&try_get), "Do not warn about missing keys")
        ("log-level", po::value<std::string>(&log_level)->default_value("error"), "log level")
        ("config-file,c", po::value<std::string>(&config_path)->required(), "path to config file")
        ("key,k", po::value<std::string>(&key)->required(), "key to get value for");

    po::positional_options_description positional_desc;
    positional_desc.add("config-file", 1);
    positional_desc.add("key", 1);

    try
    {
        po::variables_map options;
        po::store(po::command_line_parser(argc, argv).options(options_desc).positional(positional_desc).run(), options);

        if (options.count("help"))
        {
            std::cerr << "Preprocess config file and extract value of the given key." << std::endl
                << std::endl;
            std::cerr << "Usage: clickhouse extract-from-config [options]" << std::endl
                << std::endl;
            std::cerr << options_desc << std::endl;
            return 0;
        }

        po::notify(options);

        setupLogging(log_level);
        std::cout << extractFromConfig(config_path, key, try_get) << std::endl;
    }
    catch (...)
    {
        std::cerr << DB::getCurrentExceptionMessage(print_stacktrace, true) << std::endl;
        return DB::getCurrentExceptionCode();
    }

    return 0;
}

max_stars_repo_name: wuchong/tiflash

max_issues_repo_name: dragonly/tiflash

max_forks_repo_name: dragonly/tiflash


text:
//---------------------------------------------------------------------------//
//!
//! \file   DataGen_Xsdir.hpp
//! \author Alex Robinson
//! \brief  The xsdir class declaration.
//!
//---------------------------------------------------------------------------//

#ifndef DATA_GEN_XSDIR_HPP
#define DATA_GEN_XSDIR_HPP

// Boost Includes
#include <boost/unordered_map.hpp>

// Trilinos Includes
#include <Teuchos_ParameterList.hpp>
#include <Teuchos_RCP.hpp>
#include <Teuchos_Array.hpp>

// FRENSIE Includes
#include "DataGen_XsdirEntry.hpp"

namespace DataGen{

//! The xsdir
class Xsdir
{

public:

  //! Typedef for the id entries map
  typedef boost::unordered_map<unsigned,
			       Teuchos::Array<Teuchos::RCP<XsdirEntry> > >
  IdEntriesMap;

  //! Typedef for the id entry map
  typedef boost::unordered_map<unsigned,Teuchos::RCP<XsdirEntry> > IdEntryMap;

  //! Constructor
  Xsdir( const std::string& xsdir_file_name );

  //! Destructor
  ~Xsdir()
  { /* ... */ }

  //! Export the xsdir file to a parameter list
  void exportInfo( Teuchos::ParameterList& parameter_list ) const;

private:

  // Compare the versions of two entries
  static bool compareVersions( const Teuchos::RCP<XsdirEntry>& entry_a,
			       const Teuchos::RCP<XsdirEntry>& entry_b );

  // Compare the ids and version of two entries (id 1st, version 2nd)
  static bool compareIdsAndVersions( const Teuchos::RCP<XsdirEntry>& entry_a,
				     const Teuchos::RCP<XsdirEntry>& entry_b );

  // Export the continuous energy neutron entries
  void exportCENeutronEntries( Teuchos::ParameterList& parameter_list ) const;

  // Export the S(alpha,beta) entries
  void exportSAlphaBetaEntries( Teuchos::ParameterList& parameter_list ) const;

  // Export the photonuclear entries
  void exportPhotonuclearEntries(
				Teuchos::ParameterList& parameter_list ) const;

  //! Export the epr entries
  void exportEPREntries( Teuchos::ParameterList& parameter_list ) const;

  // The continuous energy neutron xsdir entries
  Teuchos::Array<Teuchos::RCP<XsdirEntry> > d_ce_neutron_xsdir_entries;

  // The S(alpha,beta) entries
  Teuchos::Array<Teuchos::RCP<XsdirEntry> > d_sab_xsdir_entries;

  // The photonuclear xsdir entries map - for quick lookup
  IdEntriesMap d_photonuclear_xsdir_entries_map;

  Teuchos::Array<Teuchos::RCP<XsdirEntry> > d_photonuclear_xsdir_entries;

  // The electron-photon-relaxation xsdir entries map - for quick lookup
  IdEntryMap d_epr_xsdir_entries_map;

  // The electron-photon-relaxation xsdir entries
  Teuchos::Array<Teuchos::RCP<XsdirEntry> > d_epr_xsdir_entries;
};

} // end DataGen namespace

#endif // end DATA_GEN_XSDIR_HPP

//---------------------------------------------------------------------------//
// end DataGen_Xsdir.hpp
//---------------------------------------------------------------------------//


text:
// Copyright (c) 2016 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_PROCESS_DETAIL_WINDOWS_JOB_WORKAROUND_HPP_
#define BOOST_PROCESS_DETAIL_WINDOWS_JOB_WORKAROUND_HPP_

#include <boost/winapi/config.hpp>
#include <boost/winapi/basic_types.hpp>
#include <boost/winapi/dll.hpp>

namespace boost { namespace process { namespace detail { namespace windows { namespace workaround {

//this import workaround is to keep it a header-only library. and enums cannot be imported from the winapi.

extern "C"
{

typedef enum _JOBOBJECTINFOCLASS_ {
      JobObjectBasicAccountingInformation_ = 1, JobObjectBasicLimitInformation_,
      JobObjectBasicProcessIdList_, JobObjectBasicUIRestrictions_,
      JobObjectSecurityLimitInformation_, JobObjectEndOfJobTimeInformation_,
      JobObjectAssociateCompletionPortInformation_, JobObjectBasicAndIoAccountingInformation_,
      JobObjectExtendedLimitInformation_, JobObjectJobSetInformation_,
      JobObjectGroupInformation_,
      JobObjectNotificationLimitInformation_,
      JobObjectLimitViolationInformation_,
      JobObjectGroupInformationEx_,
      JobObjectCpuRateControlInformation_,
      JobObjectCompletionFilter_,
      JobObjectCompletionCounter_,
      JobObjectReserved1Information_ = 18,
      JobObjectReserved2Information_,
      JobObjectReserved3Information_,
      JobObjectReserved4Information_,
      JobObjectReserved5Information_,
      JobObjectReserved6Information_,
      JobObjectReserved7Information_,
      JobObjectReserved8Information_,
      MaxJobObjectInfoClass_
    } JOBOBJECTINFOCLASS_;

typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION_ {
  ::boost::winapi::LARGE_INTEGER_ PerProcessUserTimeLimit;
  ::boost::winapi::LARGE_INTEGER_ PerJobUserTimeLimit;
  ::boost::winapi::DWORD_         LimitFlags;
  ::boost::winapi::SIZE_T_        MinimumWorkingSetSize;
  ::boost::winapi::SIZE_T_        MaximumWorkingSetSize;
  ::boost::winapi::DWORD_         ActiveProcessLimit;
  ::boost::winapi::ULONG_PTR_     Affinity;
  ::boost::winapi::DWORD_         PriorityClass;
  ::boost::winapi::DWORD_         SchedulingClass;
} JOBOBJECT_BASIC_LIMIT_INFORMATION_;

typedef struct _IO_COUNTERS_ {
  ::boost::winapi::ULONGLONG_ ReadOperationCount;
  ::boost::winapi::ULONGLONG_ WriteOperationCount;
  ::boost::winapi::ULONGLONG_ OtherOperationCount;
  ::boost::winapi::ULONGLONG_ ReadTransferCount;
  ::boost::winapi::ULONGLONG_ WriteTransferCount;
  ::boost::winapi::ULONGLONG_ OtherTransferCount;
} IO_COUNTERS_;

typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION_ {
  JOBOBJECT_BASIC_LIMIT_INFORMATION_ BasicLimitInformation;
  IO_COUNTERS_                       IoInfo;
  ::boost::winapi::SIZE_T_   ProcessMemoryLimit;
  ::boost::winapi::SIZE_T_   JobMemoryLimit;
  ::boost::winapi::SIZE_T_   PeakProcessMemoryUsed;
  ::boost::winapi::SIZE_T_   PeakJobMemoryUsed;
} JOBOBJECT_EXTENDED_LIMIT_INFORMATION_;

/*BOOL WINAPI QueryInformationJobObject(
  _In_opt_  HANDLE             hJob,
  _In_      JOBOBJECTINFOCLASS JobObjectInfoClass,
  _Out_     LPVOID             lpJobObjectInfo,
  _In_      DWORD              cbJobObjectInfoLength,
  _Out_opt_ LPDWORD            lpReturnLength
);
 */
typedef ::boost::winapi::BOOL_  ( WINAPI *query_information_job_object_p)(
        ::boost::winapi::HANDLE_,
        JOBOBJECTINFOCLASS_,
        void *,
        ::boost::winapi::DWORD_,
        ::boost::winapi::DWORD_ *);

inline ::boost::winapi::BOOL_ WINAPI query_information_job_object(
        ::boost::winapi::HANDLE_ hJob,
        JOBOBJECTINFOCLASS_ JobObjectInfoClass,
        void * lpJobObjectInfo,
        ::boost::winapi::DWORD_ cbJobObjectInfoLength,
        ::boost::winapi::DWORD_ *lpReturnLength)
{
    static ::boost::winapi::HMODULE_ h = ::boost::winapi::get_module_handle(L"Kernel32.dll");
    static query_information_job_object_p f = reinterpret_cast<query_information_job_object_p>(::boost::winapi::get_proc_address(h, "QueryInformationJobObject"));

    return (*f)(hJob, JobObjectInfoClass, lpJobObjectInfo, cbJobObjectInfoLength, lpReturnLength);
}

/*BOOL WINAPI SetInformationJobObject(
  _In_ HANDLE             hJob,
  _In_ JOBOBJECTINFOCLASS JobObjectInfoClass,
  _In_ LPVOID             lpJobObjectInfo,
  _In_ DWORD              cbJobObjectInfoLength
);*/

typedef ::boost::winapi::BOOL_  ( WINAPI *set_information_job_object_p)(
        ::boost::winapi::HANDLE_,
        JOBOBJECTINFOCLASS_,
        void *,
        ::boost::winapi::DWORD_);

}

inline ::boost::winapi::BOOL_ WINAPI set_information_job_object(
        ::boost::winapi::HANDLE_ hJob,
        JOBOBJECTINFOCLASS_ JobObjectInfoClass,
        void * lpJobObjectInfo,
        ::boost::winapi::DWORD_ cbJobObjectInfoLength)
{
    static ::boost::winapi::HMODULE_ h = ::boost::winapi::get_module_handle(L"Kernel32.dll");
    static set_information_job_object_p f = reinterpret_cast<set_information_job_object_p>(::boost::winapi::get_proc_address(h, "SetInformationJobObject"));

    return (*f)(hJob, JobObjectInfoClass, lpJobObjectInfo, cbJobObjectInfoLength);
}

constexpr static ::boost::winapi::DWORD_ JOB_OBJECT_LIMIT_BREAKAWAY_OK_ = 0x00000800;

}}}}}

#endif /* BOOST_PROCESS_DETAIL_WINDOWS_JOB_WORKAROUND_HPP_ */