<commit_before>#include "triangular.hpp"
#include "../segments/types.hpp"
#include "../vertices/types.hpp"

////////////////////////////
// Triangle, cartesian 2D //
////////////////////////////

unsigned int TriangularCartesian2D_Domain::num_vertices()
{
	TriangularCartesian2D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularCartesian2D_Domain::add_vertex(PointCartesian2D vertex)
{
	viennagrid::create_element<TriangularCartesian2D_Vertex_t>(domain, vertex.get_point());
}

TriangularCartesian2D_Domain_t & TriangularCartesian2D_Domain::get_domain()
{
	return domain;
}

PointCartesian2D TriangularCartesian2D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularCartesian2D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointCartesian2D(viennagrid::point(domain, vertices[index]), index);
}

////////////////////////////
// Triangle, cartesian 3D //
////////////////////////////

unsigned int TriangularCartesian3D_Domain::num_vertices()
{
	TriangularCartesian3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularCartesian3D_Domain::add_vertex(PointCartesian3D vertex)
{
	viennagrid::create_element<TriangularCartesian3D_Vertex_t>(domain, vertex.get_point());

	unsigned int point_id = num_vertices++;
	TriangularCartesian3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	PointCartesian3D_t &point = viennagrid::point(domain, vertex_range[point_id]);
	vertices.append<PointCartesian3D>(PointCartesian3D(&point, point_id));
}

TriangularCartesian3D_Domain_t & TriangularCartesian3D_Domain::get_domain()
{
	return domain;
}

PointCartesian3D TriangularCartesian3D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularCartesian3D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointCartesian3D(viennagrid::point(domain, vertices[index]), index);
}

////////////////////////////////
// Triangle, cylindrical (3D) //
////////////////////////////////

unsigned int TriangularCylindrical3D_Domain::num_vertices()
{
	TriangularCylindrical3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularCylindrical3D_Domain::add_vertex(PointCylindrical3D vertex)
{
	viennagrid::create_element<TriangularCylindrical3D_Vertex_t>(domain, vertex.get_point());

	unsigned int point_id = num_vertices++;
	TriangularCylindrical3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	PointCylindrical_t &point = viennagrid::point(domain, vertex_range[point_id]);
	vertices.append<PointCylindrical3D>(PointCylindrical3D(point, point_id));
}

TriangularCylindrical3D_Domain_t & TriangularCylindrical3D_Domain::get_domain()
{
	return domain;
}

PointCylindrical3D TriangularCylindrical3D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularCylindrical3D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointCylindrical3D(viennagrid::point(domain, vertices[index]), index);
}

//////////////////////////
// Triangle, polar (2D) //
//////////////////////////

unsigned int TriangularPolar2D_Domain::num_vertices()
{
	TriangularPolar2D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularPolar2D_Domain::add_vertex(PointPolar2D vertex)
{
	viennagrid::create_element<TriangularPolar2D_Vertex_t>(domain, vertex.get_point());

	unsigned int point_id = num_vertices++;
	TriangularPolar2D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	PointPolar_t &point = viennagrid::point(domain, vertex_range[point_id]);
	vertices.append<PointPolar2D>(PointPolar2D(point, point_id));
}

TriangularPolar2D_Domain_t & TriangularPolar2D_Domain::get_domain()
{
	return domain;
}

PointPolar2D TriangularPolar2D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularPolar2D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointPolar2D(viennagrid::point(domain, vertices[index]), index);
}

//////////////////////////////
// Triangle, spherical (3D) //
//////////////////////////////

unsigned int TriangularSpherical3D_Domain::num_vertices()
{
	TriangularSpherical3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularSpherical3D_Domain::add_vertex(PointSpherical3D vertex)
{
	viennagrid::create_element<TriangularSpherical3D_Vertex_t>(domain, vertex.get_point());

	unsigned int point_id = num_vertices++;
	TriangularSpherical3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	PointSpherical_t &point = viennagrid::point(domain, vertex_range[point_id]);
	vertices.append<PointSpherical3D>(PointSpherical3D(point, point_id));
}

TriangularSpherical3D_Domain_t & TriangularSpherical3D_Domain::get_domain()
{
	return domain;
}

PointSpherical3D TriangularSpherical3D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularSpherical3D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointSpherical3D(viennagrid::point(domain, vertices[index]), index);
}
<commit_msg>Fix 'Domain.add_vertex' after removing old attributes and methods.<commit_after>#include "triangular.hpp"
#include "../segments/types.hpp"
#include "../vertices/types.hpp"

////////////////////////////
// Triangle, cartesian 2D //
////////////////////////////

unsigned int TriangularCartesian2D_Domain::num_vertices()
{
	TriangularCartesian2D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularCartesian2D_Domain::add_vertex(PointCartesian2D vertex)
{
	viennagrid::create_element<TriangularCartesian2D_Vertex_t>(domain, vertex.get_point());
}

TriangularCartesian2D_Domain_t & TriangularCartesian2D_Domain::get_domain()
{
	return domain;
}

PointCartesian2D TriangularCartesian2D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularCartesian2D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointCartesian2D(viennagrid::point(domain, vertices[index]), index);
}

////////////////////////////
// Triangle, cartesian 3D //
////////////////////////////

unsigned int TriangularCartesian3D_Domain::num_vertices()
{
	TriangularCartesian3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularCartesian3D_Domain::add_vertex(PointCartesian3D vertex)
{
	viennagrid::create_element<TriangularCartesian3D_Vertex_t>(domain, vertex.get_point());
}

TriangularCartesian3D_Domain_t & TriangularCartesian3D_Domain::get_domain()
{
	return domain;
}

PointCartesian3D TriangularCartesian3D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularCartesian3D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointCartesian3D(viennagrid::point(domain, vertices[index]), index);
}

////////////////////////////////
// Triangle, cylindrical (3D) //
////////////////////////////////

unsigned int TriangularCylindrical3D_Domain::num_vertices()
{
	TriangularCylindrical3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularCylindrical3D_Domain::add_vertex(PointCylindrical3D vertex)
{
	viennagrid::create_element<TriangularCylindrical3D_Vertex_t>(domain, vertex.get_point());
}

TriangularCylindrical3D_Domain_t & TriangularCylindrical3D_Domain::get_domain()
{
	return domain;
}

PointCylindrical3D TriangularCylindrical3D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularCylindrical3D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointCylindrical3D(viennagrid::point(domain, vertices[index]), index);
}

//////////////////////////
// Triangle, polar (2D) //
//////////////////////////

unsigned int TriangularPolar2D_Domain::num_vertices()
{
	TriangularPolar2D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularPolar2D_Domain::add_vertex(PointPolar2D vertex)
{
	viennagrid::create_element<TriangularPolar2D_Vertex_t>(domain, vertex.get_point());
}

TriangularPolar2D_Domain_t & TriangularPolar2D_Domain::get_domain()
{
	return domain;
}

PointPolar2D TriangularPolar2D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularPolar2D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointPolar2D(viennagrid::point(domain, vertices[index]), index);
}

//////////////////////////////
// Triangle, spherical (3D) //
//////////////////////////////

unsigned int TriangularSpherical3D_Domain::num_vertices()
{
	TriangularSpherical3D_VertexRange_t vertex_range = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return vertex_range.size();
}

void TriangularSpherical3D_Domain::add_vertex(PointSpherical3D vertex)
{
	viennagrid::create_element<TriangularSpherical3D_Vertex_t>(domain, vertex.get_point());
}

TriangularSpherical3D_Domain_t & TriangularSpherical3D_Domain::get_domain()
{
	return domain;
}

PointSpherical3D TriangularSpherical3D_Domain::get_vertex(unsigned int index)
{
	// TODO: domain.find_by_id(index);
	TriangularSpherical3D_VertexRange_t vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);
	return PointSpherical3D(viennagrid::point(domain, vertices[index]), index);
}
<|endoftext|>


<commit_before>/*
 *  Copyright (c) 2014-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */

#include <osquery/filesystem.h>

#include "osquery/remote/transports/tls.h"

namespace http = boost::network::http;

namespace osquery {

const std::string kTLSCiphers =
    "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:"
    "DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5";
const std::string kTLSUserAgentBase = "osquery/";

/// TLS server hostname.
CLI_FLAG(string,
         tls_hostname,
         "",
         "TLS/HTTPS hostname for Config, Logger, and Enroll plugins");

/// Path to optional TLS server/CA certificate(s), used for pinning.
CLI_FLAG(string,
         tls_server_certs,
         "",
         "Optional path to a TLS server PEM certificate(s) bundle");

/// Path to optional TLS client certificate, used for enrollment/requests.
CLI_FLAG(string,
         tls_client_cert,
         "",
         "Optional path to a TLS client-auth PEM certificate");

/// Path to optional TLS client secret key, used for enrollment/requests.
CLI_FLAG(string,
         tls_client_key,
         "",
         "Optional path to a TLS client-auth PEM private key");

#if defined(DEBUG)
HIDDEN_FLAG(bool,
            tls_allow_unsafe,
            false,
            "Allow TLS server certificate trust failures");
#endif

HIDDEN_FLAG(bool, tls_dump, false, "Print remote requests and responses");

/// Undocumented feature to override TLS endpoints.
HIDDEN_FLAG(bool, tls_node_api, false, "Use node key as TLS endpoints");

DECLARE_bool(verbose);

TLSTransport::TLSTransport() : verify_peer_(true) {
  if (FLAGS_tls_server_certs.size() > 0) {
    server_certificate_file_ = FLAGS_tls_server_certs;
  }

  if (FLAGS_tls_client_cert.size() > 0 && FLAGS_tls_client_key.size() > 0) {
    client_certificate_file_ = FLAGS_tls_client_cert;
    client_private_key_file_ = FLAGS_tls_client_key;
  }
}

void TLSTransport::decorateRequest(http::client::request& r) {
  r << boost::network::header("Connection", "close");
  r << boost::network::header("Content-Type", serializer_->getContentType());
  r << boost::network::header("Accept", serializer_->getContentType());
  r << boost::network::header("Host", FLAGS_tls_hostname);
  r << boost::network::header("User-Agent", kTLSUserAgentBase + kVersion);
}

http::client TLSTransport::getClient() {
  http::client::options options;
  options.follow_redirects(true).always_verify_peer(verify_peer_).timeout(16);

  std::string ciphers = kTLSCiphers;
// Some Ubuntu 12.04 clients exhaust their cipher suites without SHA.
#if defined(HAS_SSL_TXT_TLSV1_2) && !defined(UBUNTU_PRECISE) && !defined(DARWIN)
  // Otherwise we prefer GCM and SHA256+
  ciphers += ":!CBC:!SHA";
#endif

#if defined(DEBUG)
  // Configuration may allow unsafe TLS testing if compiled as a debug target.
  if (FLAGS_tls_allow_unsafe) {
    options.always_verify_peer(false);
  }
#endif

  options.openssl_ciphers(ciphers);
  options.openssl_options(SSL_OP_NO_SSLv3 | SSL_OP_NO_SSLv2 | SSL_OP_ALL);

  if (server_certificate_file_.size() > 0) {
    if (!osquery::isReadable(server_certificate_file_).ok()) {
      LOG(WARNING) << "Cannot read TLS server certificate(s): "
                   << server_certificate_file_;
    } else {
      // There is a non-default server certificate set.
      options.openssl_verify_path(server_certificate_file_);
      options.openssl_certificate(server_certificate_file_);
    }
  }

  if (client_certificate_file_.size() > 0) {
    if (!osquery::isReadable(client_certificate_file_).ok()) {
      LOG(WARNING) << "Cannot read TLS client certificate: "
                   << client_certificate_file_;
    } else if (!osquery::isReadable(client_private_key_file_).ok()) {
      LOG(WARNING) << "Cannot read TLS client private key: "
                   << client_private_key_file_;
    } else {
      options.openssl_certificate_file(client_certificate_file_);
      options.openssl_private_key_file(client_private_key_file_);
    }
  }

  // 'Optionally', though all TLS plugins should set a hostname, supply an SNI
  // hostname. This will reveal the requested domain.
  if (options_.count("hostname")) {
#if BOOST_NETLIB_VERSION_MINOR >= 12
    // Boost cpp-netlib will only support SNI in versions >= 0.12
    options.openssl_sni_hostname(options_.get<std::string>("hostname"));
#endif
  }

  http::client client(options);
  return client;
}

inline bool tlsFailure(const std::string& what) {
  if (what.find("Error") == 0 || what.find("refused") != std::string::npos) {
    return false;
  }
  return true;
}

Status TLSTransport::sendRequest() {
  if (destination_.find("https://") == std::string::npos) {
    return Status(1, "Cannot create TLS request for non-HTTPS protocol URI");
  }

  auto client = getClient();
  http::client::request r(destination_);
  decorateRequest(r);

  VLOG(1) << "TLS/HTTPS GET request to URI: " << destination_;
  try {
    response_ = client.get(r);
    const auto& response_body = body(response_);
    if (FLAGS_verbose && FLAGS_tls_dump) {
      fprintf(stdout, "%s\n", std::string(response_body).c_str());
    }
    response_status_ =
        serializer_->deserialize(response_body, response_params_);
  } catch (const std::exception& e) {
    return Status((tlsFailure(e.what())) ? 2 : 1,
                  std::string("Request error: ") + e.what());
  }
  return response_status_;
}

Status TLSTransport::sendRequest(const std::string& params, bool compress) {
  if (destination_.find("https://") == std::string::npos) {
    return Status(1, "Cannot create TLS request for non-HTTPS protocol URI");
  }

  auto client = getClient();
  http::client::request r(destination_);
  decorateRequest(r);
  if (compress) {
    // Later, when posting/putting, the data will be optionally compressed.
    r << boost::network::header("Content-Encoding", "gzip");
  }

  // Allow request calls to override the default HTTP POST verb.
  HTTPVerb verb = HTTP_POST;
  if (options_.count("verb") > 0) {
    verb = (HTTPVerb)options_.get<int>("verb", HTTP_POST);
  }

  VLOG(1) << "TLS/HTTPS " << ((verb == HTTP_POST) ? "POST" : "PUT")
          << " request to URI: " << destination_;
  if (FLAGS_verbose && FLAGS_tls_dump) {
    fprintf(stdout, "%s\n", params.c_str());
  }

  try {
    if (verb == HTTP_POST) {
      response_ = client.post(r, (compress) ? compressString(params) : params);
    } else {
      response_ = client.put(r, (compress) ? compressString(params) : params);
    }

    const auto& response_body = body(response_);
    if (FLAGS_verbose && FLAGS_tls_dump) {
      fprintf(stdout, "%s\n", std::string(response_body).c_str());
    }
    response_status_ =
        serializer_->deserialize(response_body, response_params_);
  } catch (const std::exception& e) {
    return Status((tlsFailure(e.what())) ? 2 : 1,
                  std::string("Request error: ") + e.what());
  }
  return response_status_;
}
}
<commit_msg>Remove OpenSSL and cpp-netlib old version exceptions (#2413)<commit_after>/*
 *  Copyright (c) 2014-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */

#include <osquery/core.h>
#include <osquery/filesystem.h>

#include "osquery/remote/transports/tls.h"

namespace http = boost::network::http;

namespace osquery {

const std::string kTLSCiphers =
    "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:"
    "DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5";
const std::string kTLSUserAgentBase = "osquery/";

/// TLS server hostname.
CLI_FLAG(string,
         tls_hostname,
         "",
         "TLS/HTTPS hostname for Config, Logger, and Enroll plugins");

/// Path to optional TLS server/CA certificate(s), used for pinning.
CLI_FLAG(string,
         tls_server_certs,
         "",
         "Optional path to a TLS server PEM certificate(s) bundle");

/// Path to optional TLS client certificate, used for enrollment/requests.
CLI_FLAG(string,
         tls_client_cert,
         "",
         "Optional path to a TLS client-auth PEM certificate");

/// Path to optional TLS client secret key, used for enrollment/requests.
CLI_FLAG(string,
         tls_client_key,
         "",
         "Optional path to a TLS client-auth PEM private key");

#if defined(DEBUG)
HIDDEN_FLAG(bool,
            tls_allow_unsafe,
            false,
            "Allow TLS server certificate trust failures");
#endif

HIDDEN_FLAG(bool, tls_dump, false, "Print remote requests and responses");

/// Undocumented feature to override TLS endpoints.
HIDDEN_FLAG(bool, tls_node_api, false, "Use node key as TLS endpoints");

DECLARE_bool(verbose);

TLSTransport::TLSTransport() : verify_peer_(true) {
  if (FLAGS_tls_server_certs.size() > 0) {
    server_certificate_file_ = FLAGS_tls_server_certs;
  }

  if (FLAGS_tls_client_cert.size() > 0 && FLAGS_tls_client_key.size() > 0) {
    client_certificate_file_ = FLAGS_tls_client_cert;
    client_private_key_file_ = FLAGS_tls_client_key;
  }
}

void TLSTransport::decorateRequest(http::client::request& r) {
  r << boost::network::header("Connection", "close");
  r << boost::network::header("Content-Type", serializer_->getContentType());
  r << boost::network::header("Accept", serializer_->getContentType());
  r << boost::network::header("Host", FLAGS_tls_hostname);
  r << boost::network::header("User-Agent", kTLSUserAgentBase + kVersion);
}

http::client TLSTransport::getClient() {
  http::client::options options;
  options.follow_redirects(true).always_verify_peer(verify_peer_).timeout(16);

  std::string ciphers = kTLSCiphers;
  if (!isPlatform(PlatformType::TYPE_OSX)) {
    // Otherwise we prefer GCM and SHA256+
    ciphers += ":!CBC:!SHA";
  }

#if defined(DEBUG)
  // Configuration may allow unsafe TLS testing if compiled as a debug target.
  if (FLAGS_tls_allow_unsafe) {
    options.always_verify_peer(false);
  }
#endif

  options.openssl_ciphers(ciphers);
  options.openssl_options(SSL_OP_NO_SSLv3 | SSL_OP_NO_SSLv2 | SSL_OP_ALL);

  if (server_certificate_file_.size() > 0) {
    if (!osquery::isReadable(server_certificate_file_).ok()) {
      LOG(WARNING) << "Cannot read TLS server certificate(s): "
                   << server_certificate_file_;
    } else {
      // There is a non-default server certificate set.
      options.openssl_verify_path(server_certificate_file_);
      options.openssl_certificate(server_certificate_file_);
    }
  }

  if (client_certificate_file_.size() > 0) {
    if (!osquery::isReadable(client_certificate_file_).ok()) {
      LOG(WARNING) << "Cannot read TLS client certificate: "
                   << client_certificate_file_;
    } else if (!osquery::isReadable(client_private_key_file_).ok()) {
      LOG(WARNING) << "Cannot read TLS client private key: "
                   << client_private_key_file_;
    } else {
      options.openssl_certificate_file(client_certificate_file_);
      options.openssl_private_key_file(client_private_key_file_);
    }
  }

  // 'Optionally', though all TLS plugins should set a hostname, supply an SNI
  // hostname. This will reveal the requested domain.
  if (options_.count("hostname")) {
    // Boost cpp-netlib will only support SNI in versions >= 0.12
    options.openssl_sni_hostname(options_.get<std::string>("hostname"));
  }

  http::client client(options);
  return client;
}

inline bool tlsFailure(const std::string& what) {
  if (what.find("Error") == 0 || what.find("refused") != std::string::npos) {
    return false;
  }
  return true;
}

Status TLSTransport::sendRequest() {
  if (destination_.find("https://") == std::string::npos) {
    return Status(1, "Cannot create TLS request for non-HTTPS protocol URI");
  }

  auto client = getClient();
  http::client::request r(destination_);
  decorateRequest(r);

  VLOG(1) << "TLS/HTTPS GET request to URI: " << destination_;
  try {
    response_ = client.get(r);
    const auto& response_body = body(response_);
    if (FLAGS_verbose && FLAGS_tls_dump) {
      fprintf(stdout, "%s\n", std::string(response_body).c_str());
    }
    response_status_ =
        serializer_->deserialize(response_body, response_params_);
  } catch (const std::exception& e) {
    return Status((tlsFailure(e.what())) ? 2 : 1,
                  std::string("Request error: ") + e.what());
  }
  return response_status_;
}

Status TLSTransport::sendRequest(const std::string& params, bool compress) {
  if (destination_.find("https://") == std::string::npos) {
    return Status(1, "Cannot create TLS request for non-HTTPS protocol URI");
  }

  auto client = getClient();
  http::client::request r(destination_);
  decorateRequest(r);
  if (compress) {
    // Later, when posting/putting, the data will be optionally compressed.
    r << boost::network::header("Content-Encoding", "gzip");
  }

  // Allow request calls to override the default HTTP POST verb.
  HTTPVerb verb = HTTP_POST;
  if (options_.count("verb") > 0) {
    verb = (HTTPVerb)options_.get<int>("verb", HTTP_POST);
  }

  VLOG(1) << "TLS/HTTPS " << ((verb == HTTP_POST) ? "POST" : "PUT")
          << " request to URI: " << destination_;
  if (FLAGS_verbose && FLAGS_tls_dump) {
    fprintf(stdout, "%s\n", params.c_str());
  }

  try {
    if (verb == HTTP_POST) {
      response_ = client.post(r, (compress) ? compressString(params) : params);
    } else {
      response_ = client.put(r, (compress) ? compressString(params) : params);
    }

    const auto& response_body = body(response_);
    if (FLAGS_verbose && FLAGS_tls_dump) {
      fprintf(stdout, "%s\n", std::string(response_body).c_str());
    }
    response_status_ =
        serializer_->deserialize(response_body, response_params_);
  } catch (const std::exception& e) {
    return Status((tlsFailure(e.what())) ? 2 : 1,
                  std::string("Request error: ") + e.what());
  }
  return response_status_;
}
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: register.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2003-12-01 18:09:29 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_
#include <com/sun/star/registry/XRegistryKey.hpp>
#endif
#ifndef _COM_SUN_STAR_REGISTRY_INVALIDREGISTRYEXCEPTION_HPP_
#include <com/sun/star/registry/InvalidRegistryException.hpp>
#endif

#ifndef _CPPUHELPER_FACTORY_HXX_
#include <cppuhelper/factory.hxx>
#endif

#include "xfactory.hxx"

using namespace ::com::sun::star;

extern "C" {

void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
{
    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}

void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
{
    void * pRet = 0;

    ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) );
    uno::Reference< lang::XSingleServiceFactory > xFactory;

    if ( pServiceManager && aImplName.equals( OStorageFactory::impl_staticGetImplementationName() ) )
    {
        xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
                                            OStorageFactory::impl_staticGetImplementationName(),
                                            OStorageFactory::impl_staticCreateSelfInstance,
                                            OStorageFactory::impl_staticGetSupportedServiceNames() );
    }

    if ( xFactory.is() )
    {
        xFactory->acquire();
        pRet = xFactory.get();
    }

    return pRet;
}

sal_Bool SAL_CALL component_writeInfo( void * pServiceManager, void * pRegistryKey )
{
    if (pRegistryKey)
    {
        try
        {
            uno::Reference< registry::XRegistryKey > xKey( reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ) );

            uno::Reference< registry::XRegistryKey >  xNewKey;

            xNewKey = xKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
                                        OStorageFactory::impl_staticGetImplementationName() +
                                        ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") )  );

            const uno::Sequence< ::rtl::OUString > &rServices = OStorageFactory::impl_staticGetSupportedServiceNames();
            for( sal_Int32 ind = 0; ind < rServices.getLength(); ind++ )
                xNewKey->createKey( rServices.getConstArray()[ind] );

            return sal_True;
        }
        catch (registry::InvalidRegistryException &)
        {
            OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
        }
    }
    return sal_False;
}

} // extern "C"

<commit_msg>INTEGRATION: CWS mav09 (1.3.42); FILE MERGED 2004/05/13 15:10:03 mav 1.3.42.1: #112768# remove dangerous references<commit_after>/*************************************************************************
 *
 *  $RCSfile: register.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: kz $ $Date: 2004-10-04 21:08:09 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_
#include <com/sun/star/registry/XRegistryKey.hpp>
#endif
#ifndef _COM_SUN_STAR_REGISTRY_INVALIDREGISTRYEXCEPTION_HPP_
#include <com/sun/star/registry/InvalidRegistryException.hpp>
#endif

#ifndef _CPPUHELPER_FACTORY_HXX_
#include <cppuhelper/factory.hxx>
#endif

#include "xfactory.hxx"

using namespace ::com::sun::star;

extern "C" {

void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
{
    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}

void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
{
    void * pRet = 0;

    ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) );
    uno::Reference< lang::XSingleServiceFactory > xFactory;

    if ( pServiceManager && aImplName.equals( OStorageFactory::impl_staticGetImplementationName() ) )
    {
        xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
                                            OStorageFactory::impl_staticGetImplementationName(),
                                            OStorageFactory::impl_staticCreateSelfInstance,
                                            OStorageFactory::impl_staticGetSupportedServiceNames() );
    }

    if ( xFactory.is() )
    {
        xFactory->acquire();
        pRet = xFactory.get();
    }

    return pRet;
}

sal_Bool SAL_CALL component_writeInfo( void * pServiceManager, void * pRegistryKey )
{
    if (pRegistryKey)
    {
        try
        {
            uno::Reference< registry::XRegistryKey > xKey( reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ) );

            uno::Reference< registry::XRegistryKey >  xNewKey;

            xNewKey = xKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
                                        OStorageFactory::impl_staticGetImplementationName() +
                                        ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") )  );

            const uno::Sequence< ::rtl::OUString > aServices = OStorageFactory::impl_staticGetSupportedServiceNames();
            for( sal_Int32 ind = 0; ind < aServices.getLength(); ind++ )
                xNewKey->createKey( aServices.getConstArray()[ind] );

            return sal_True;
        }
        catch (registry::InvalidRegistryException &)
        {
            OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
        }
    }
    return sal_False;
}

} // extern "C"

<|endoftext|>


<commit_before>#include "BACharacter.h"
#include "BAMap.h"
#include "BAGlobal.h"

BAPlayer::BAPlayer(BACharacterData data){
  charData = data;

  // init ships
  ships = NULL;
  numberOfShips = charData.sShips + charData.mShips + charData.lShips;
  ships = new BAShip[numberOfShips];

  // small ships
  for(size_t i = 0; i < charData.sShips; i++)
    ships[i] = BAShipMake(1);

  // medium ships
  for(size_t i = 0; i < charData.mShips; i++)
    ships[i+charData.sShips] = BAShipMake(2);

  // big ships
  for(size_t i = 0; i < charData.lShips; i++)
    ships[i+charData.sShips+charData.mShips] = BAShipMake(3);

  // create water map
  for(size_t j = 0; j < GAME_BOARD_SIZE_HEIGHT; j++){
    for(size_t i = 0; i < GAME_BOARD_SIZE_WIDTH; i++){
      //Water
      playerBoard[j][i] = BAMapTileTypeWater0;
    }
  }

  // random mountains
  byte mountainsCount = random(3,6);
  ABPoint lastMountainPos = ABPointMake(-1, -1);

  for(byte i = 0; i < mountainsCount ; i++){
    ABPoint mountainPos;
    do{
      mountainPos.x = random(0, GAME_BOARD_SIZE_WIDTH);
      mountainPos.y = random(0, GAME_BOARD_SIZE_HEIGHT);
    }
    while(pointIsEqualToPoint(mountainPos, lastMountainPos));

    lastMountainPos = mountainPos;
    playerBoard[mountainPos.y][mountainPos.x] = BAMapTileTypeMountain;
  }
}

BAPlayer::~BAPlayer(){
  delete ships;
  ships = NULL;
}

BACharacterData BAPlayer::getCharacterData(){
  return charData;
}

BAShip BAPlayer::shipAtIndex(byte idx){
  return ships[idx];
}

void BAPlayer::updateShipAtIndex(byte idx, BAShip newShip){
  ships[idx].remainingLength = newShip.remainingLength;
  ships[idx].horizontal = newShip.horizontal;
}

byte BAPlayer:: numberOfRemainingShips(){
  byte nr = 0;

  for(int i = 0; i<numberOfShips ;i++)
    if(!isShipDestroyed(ships[i])) nr++;

  return nr;
}

<commit_msg>update ship position when update ship<commit_after>#include "BACharacter.h"
#include "BAMap.h"
#include "BAGlobal.h"

BAPlayer::BAPlayer(BACharacterData data){
  charData = data;

  // init ships
  ships = NULL;
  numberOfShips = charData.sShips + charData.mShips + charData.lShips;
  ships = new BAShip[numberOfShips];

  // small ships
  for(size_t i = 0; i < charData.sShips; i++)
    ships[i] = BAShipMake(1);

  // medium ships
  for(size_t i = 0; i < charData.mShips; i++)
    ships[i+charData.sShips] = BAShipMake(2);

  // big ships
  for(size_t i = 0; i < charData.lShips; i++)
    ships[i+charData.sShips+charData.mShips] = BAShipMake(3);

  // create water map
  for(size_t j = 0; j < GAME_BOARD_SIZE_HEIGHT; j++){
    for(size_t i = 0; i < GAME_BOARD_SIZE_WIDTH; i++){
      //Water
      playerBoard[j][i] = BAMapTileTypeWater0;
    }
  }

  // random mountains
  byte mountainsCount = random(3,6);
  ABPoint lastMountainPos = ABPointMake(-1, -1);

  for(byte i = 0; i < mountainsCount ; i++){
    ABPoint mountainPos;
    do{
      mountainPos.x = random(0, GAME_BOARD_SIZE_WIDTH);
      mountainPos.y = random(0, GAME_BOARD_SIZE_HEIGHT);
    }
    while(pointIsEqualToPoint(mountainPos, lastMountainPos));

    lastMountainPos = mountainPos;
    playerBoard[mountainPos.y][mountainPos.x] = BAMapTileTypeMountain;
  }
}

BAPlayer::~BAPlayer(){
  delete ships;
  ships = NULL;
}

BACharacterData BAPlayer::getCharacterData(){
  return charData;
}

BAShip BAPlayer::shipAtIndex(byte idx){
  return ships[idx];
}

void BAPlayer::updateShipAtIndex(byte idx, BAShip newShip){
  ships[idx].remainingLength = newShip.remainingLength;
  ships[idx].horizontal = newShip.horizontal;
  ships[idx].position = newShip.position;
}

byte BAPlayer:: numberOfRemainingShips(){
  byte nr = 0;

  for(int i = 0; i<numberOfShips ;i++)
    if(!isShipDestroyed(ships[i])) nr++;

  return nr;
}

<|endoftext|>


<commit_before>// Port of
// third_party/nxp/rt1176-sdk/middleware/wireless/ethermind/port/pal/mcux/bluetooth/BT_storage_pl.c
// to use Dev Board Micro's filesystem APIs.

#include "libs/base/filesystem.h"

extern "C" {

#include "third_party/nxp/rt1176-sdk/middleware/wireless/ethermind/port/pal/mcux/bluetooth/BT_storage_pl.h"

static lfs_file_t *fp[STORAGE_NUM_TYPES];
static lfs_file_t lfs_file[STORAGE_NUM_TYPES];
/* Storage File Name array */
static UCHAR *fn[STORAGE_NUM_TYPES] = {
    (UCHAR *)"btps.db",
#ifdef STORAGE_RETENTION_SUPPORT
    (UCHAR *)"btrn.db",
#endif /* STORAGE_RETENTION_SUPPORT */
};

/* Storage Signature Key array */
static UCHAR ssign[STORAGE_NUM_TYPES][STORAGE_SKEY_SIZE] = {
    {'E', 'T', 'H', 'E', 'R', 'M', 'I', 'N', 'D', 'P', 'S'}};

API_RESULT storage_open_pl(UCHAR type, UCHAR mode) {
  if (NULL != fp[type]) {
    coralmicro::filesystem::Close(fp[type]);
    fp[type] = NULL;
  }
  bool open;
  if (mode == STORAGE_OPEN_MODE_WRITE) {
    open = coralmicro::filesystem::Open(&lfs_file[type], (char *)fn[type], true);
  } else {
    open = coralmicro::filesystem::Open(&lfs_file[type], (char *)fn[type]);
  }
  if (!open) {
    return API_FAILURE;
  }

  fp[type] = &lfs_file[type];
  return API_SUCCESS;
}

API_RESULT storage_close_pl(UCHAR type, UCHAR mode) {
  if (NULL != fp[type]) {
    coralmicro::filesystem::Close(fp[type]);
    fp[type] = NULL;
  }

  return API_SUCCESS;
}

INT16 storage_write_pl(UCHAR type, void *buffer, UINT16 size) {
  INT16 nbytes;
  nbytes = 0;

  if (NULL != fp[type]) {
    nbytes = (INT16)coralmicro::filesystem::Write(fp[type], buffer, size);
  }
  return nbytes;
}

INT16 storage_read_pl(UCHAR type, void *buffer, UINT16 size) {
  INT16 nbytes = 0;
  if (NULL != fp[type]) {
    nbytes = (INT16)coralmicro::filesystem::Read(fp[type], buffer, size);
  }
  return nbytes;
}

INT16 storage_write_signature_pl(UCHAR type) {
  INT16 nbytes = 0;
  if (NULL != fp[type]) {
    nbytes = (INT16)coralmicro::filesystem::Write(fp[type], ssign[type],
                                               STORAGE_SKEY_SIZE);
  }
  return nbytes;
}

INT16 storage_read_signature_pl(UCHAR type) {
  INT16 nbytes = 0;
  UCHAR sign[STORAGE_SKEY_SIZE];
  if (NULL != fp[type]) {
    nbytes = coralmicro::filesystem::Read(fp[type], sign, STORAGE_SKEY_SIZE);
    if (BT_mem_cmp(ssign[type], sign, STORAGE_SKEY_SIZE)) {
      return -1;
    }
  }
  return nbytes;
}

void storage_bt_init_pl(void) {
  for (unsigned int i = 0; i < STORAGE_NUM_TYPES; ++i) {
    fp[i] = NULL;
  }
}

}  // extern "C"
<commit_msg>Use LFS API directly in BT_storage_pl.cc<commit_after>// Port of
// third_party/nxp/rt1176-sdk/middleware/wireless/ethermind/port/pal/mcux/bluetooth/BT_storage_pl.c

#include "libs/base/filesystem.h"

/*
 *  Copyright (C) 2013. Mindtree Ltd.
 *  All rights reserved.
 */

using coralmicro::filesystem::Lfs;

extern "C" {

#include "third_party/nxp/rt1176-sdk/middleware/wireless/ethermind/port/pal/mcux/bluetooth/BT_storage_pl.h"

/* Storage File Handle array */
static lfs_file_t* fp[STORAGE_NUM_TYPES];
static lfs_file_t lfs_file[STORAGE_NUM_TYPES];

/* Storage File Name array */
static UCHAR* fn[STORAGE_NUM_TYPES] = {
    (UCHAR*)"btps.db",
#ifdef STORAGE_RETENTION_SUPPORT
    (UCHAR*)"btrn.db",
#endif /* STORAGE_RETENTION_SUPPORT */
};

/* Storage Signature Key array */
static UCHAR ssign[STORAGE_NUM_TYPES][STORAGE_SKEY_SIZE] = {
    {'E', 'T', 'H', 'E', 'R', 'M', 'I', 'N', 'D', 'P', 'S'}};

API_RESULT storage_open_pl(UCHAR type, UCHAR mode) {
  if (NULL != fp[type]) {
    (void)lfs_file_close(Lfs(), fp[type]);
    fp[type] = NULL;
  }
  /* Set the file access mode */
  int rw =
      (int)((STORAGE_OPEN_MODE_WRITE == mode) ? (LFS_O_WRONLY | LFS_O_CREAT)
                                              : LFS_O_RDONLY);

  int err = lfs_file_open(Lfs(), &lfs_file[type], (CHAR*)fn[type], rw);

  if (err < 0) {
    return API_FAILURE;
  }

  fp[type] = &lfs_file[type];

  return API_SUCCESS;
}

API_RESULT storage_close_pl(UCHAR type, UCHAR mode) {
  BT_IGNORE_UNUSED_PARAM(mode);
  if (NULL != fp[type]) {
    (void)lfs_file_close(Lfs(), fp[type]);
    fp[type] = NULL;
  }
  return API_SUCCESS;
}

INT16 storage_write_pl(UCHAR type, void* buffer, UINT16 size) {
  INT16 nbytes = 0;
  if (NULL != fp[type]) {
    nbytes = (INT16)lfs_file_write(Lfs(), fp[type], buffer, size);
  }
  return nbytes;
}

INT16 storage_read_pl(UCHAR type, void* buffer, UINT16 size) {
  INT16 nbytes = 0;
  if (NULL != fp[type]) {
    nbytes = (INT16)lfs_file_read(Lfs(), fp[type], buffer, size);
  }
  return nbytes;
}

INT16 storage_write_signature_pl(UCHAR type) {
  INT16 nbytes = 0;
  if (NULL != fp[type]) {
    nbytes =
        (INT16)lfs_file_write(Lfs(), fp[type], ssign[type], STORAGE_SKEY_SIZE);
  }
  return nbytes;
}

INT16 storage_read_signature_pl(UCHAR type) {
  INT16 nbytes = 0;
  UCHAR sign[STORAGE_SKEY_SIZE];

  if (NULL != fp[type]) {
    nbytes = lfs_file_read(Lfs(), fp[type], sign, STORAGE_SKEY_SIZE);

    if (BT_mem_cmp(ssign[type], sign, STORAGE_SKEY_SIZE)) {
      return -1;
    }
  }
  return nbytes;
}

void storage_bt_init_pl() {
  for (UCHAR i = 0; i < STORAGE_NUM_TYPES; i++) {
    fp[i] = NULL;
  }
}

void storage_bt_shutdown_pl() {
  for (UCHAR i = 0; i < STORAGE_NUM_TYPES; i++) {
    if (NULL != fp[i]) {
      lfs_file_close(Lfs(), fp[i]);
      fp[i] = NULL;
    }
  }
}

}  // extern "C"
<|endoftext|>


<commit_before>// $Id$

/*
Copyright (c) 2007-2009, Trustees of The Leland Stanford Junior University
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the Stanford University nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "booksim.hpp"
#include <iostream>
#include <cassert>
#include "allocator.hpp"

/////////////////////////////////////////////////////////////////////////
//Allocator types
#include "maxsize.hpp"
#include "pim.hpp"
#include "islip.hpp"
#include "loa.hpp"
#include "wavefront.hpp"
#include "fair_wavefront.hpp"
#include "prio_wavefront.hpp"
#include "selalloc.hpp"
#include "separable_input_first.hpp"
#include "separable_output_first.hpp"
//
/////////////////////////////////////////////////////////////////////////

//==================================================
// Allocator base class
//==================================================

Allocator::Allocator( Module *parent, const string& name,
		      int inputs, int outputs ) :
  Module( parent, name ), _inputs( inputs ), _outputs( outputs )
{
  _inmatch.resize(_inputs, -1);
  _outmatch.resize(_outputs, -1);
}

void Allocator::Clear( )
{
  _inmatch.assign(_inputs, -1);
  _outmatch.assign(_outputs, -1);
}

void Allocator::AddRequest( int in, int out, int label, int in_pri,
			    int out_pri ) {

  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );
  assert( label >= 0 );
}

int Allocator::OutputAssigned( int in ) const
{
  assert( ( in >= 0 ) && ( in < _inputs ) );

  return _inmatch[in];
}

int Allocator::InputAssigned( int out ) const
{
  assert( ( out >= 0 ) && ( out < _outputs ) );

  return _outmatch[out];
}

//==================================================
// DenseAllocator
//==================================================

DenseAllocator::DenseAllocator( Module *parent, const string& name,
				int inputs, int outputs ) :
  Allocator( parent, name, inputs, outputs )
{
  _request.resize(_inputs);

  for ( int i = 0; i < _inputs; ++i ) {
    _request[i].resize(_outputs);
    for ( int j = 0; j < _outputs; ++j ) {
      _request[i][j].label = -1;
    }
  }
}

void DenseAllocator::Clear( )
{
  for ( int i = 0; i < _inputs; ++i ) {
    for ( int j = 0; j < _outputs; ++j ) {
      _request[i][j].label = -1;
    }
  }
  Allocator::Clear();
}

int DenseAllocator::ReadRequest( int in, int out ) const
{
  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  return _request[in][out].label;
}

bool DenseAllocator::ReadRequest( sRequest &req, int in, int out ) const
{
  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  req = _request[in][out];

  return ( req.label != -1 );
}

void DenseAllocator::AddRequest( int in, int out, int label,
				 int in_pri, int out_pri )
{
  Allocator::AddRequest(in, out, label, in_pri, out_pri);

  if((_request[in][out].label == -1) || (_request[in][out].in_pri < in_pri)) {
    _request[in][out].label   = label;
    _request[in][out].in_pri  = in_pri;
    _request[in][out].out_pri = out_pri;
  }
}

void DenseAllocator::RemoveRequest( int in, int out, int label )
{
  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  _request[in][out].label = -1;
}

void DenseAllocator::PrintRequests( ostream * os ) const
{
  if(!os) os = &cout;
  *os << "Requests = [ ";
  for ( int i = 0; i < _inputs; ++i ) {
    *os << "[ ";
    for ( int j = 0; j < _outputs; ++j ) {
      *os << ( _request[i][j].label != -1 ) << " ";
    }
    *os << "] ";
  }
  *os << "]." << endl;
}

//==================================================
// SparseAllocator
//==================================================

SparseAllocator::SparseAllocator( Module *parent, const string& name,
				  int inputs, int outputs ) :
  Allocator( parent, name, inputs, outputs )
{
  _in_req.resize(_inputs);
  _out_req.resize(_outputs);
}

void SparseAllocator::Clear( )
{
  for ( int i = 0; i < _inputs; ++i ) {
    _in_req[i].clear( );
  }

  for ( int j = 0; j < _outputs; ++j ) {
    _out_req[j].clear( );
  }

  _in_occ.clear( );
  _out_occ.clear( );

  Allocator::Clear();
}

int SparseAllocator::ReadRequest( int in, int out ) const
{
  sRequest r;

  if ( ! ReadRequest( r, in, out ) ) {
    r.label = -1;
  }

  return r.label;
}

bool SparseAllocator::ReadRequest( sRequest &req, int in, int out ) const
{
  bool found;

  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  map<int, sRequest>::const_iterator match = _in_req[in].find(out);
  if ( match != _in_req[in].end( ) ) {
    req = match->second;
    found = true;
  } else {
    found = false;
  }

  return found;
}

void SparseAllocator::AddRequest( int in, int out, int label,
				  int in_pri, int out_pri )
{
  Allocator::AddRequest(in, out, label, in_pri, out_pri);

  // insert into occupied inputs set if
  // input is currently empty
  if ( _in_req[in].empty( ) ) {
    _in_occ.insert(in);
  }

  // similarly for the output
  if ( _out_req[out].empty( ) ) {
    _out_occ.insert(out);
  }

  sRequest req;
  req.port    = out;
  req.label   = label;
  req.in_pri  = in_pri;
  req.out_pri = out_pri;

  // insert input request in order of it's output
  map<int, sRequest>::iterator insert_point = _in_req[in].find(out);
  if(insert_point == _in_req[in].end()) {
    _in_req[in][out] = req;
  } else if(insert_point->second.in_pri < in_pri) {
    insert_point->second = req;
  }

  req.port  = in;
  req.label = label;

  insert_point = _out_req[out].find(in);
  if(insert_point == _out_req[out].end()) {
    _out_req[out][in] = req;
  } else if(insert_point->second.in_pri < in_pri) {
    insert_point->second = req;
  }
}

void SparseAllocator::RemoveRequest( int in, int out, int label )
{
  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  // insert input request in order of it's output
  map<int, sRequest>::iterator erase_point = _in_req[in].find(out);

  assert( erase_point != _in_req[in].end( ) );
  _in_req[in].erase( erase_point );

  // remove from occupied inputs list if
  // input is now empty
  if ( _in_req[in].empty( ) ) {
    _in_occ.erase(in);
  }

  // similarly for the output
  erase_point = _out_req[out].find(in);

  assert( erase_point != _out_req[out].end( ) );
  _out_req[out].erase( erase_point );

  if ( _out_req[out].empty( ) ) {
    _out_occ.erase(out);
  }
}

void SparseAllocator::PrintRequests( ostream * os ) const
{
  map<int, sRequest>::const_iterator iter;

  if(!os) os = &cout;

  *os << "Input requests = [ ";
  for ( int input = 0; input < _inputs; ++input ) {
    *os << input << " -> [ ";
    for ( iter = _in_req[input].begin( );
	  iter != _in_req[input].end( ); iter++ ) {
      *os << iter->second.port << " ";
    }
    *os << "]  ";
  }
  *os << "], output requests = [ ";
  for ( int output = 0; output < _outputs; ++output ) {
    *os << output << " -> ";
    *os << "[ ";
    for ( iter = _out_req[output].begin( );
	  iter != _out_req[output].end( ); iter++ ) {
      *os << iter->second.port << " ";
    }
    *os << "]  ";
  }
  *os << "]." << endl;
}

//==================================================
// Global allocator allocation function
//==================================================

Allocator *Allocator::NewAllocator( Module *parent, const string& name,
				    const string &alloc_type,
				    int inputs, int outputs,
				    int iters, const string &arb_type )
{
  Allocator *a = 0;

  if ( alloc_type == "max_size" ) {
    a = new MaxSizeMatch( parent, name, inputs, outputs );
  } else if ( alloc_type == "pim" ) {
    a = new PIM( parent, name, inputs, outputs, iters );
  } else if ( alloc_type == "islip" ) {
    a = new iSLIP_Sparse( parent, name, inputs, outputs, iters );
  } else if ( alloc_type == "loa" ) {
    a = new LOA( parent, name, inputs, outputs );
  } else if ( alloc_type == "wavefront" ) {
    a = new Wavefront( parent, name, inputs, outputs );
  } else if ( alloc_type == "fair_wavefront" ) {
    a = new FairWavefront( parent, name, inputs, outputs );
  } else if ( alloc_type == "prio_wavefront" ) {
    a = new PrioWavefront( parent, name, inputs, outputs );
  } else if ( alloc_type == "select" ) {
    a = new SelAlloc( parent, name, inputs, outputs, iters );
  } else if (alloc_type == "separable_input_first") {
    a = new SeparableInputFirstAllocator( parent, name, inputs, outputs,
					  arb_type );
  } else if (alloc_type == "separable_output_first") {
    a = new SeparableOutputFirstAllocator( parent, name, inputs, outputs,
					   arb_type );
  }

//==================================================
// Insert new allocators here, add another else if
//==================================================

  return a;
}

<commit_msg>simplify request removal for sparse allocator<commit_after>// $Id$

/*
Copyright (c) 2007-2009, Trustees of The Leland Stanford Junior University
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the Stanford University nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "booksim.hpp"
#include <iostream>
#include <cassert>
#include "allocator.hpp"

/////////////////////////////////////////////////////////////////////////
//Allocator types
#include "maxsize.hpp"
#include "pim.hpp"
#include "islip.hpp"
#include "loa.hpp"
#include "wavefront.hpp"
#include "fair_wavefront.hpp"
#include "prio_wavefront.hpp"
#include "selalloc.hpp"
#include "separable_input_first.hpp"
#include "separable_output_first.hpp"
//
/////////////////////////////////////////////////////////////////////////

//==================================================
// Allocator base class
//==================================================

Allocator::Allocator( Module *parent, const string& name,
		      int inputs, int outputs ) :
  Module( parent, name ), _inputs( inputs ), _outputs( outputs )
{
  _inmatch.resize(_inputs, -1);
  _outmatch.resize(_outputs, -1);
}

void Allocator::Clear( )
{
  _inmatch.assign(_inputs, -1);
  _outmatch.assign(_outputs, -1);
}

void Allocator::AddRequest( int in, int out, int label, int in_pri,
			    int out_pri ) {

  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );
  assert( label >= 0 );
}

int Allocator::OutputAssigned( int in ) const
{
  assert( ( in >= 0 ) && ( in < _inputs ) );

  return _inmatch[in];
}

int Allocator::InputAssigned( int out ) const
{
  assert( ( out >= 0 ) && ( out < _outputs ) );

  return _outmatch[out];
}

//==================================================
// DenseAllocator
//==================================================

DenseAllocator::DenseAllocator( Module *parent, const string& name,
				int inputs, int outputs ) :
  Allocator( parent, name, inputs, outputs )
{
  _request.resize(_inputs);

  for ( int i = 0; i < _inputs; ++i ) {
    _request[i].resize(_outputs);
    for ( int j = 0; j < _outputs; ++j ) {
      _request[i][j].label = -1;
    }
  }
}

void DenseAllocator::Clear( )
{
  for ( int i = 0; i < _inputs; ++i ) {
    for ( int j = 0; j < _outputs; ++j ) {
      _request[i][j].label = -1;
    }
  }
  Allocator::Clear();
}

int DenseAllocator::ReadRequest( int in, int out ) const
{
  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  return _request[in][out].label;
}

bool DenseAllocator::ReadRequest( sRequest &req, int in, int out ) const
{
  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  req = _request[in][out];

  return ( req.label != -1 );
}

void DenseAllocator::AddRequest( int in, int out, int label,
				 int in_pri, int out_pri )
{
  Allocator::AddRequest(in, out, label, in_pri, out_pri);

  if((_request[in][out].label == -1) || (_request[in][out].in_pri < in_pri)) {
    _request[in][out].label   = label;
    _request[in][out].in_pri  = in_pri;
    _request[in][out].out_pri = out_pri;
  }
}

void DenseAllocator::RemoveRequest( int in, int out, int label )
{
  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  _request[in][out].label = -1;
}

void DenseAllocator::PrintRequests( ostream * os ) const
{
  if(!os) os = &cout;
  *os << "Requests = [ ";
  for ( int i = 0; i < _inputs; ++i ) {
    *os << "[ ";
    for ( int j = 0; j < _outputs; ++j ) {
      *os << ( _request[i][j].label != -1 ) << " ";
    }
    *os << "] ";
  }
  *os << "]." << endl;
}

//==================================================
// SparseAllocator
//==================================================

SparseAllocator::SparseAllocator( Module *parent, const string& name,
				  int inputs, int outputs ) :
  Allocator( parent, name, inputs, outputs )
{
  _in_req.resize(_inputs);
  _out_req.resize(_outputs);
}

void SparseAllocator::Clear( )
{
  for ( int i = 0; i < _inputs; ++i ) {
    _in_req[i].clear( );
  }

  for ( int j = 0; j < _outputs; ++j ) {
    _out_req[j].clear( );
  }

  _in_occ.clear( );
  _out_occ.clear( );

  Allocator::Clear();
}

int SparseAllocator::ReadRequest( int in, int out ) const
{
  sRequest r;

  if ( ! ReadRequest( r, in, out ) ) {
    r.label = -1;
  }

  return r.label;
}

bool SparseAllocator::ReadRequest( sRequest &req, int in, int out ) const
{
  bool found;

  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  map<int, sRequest>::const_iterator match = _in_req[in].find(out);
  if ( match != _in_req[in].end( ) ) {
    req = match->second;
    found = true;
  } else {
    found = false;
  }

  return found;
}

void SparseAllocator::AddRequest( int in, int out, int label,
				  int in_pri, int out_pri )
{
  Allocator::AddRequest(in, out, label, in_pri, out_pri);

  // insert into occupied inputs set if
  // input is currently empty
  if ( _in_req[in].empty( ) ) {
    _in_occ.insert(in);
  }

  // similarly for the output
  if ( _out_req[out].empty( ) ) {
    _out_occ.insert(out);
  }

  sRequest req;
  req.port    = out;
  req.label   = label;
  req.in_pri  = in_pri;
  req.out_pri = out_pri;

  _in_req[in][out] = req;

  req.port  = in;
  req.label = label;

  _out_req[out][in] = req;
}

void SparseAllocator::RemoveRequest( int in, int out, int label )
{
  assert( ( in >= 0 ) && ( in < _inputs ) );
  assert( ( out >= 0 ) && ( out < _outputs ) );

  assert( _in_req[in].count( out ) > 0 );
  _in_req[in].erase( out );

  // remove from occupied inputs list if
  // input is now empty
  if ( _in_req[in].empty( ) ) {
    _in_occ.erase(in);
  }

  // similarly for the output
  assert( _out_req[out].count( out ) > 0 );
  _out_req[out].erase( out );

  if ( _out_req[out].empty( ) ) {
    _out_occ.erase(out);
  }
}

void SparseAllocator::PrintRequests( ostream * os ) const
{
  map<int, sRequest>::const_iterator iter;

  if(!os) os = &cout;

  *os << "Input requests = [ ";
  for ( int input = 0; input < _inputs; ++input ) {
    *os << input << " -> [ ";
    for ( iter = _in_req[input].begin( );
	  iter != _in_req[input].end( ); iter++ ) {
      *os << iter->second.port << " ";
    }
    *os << "]  ";
  }
  *os << "], output requests = [ ";
  for ( int output = 0; output < _outputs; ++output ) {
    *os << output << " -> ";
    *os << "[ ";
    for ( iter = _out_req[output].begin( );
	  iter != _out_req[output].end( ); iter++ ) {
      *os << iter->second.port << " ";
    }
    *os << "]  ";
  }
  *os << "]." << endl;
}

//==================================================
// Global allocator allocation function
//==================================================

Allocator *Allocator::NewAllocator( Module *parent, const string& name,
				    const string &alloc_type,
				    int inputs, int outputs,
				    int iters, const string &arb_type )
{
  Allocator *a = 0;

  if ( alloc_type == "max_size" ) {
    a = new MaxSizeMatch( parent, name, inputs, outputs );
  } else if ( alloc_type == "pim" ) {
    a = new PIM( parent, name, inputs, outputs, iters );
  } else if ( alloc_type == "islip" ) {
    a = new iSLIP_Sparse( parent, name, inputs, outputs, iters );
  } else if ( alloc_type == "loa" ) {
    a = new LOA( parent, name, inputs, outputs );
  } else if ( alloc_type == "wavefront" ) {
    a = new Wavefront( parent, name, inputs, outputs );
  } else if ( alloc_type == "fair_wavefront" ) {
    a = new FairWavefront( parent, name, inputs, outputs );
  } else if ( alloc_type == "prio_wavefront" ) {
    a = new PrioWavefront( parent, name, inputs, outputs );
  } else if ( alloc_type == "select" ) {
    a = new SelAlloc( parent, name, inputs, outputs, iters );
  } else if (alloc_type == "separable_input_first") {
    a = new SeparableInputFirstAllocator( parent, name, inputs, outputs,
					  arb_type );
  } else if (alloc_type == "separable_output_first") {
    a = new SeparableOutputFirstAllocator( parent, name, inputs, outputs,
					   arb_type );
  }

//==================================================
// Insert new allocators here, add another else if
//==================================================

  return a;
}

<|endoftext|>


<commit_before>void lego() {
// macro to visualize the lego plots generated by gAlive->RunLego

   gROOT->Reset();
   TFile *file = new TFile("galice.root");

   Float_t theta = 10;
   Float_t phi   = 170;
   Int_t ncont   = 50;

   TCanvas *cgcm2 = new TCanvas("cgcm2","gcm2",200,100,600,400);
   cgcm2->SetTheta(theta);
   cgcm2->SetPhi(phi);
   TH2F *hgcm2 = (TH2F*)file->Get("hgcm2");
   hgcm2->SetFillColor(2);
   hgcm2->SetMaximum(1);
   hgcm2->SetContour(ncont);
   hgcm2->SetMaximum(50);
   hgcm2->Draw("lego2sphe");

   TCanvas *cabso = new TCanvas("cabso","abso",100,50,600,400);
   cabso->SetTheta(theta);
   cabso->SetPhi(phi);
   TH2F *habso = (TH2F*)file->Get("habso");
   habso->SetFillColor(2);
   habso->SetMaximum(1);
   habso->SetContour(ncont);
   habso->SetMaximum(1);
   habso->Draw("lego2sphe");

   TCanvas *cradl = new TCanvas("cradl","radl",10,10,600,400);
   cradl->SetTheta(theta);
   cradl->SetPhi(phi);
   TH2F *hradl = (TH2F*)file->Get("hradl");
   hradl->SetFillColor(2);
   hradl->SetMaximum(1);
   hradl->SetContour(ncont);
   hradl->SetMaximum(5);
   hradl->Draw("lego2sphe");

   TCanvas *cetar = new TCanvas("cetar","etar",10,10,600,400);
   cetar->SetTheta(theta);
   cetar->SetPhi(phi);
   TH2F *hetar = (TH2F*)file->Get("hetar");
   hetar->SetFillColor(2);
   hetar->SetMaximum(1);
   hetar->SetContour(ncont);
   hetar->SetMaximum(5);
   hetar->Draw("lego2sphe");
}
<commit_msg>Pseudorapidity histogram removed.<commit_after>void lego() {
// macro to visualize the lego plots generated by gAlive->RunLego

   gROOT->Reset();
   TFile *file = new TFile("galice.root");

   Float_t theta = 10;
   Float_t phi   = 170;
   Int_t ncont   = 50;

   TCanvas *cgcm2 = new TCanvas("cgcm2","gcm2",200,100,600,400);
   cgcm2->SetTheta(theta);
   cgcm2->SetPhi(phi);
   TH2F *hgcm2 = (TH2F*)file->Get("hgcm2");
   hgcm2->SetFillColor(2);
   hgcm2->SetMaximum(1);
   hgcm2->SetContour(ncont);
   hgcm2->SetMaximum(50);
   hgcm2->Draw("lego2sphe");

   TCanvas *cabso = new TCanvas("cabso","abso",100,50,600,400);
   cabso->SetTheta(theta);
   cabso->SetPhi(phi);
   TH2F *habso = (TH2F*)file->Get("habso");
   habso->SetFillColor(2);
   habso->SetMaximum(1);
   habso->SetContour(ncont);
   habso->SetMaximum(1);
   habso->Draw("lego2sphe");

   TCanvas *cradl = new TCanvas("cradl","radl",10,10,600,400);
   cradl->SetTheta(theta);
   cradl->SetPhi(phi);
   TH2F *hradl = (TH2F*)file->Get("hradl");
   hradl->SetFillColor(2);
   hradl->SetMaximum(1);
   hradl->SetContour(ncont);
   hradl->SetMaximum(5);
   hradl->Draw("lego2sphe");
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: BGroups.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 02:06:47 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_connectivity.hxx"

#ifndef _CONNECTIVITY_ADABAS_GROUPS_HXX_
#include "adabas/BGroups.hxx"
#endif
#ifndef _CONNECTIVITY_ADABAS_GROUP_HXX_
#include "adabas/BGroup.hxx"
#endif
#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_
#include "adabas/BTable.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
#include <com/sun/star/sdbc/XRow.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
#include <com/sun/star/sdbc/XResultSet.hpp>
#endif
#ifndef _CONNECTIVITY_SDBCX_IREFRESHABLE_HXX_
#include "sdbcx/IRefreshable.hxx"
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif

using namespace ::comphelper;
using namespace connectivity;
using namespace connectivity::adabas;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
//  using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
typedef connectivity::sdbcx::OCollection OCollection_TYPE;
// -------------------------------------------------------------------------
sdbcx::ObjectType OGroups::createObject(const ::rtl::OUString& _rName)
{
    return new OAdabasGroup(m_pConnection,_rName);
}
// -------------------------------------------------------------------------
void OGroups::impl_refresh() throw(RuntimeException)
{
    m_pParent->refreshGroups();
}
// -------------------------------------------------------------------------
Reference< XPropertySet > OGroups::createDescriptor()
{
    //  OAdabasGroup* pNew =
    return new OAdabasGroup(m_pConnection);
}
// -------------------------------------------------------------------------
// XAppend
sdbcx::ObjectType OGroups::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& /*descriptor*/ )
{
    ::rtl::OUString aSql    = ::rtl::OUString::createFromAscii("CREATE USERGROUP ");
    ::rtl::OUString aQuote  = m_pConnection->getMetaData()->getIdentifierQuoteString(  );

    aSql = aSql + aQuote + _rForName + aQuote;

    Reference< XStatement > xStmt = m_pConnection->createStatement(  );
    xStmt->execute(aSql);
    ::comphelper::disposeComponent(xStmt);

    return createObject( _rForName );
}
// -------------------------------------------------------------------------
// XDrop
void OGroups::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString _sElementName)
{
    ::rtl::OUString aSql    = ::rtl::OUString::createFromAscii("DROP USERGROUP ");
    ::rtl::OUString aQuote  = m_pConnection->getMetaData()->getIdentifierQuoteString(  );

    aSql = aSql + aQuote + _sElementName + aQuote;

    Reference< XStatement > xStmt = m_pConnection->createStatement(  );
    xStmt->execute(aSql);
    ::comphelper::disposeComponent(xStmt);
}
// -------------------------------------------------------------------------

<commit_msg>INTEGRATION: CWS changefileheader (1.13.216); FILE MERGED 2008/04/01 19:56:13 thb 1.13.216.4: #i85898# Stripping all external header guards, now manually fixing misspelled ones and other compile-time breakage 2008/04/01 15:08:34 thb 1.13.216.3: #i85898# Stripping all external header guards 2008/04/01 10:52:47 thb 1.13.216.2: #i85898# Stripping all external header guards 2008/03/28 15:23:23 rt 1.13.216.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: BGroups.cxx,v $
 * $Revision: 1.14 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_connectivity.hxx"
#include "adabas/BGroups.hxx"
#include "adabas/BGroup.hxx"
#include "adabas/BTable.hxx"
#include <com/sun/star/sdbc/XRow.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <comphelper/types.hxx>

using namespace ::comphelper;
using namespace connectivity;
using namespace connectivity::adabas;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
//  using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
typedef connectivity::sdbcx::OCollection OCollection_TYPE;
// -------------------------------------------------------------------------
sdbcx::ObjectType OGroups::createObject(const ::rtl::OUString& _rName)
{
    return new OAdabasGroup(m_pConnection,_rName);
}
// -------------------------------------------------------------------------
void OGroups::impl_refresh() throw(RuntimeException)
{
    m_pParent->refreshGroups();
}
// -------------------------------------------------------------------------
Reference< XPropertySet > OGroups::createDescriptor()
{
    //  OAdabasGroup* pNew =
    return new OAdabasGroup(m_pConnection);
}
// -------------------------------------------------------------------------
// XAppend
sdbcx::ObjectType OGroups::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& /*descriptor*/ )
{
    ::rtl::OUString aSql    = ::rtl::OUString::createFromAscii("CREATE USERGROUP ");
    ::rtl::OUString aQuote  = m_pConnection->getMetaData()->getIdentifierQuoteString(  );

    aSql = aSql + aQuote + _rForName + aQuote;

    Reference< XStatement > xStmt = m_pConnection->createStatement(  );
    xStmt->execute(aSql);
    ::comphelper::disposeComponent(xStmt);

    return createObject( _rForName );
}
// -------------------------------------------------------------------------
// XDrop
void OGroups::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString _sElementName)
{
    ::rtl::OUString aSql    = ::rtl::OUString::createFromAscii("DROP USERGROUP ");
    ::rtl::OUString aQuote  = m_pConnection->getMetaData()->getIdentifierQuoteString(  );

    aSql = aSql + aQuote + _sElementName + aQuote;

    Reference< XStatement > xStmt = m_pConnection->createStatement(  );
    xStmt->execute(aSql);
    ::comphelper::disposeComponent(xStmt);
}
// -------------------------------------------------------------------------

<|endoftext|>