<commit_before>/*
 * Copyright 2010-2012 Esrille Inc.
 *
 * 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 "CSSInputStream.h"

#include <assert.h>
#include <string.h>

#include <unicode/ucnv.h>

#include <algorithm>

namespace {

const char* const CSSDefaultEncoding = "utf-8";

}

CSSInputStream::CSSInputStream(std::istream& stream, const std::string& optionalEncoding) :
    U16InputStream(stream, optionalEncoding)
{
}

bool CSSInputStream::detect(const char* p)
{
    static char be[] = { 0x00, 0x40, 0x00, 0x63, 0x00, 0x68, 0x00, 0x61, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x00, 0x74 };
    static char le[] = { 0x40, 0x00, 0x63, 0x00, 0x68, 0x00, 0x61, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x00, 0x74, 0x00 };

    std::string u16 = "";
    if (confidence == Certain)
        return false;
    if (strncmp(p, "\xfe\xff", 2) == 0 || strncmp(p, be, sizeof(be)) == 0) {
        encoding = "utf-16be";
        confidence = Irrelevant;
        u16 = beToAscii((*p == '\xfe') ? p + 2 : p);
        p = u16.c_str();
    } else if (strncmp(p, "\xff\xfe", 2) == 0 || strncmp(p, le, sizeof(le)) == 0) {
        encoding = "utf-16le";
        confidence = Irrelevant;
        u16 = leToAscii((*p == '\xff') ? p + 2 : p);
        p = u16.c_str();
    } else if (strncmp(p, "\xef\xbb\xbf", 3) == 0) {
        encoding = "utf-8";
        confidence = Irrelevant;
        p += 3;
    }

    if (strncmp(p, "@charset", 8) != 0) {
        if (confidence == Tentative)
            encoding = CSSDefaultEncoding;
        return false;
    }
    std::string tentative;
    p = skipSpace(p + 8);
    char quote = *p++;
    if (quote == '\'' || quote == '"') {
        for (;;) {
            if (!*p) {
                encoding = "";
                return false;
            }
            if (*p == quote) {
                p = skipSpace(++p);
                if (*p != ';') {
                    encoding = "";
                    return false;
                }
                break;
            }
            tentative += *p++;
        }
    }
    if (confidence == Tentative) {
        encoding = tentative;
        return false;
    }
    if (strcasecmp(tentative.c_str(), "utf-16") == 0 && strncmp(encoding.c_str(), "utf-16", 6) == 0 ||
        strcasecmp(encoding.c_str(), tentative.c_str()) == 0)
        return false;
    encoding = "";
    return false;
}
<commit_msg>(CSSInputStream::detect) : Check @charset syntax strictly; cf. at-charset-056.<commit_after>/*
 * Copyright 2010-2012 Esrille Inc.
 *
 * 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 "CSSInputStream.h"

#include <assert.h>
#include <string.h>

#include <unicode/ucnv.h>

#include <algorithm>

namespace {

const char* const CSSDefaultEncoding = "utf-8";

}

CSSInputStream::CSSInputStream(std::istream& stream, const std::string& optionalEncoding) :
    U16InputStream(stream, optionalEncoding)
{
}

bool CSSInputStream::detect(const char* p)
{
    static char be[] = { 0x00, 0x40, 0x00, 0x63, 0x00, 0x68, 0x00, 0x61, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x00, 0x74 };
    static char le[] = { 0x40, 0x00, 0x63, 0x00, 0x68, 0x00, 0x61, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x00, 0x74, 0x00 };

    std::string u16 = "";
    if (confidence == Certain)
        return false;
    if (strncmp(p, "\xfe\xff", 2) == 0 || strncmp(p, be, sizeof(be)) == 0) {
        encoding = "utf-16be";
        confidence = Irrelevant;
        u16 = beToAscii((*p == '\xfe') ? p + 2 : p);
        p = u16.c_str();
    } else if (strncmp(p, "\xff\xfe", 2) == 0 || strncmp(p, le, sizeof(le)) == 0) {
        encoding = "utf-16le";
        confidence = Irrelevant;
        u16 = leToAscii((*p == '\xff') ? p + 2 : p);
        p = u16.c_str();
    } else if (strncmp(p, "\xef\xbb\xbf", 3) == 0) {
        encoding = "utf-8";
        confidence = Irrelevant;
        p += 3;
    }

    if (strncmp(p, "@charset", 8) != 0) {
        if (confidence == Tentative)
            encoding = CSSDefaultEncoding;
        return false;
    }
    std::string tentative;
    p += 8;
    if (*p++ != ' ' || *p++ != '"') {
        encoding = "";
        return false;
    }
    for (;;) {
        if (!*p) {
            encoding = "";
            return false;
        }
        if (*p == '"') {
            if (*++p != ';') {
                encoding = "";
                return false;
            }
            break;
        }
        tentative += *p++;
    }
    if (confidence == Tentative) {
        encoding = tentative;
        return false;
    }
    if (strcasecmp(tentative.c_str(), "utf-16") == 0 && strncmp(encoding.c_str(), "utf-16", 6) == 0 ||
        strcasecmp(encoding.c_str(), tentative.c_str()) == 0)
        return false;
    encoding = "";
    return false;
}
<|endoftext|>


<commit_before>// Filename: bulletCharacterControllerNode.cxx
// Created by:  enn0x (21Nov10)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University.  All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license.  You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////

#include "bulletCharacterControllerNode.h"

TypeHandle BulletCharacterControllerNode::_type_handle;

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::Constructor
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
BulletCharacterControllerNode::
BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const char *name) : BulletBaseCharacterControllerNode(name) {

  // Synchronised transform
  _sync = TransformState::make_identity();
  _sync_disable = false;

  // Initial transform
  btTransform trans = btTransform::getIdentity();

  // Get convex shape (for ghost object)
  if (!shape->is_convex()) {
    bullet_cat.error() << "a convex shape is required!" << endl;
    return;
  }

  btConvexShape *convex = (btConvexShape *)(shape->ptr());

  // Ghost object
  _ghost = new btPairCachingGhostObject();
  _ghost->setUserPointer(this);

  _ghost->setWorldTransform(trans);
  _ghost->setInterpolationWorldTransform(trans);
  _ghost->setCollisionShape(convex);
  _ghost->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);

  // Up axis
  _up = get_default_up_axis();

  // Initialise movement
  _linear_movement_is_local = false;
  _linear_movement.set(0.0f, 0.0f, 0.0f);
  _angular_movement = 0.0f;

  // Character controller
  _character = new btKinematicCharacterController(_ghost, convex, step_height, _up);
  _character->setGravity((btScalar)9.81f);

  // Retain a pointer to the shape
  _shape = shape;

  // Default collide mask
  // TODO set_into_collide_mask(CollideMask::all_on());
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_linear_movement
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_linear_movement(const LVector3 &movement, bool is_local) {

  nassertv(!movement.is_nan());

  _linear_movement = movement;
  _linear_movement_is_local = is_local;
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_angular_movement
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_angular_movement(PN_stdfloat omega) {

  _angular_movement = omega;
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::sync_p2b
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
sync_p2b(PN_stdfloat dt, int num_substeps) {

  // Synchronise global transform
  transform_changed();

  // Angular rotation
  btScalar angle = dt * deg_2_rad(_angular_movement);

  btMatrix3x3 m = _ghost->getWorldTransform().getBasis();
  btVector3 up = m[_up];

  m *= btMatrix3x3(btQuaternion(up, angle));

  _ghost->getWorldTransform().setBasis(m);

  // Linear movement
  LVector3 vp = _linear_movement / (btScalar)num_substeps;

  btVector3 v;
  if (_linear_movement_is_local) {
    btTransform xform = _ghost->getWorldTransform();
    xform.setOrigin(btVector3(0.0f, 0.0f, 0.0f));
    v = xform(LVecBase3_to_btVector3(vp));
  }
  else {
    v = LVecBase3_to_btVector3(vp);
  }

  //_character->setVelocityForTimeInterval(v, dt);
  _character->setWalkDirection(v * dt);
  _angular_movement = 0.0f;
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::sync_b2p
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
sync_b2p() {

  NodePath np = NodePath::any_path((PandaNode *)this);
  LVecBase3 scale = np.get_net_transform()->get_scale();

  btTransform trans = _ghost->getWorldTransform();
  CPT(TransformState) ts = btTrans_to_TransformState(trans, scale);

  LMatrix4 m_sync = _sync->get_mat();
  LMatrix4 m_ts = ts->get_mat();

  if (!m_sync.almost_equal(m_ts)) {
    _sync = ts;
    _sync_disable = true;
    np.set_transform(NodePath(), ts);
    _sync_disable = false;
  }
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::transform_changed
//       Access: Protected
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
transform_changed() {

  if (_sync_disable) return;

  NodePath np = NodePath::any_path((PandaNode *)this);
  CPT(TransformState) ts = np.get_net_transform();

  LMatrix4 m_sync = _sync->get_mat();
  LMatrix4 m_ts = ts->get_mat();

  if (!m_sync.almost_equal(m_ts)) {
    _sync = ts;

    // Get translation, heading and scale
    LPoint3 pos = ts->get_pos();
    PN_stdfloat heading = ts->get_hpr().get_x();
    LVecBase3 scale = ts->get_scale();

    // Set translation
    _character->warp(LVecBase3_to_btVector3(pos));

    // Set Heading
    btMatrix3x3 m = _ghost->getWorldTransform().getBasis();
    btVector3 up = m[_up];

    m = btMatrix3x3(btQuaternion(up, heading));

    _ghost->getWorldTransform().setBasis(m);

    // Set scale
    _shape->set_local_scale(scale);
  }
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::get_shape
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
BulletShape *BulletCharacterControllerNode::
get_shape() const {

  return _shape;
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::is_on_ground
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
is_on_ground() const {

  return _character->onGround();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::can_jump
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
can_jump() const {

  return _character->canJump();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::do_jump
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
do_jump() {

  _character->jump();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_fall_speed
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_fall_speed(PN_stdfloat fall_speed) {

  _character->setFallSpeed((btScalar)fall_speed);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_jump_speed
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_jump_speed(PN_stdfloat jump_speed) {

  _character->setJumpSpeed((btScalar)jump_speed);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_max_jump_height
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_max_jump_height(PN_stdfloat max_jump_height) {

  _character->setMaxJumpHeight((btScalar)max_jump_height);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_max_slope
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_max_slope(PN_stdfloat max_slope) {

  _character->setMaxSlope((btScalar)max_slope);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::get_max_slope
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
PN_stdfloat BulletCharacterControllerNode::
get_max_slope() const {

  return (PN_stdfloat)_character->getMaxSlope();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::get_gravity
//  Description:
////////////////////////////////////////////////////////////////////
PN_stdfloat BulletCharacterControllerNode::
get_gravity() const {

  return (PN_stdfloat)_character->getGravity();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_gravity
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_gravity(PN_stdfloat gravity) {

  _character->setGravity((btScalar)gravity);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_use_ghost_sweep_test
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_use_ghost_sweep_test(bool value) {

  return _character->setUseGhostSweepTest(value);
}

<commit_msg>Bullet KCC: amended deg_to_rad in transform_changed.<commit_after>// Filename: bulletCharacterControllerNode.cxx
// Created by:  enn0x (21Nov10)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University.  All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license.  You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////

#include "bulletCharacterControllerNode.h"

TypeHandle BulletCharacterControllerNode::_type_handle;

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::Constructor
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
BulletCharacterControllerNode::
BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const char *name) : BulletBaseCharacterControllerNode(name) {

  // Synchronised transform
  _sync = TransformState::make_identity();
  _sync_disable = false;

  // Initial transform
  btTransform trans = btTransform::getIdentity();

  // Get convex shape (for ghost object)
  if (!shape->is_convex()) {
    bullet_cat.error() << "a convex shape is required!" << endl;
    return;
  }

  btConvexShape *convex = (btConvexShape *)(shape->ptr());

  // Ghost object
  _ghost = new btPairCachingGhostObject();
  _ghost->setUserPointer(this);

  _ghost->setWorldTransform(trans);
  _ghost->setInterpolationWorldTransform(trans);
  _ghost->setCollisionShape(convex);
  _ghost->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);

  // Up axis
  _up = get_default_up_axis();

  // Initialise movement
  _linear_movement_is_local = false;
  _linear_movement.set(0.0f, 0.0f, 0.0f);
  _angular_movement = 0.0f;

  // Character controller
  _character = new btKinematicCharacterController(_ghost, convex, step_height, _up);
  _character->setGravity((btScalar)9.81f);

  // Retain a pointer to the shape
  _shape = shape;

  // Default collide mask
  // TODO set_into_collide_mask(CollideMask::all_on());
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_linear_movement
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_linear_movement(const LVector3 &movement, bool is_local) {

  nassertv(!movement.is_nan());

  _linear_movement = movement;
  _linear_movement_is_local = is_local;
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_angular_movement
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_angular_movement(PN_stdfloat omega) {

  _angular_movement = omega;
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::sync_p2b
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
sync_p2b(PN_stdfloat dt, int num_substeps) {

  // Synchronise global transform
  transform_changed();

  // Angular rotation
  btScalar angle = dt * deg_2_rad(_angular_movement);

  btMatrix3x3 m = _ghost->getWorldTransform().getBasis();
  btVector3 up = m[_up];

  m *= btMatrix3x3(btQuaternion(up, angle));

  _ghost->getWorldTransform().setBasis(m);

  // Linear movement
  LVector3 vp = _linear_movement / (btScalar)num_substeps;

  btVector3 v;
  if (_linear_movement_is_local) {
    btTransform xform = _ghost->getWorldTransform();
    xform.setOrigin(btVector3(0.0f, 0.0f, 0.0f));
    v = xform(LVecBase3_to_btVector3(vp));
  }
  else {
    v = LVecBase3_to_btVector3(vp);
  }

  //_character->setVelocityForTimeInterval(v, dt);
  _character->setWalkDirection(v * dt);
  _angular_movement = 0.0f;
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::sync_b2p
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
sync_b2p() {

  NodePath np = NodePath::any_path((PandaNode *)this);
  LVecBase3 scale = np.get_net_transform()->get_scale();

  btTransform trans = _ghost->getWorldTransform();
  CPT(TransformState) ts = btTrans_to_TransformState(trans, scale);

  LMatrix4 m_sync = _sync->get_mat();
  LMatrix4 m_ts = ts->get_mat();

  if (!m_sync.almost_equal(m_ts)) {
    _sync = ts;
    _sync_disable = true;
    np.set_transform(NodePath(), ts);
    _sync_disable = false;
  }
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::transform_changed
//       Access: Protected
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
transform_changed() {

  if (_sync_disable) return;

  NodePath np = NodePath::any_path((PandaNode *)this);
  CPT(TransformState) ts = np.get_net_transform();

  LMatrix4 m_sync = _sync->get_mat();
  LMatrix4 m_ts = ts->get_mat();

  if (!m_sync.almost_equal(m_ts)) {
    _sync = ts;

    // Get translation, heading and scale
    LPoint3 pos = ts->get_pos();
    PN_stdfloat heading = ts->get_hpr().get_x();
    LVecBase3 scale = ts->get_scale();

    // Set translation
    _character->warp(LVecBase3_to_btVector3(pos));

    // Set Heading
    btMatrix3x3 m = _ghost->getWorldTransform().getBasis();
    btVector3 up = m[_up];

    m = btMatrix3x3(btQuaternion(up, deg_2_rad(heading)));

    _ghost->getWorldTransform().setBasis(m);

    // Set scale
    _shape->set_local_scale(scale);
  }
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::get_shape
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
BulletShape *BulletCharacterControllerNode::
get_shape() const {

  return _shape;
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::is_on_ground
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
is_on_ground() const {

  return _character->onGround();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::can_jump
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
can_jump() const {

  return _character->canJump();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::do_jump
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
do_jump() {

  _character->jump();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_fall_speed
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_fall_speed(PN_stdfloat fall_speed) {

  _character->setFallSpeed((btScalar)fall_speed);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_jump_speed
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_jump_speed(PN_stdfloat jump_speed) {

  _character->setJumpSpeed((btScalar)jump_speed);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_max_jump_height
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_max_jump_height(PN_stdfloat max_jump_height) {

  _character->setMaxJumpHeight((btScalar)max_jump_height);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_max_slope
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_max_slope(PN_stdfloat max_slope) {

  _character->setMaxSlope((btScalar)max_slope);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::get_max_slope
//       Access: Published
//  Description:
////////////////////////////////////////////////////////////////////
PN_stdfloat BulletCharacterControllerNode::
get_max_slope() const {

  return (PN_stdfloat)_character->getMaxSlope();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::get_gravity
//  Description:
////////////////////////////////////////////////////////////////////
PN_stdfloat BulletCharacterControllerNode::
get_gravity() const {

  return (PN_stdfloat)_character->getGravity();
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_gravity
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_gravity(PN_stdfloat gravity) {

  _character->setGravity((btScalar)gravity);
}

////////////////////////////////////////////////////////////////////
//     Function: BulletCharacterControllerNode::set_use_ghost_sweep_test
//  Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_use_ghost_sweep_test(bool value) {

  return _character->setUseGhostSweepTest(value);
}

<|endoftext|>


<commit_before>#ifndef BUILTINS_H_
#define BUILTINS_H_

#include <string>
#include <unordered_map>
#include <functional>
#include <stdexcept>
#include <cmath>
#include <boost/any.hpp>

#include "global.hpp"
#include "operators.hpp"

namespace lang {

  typedef std::unordered_map<Operator, std::unordered_map<std::string, boost::any>, OperatorHash> OperatorMap;
  extern OperatorMap opsMap;

  class Object : Stringifyable {
  public:
    typedef std::function<Object*(Object*, Object*)> BinaryOp;
    typedef std::function<Object*(Object*)> UnaryOp;

    Object();
    virtual ~Object();

    virtual std::string toString() = 0;
    virtual std::string getTypeData() = 0; // Pure virtual, derived classes must implement this
  };

  inline std::ostream& operator<<(std::ostream& os, Object& obj) {
    return os << "Object[" << obj.toString() << "]";
  }

  void concatenateNames(std::string& result);

  template<typename... Args>
  void concatenateNames(std::string& result, Object* obj, Args... args) {
    result += obj->getTypeData() + " ";
    concatenateNames(result, args...);
  }

  template<typename... Args>
  Object* runOperator(Operator* op, Args... pr) {
    std::string funSig = "";
    concatenateNames(funSig, pr...);
    // TODO: handle case where operator function is undefined for given types
    // 1. Get a boost::any instance from the OperatorMap
    // 2. Use boost::any_cast to get a pointer to the operator function
    // 3. Dereference pointer and call function
    auto result = (*boost::any_cast<std::function<Object*(Args...)>*>(opsMap[*op][funSig]))(pr...);
    return result;
  }

  class Variable : public Object {
  private:
    Object* internal = nullptr;
  public:
    Variable();
    Variable(Object* obj);

    std::string toString();
    std::string getTypeData();

    void assign(Object* newObj);
    Object* read();
  };

  class String : public Object {
  private:
    std::string internal = "";
  public:
    String();
    String(std::string str);

    std::string toString();
    std::string getTypeData();

    std::string getString();
  };

  // TODO: Number<T> class, with T = int64 || double64

  class Float : public Object {
  private:
    double64 internal = 0.0;
  public:
    Float();
    Float(std::string str);
    Float(double64 f);

    std::string toString();
    std::string getTypeData();

    double64 getNumber();
  };

  class Integer : public Object {
  private:
    int64 internal = 0;
  public:
    Integer();
    Integer(std::string str, int base);
    Integer(int64 i);

    std::string toString();
    std::string getTypeData();

    int64 getNumber();
  };

}; /* namespace lang */

#endif /* BUILTINS_H_ */
<commit_msg>Added TODO<commit_after>#ifndef BUILTINS_H_
#define BUILTINS_H_

#include <string>
#include <unordered_map>
#include <functional>
#include <stdexcept>
#include <cmath>
#include <boost/any.hpp>

#include "global.hpp"
#include "operators.hpp"

namespace lang {

  typedef std::unordered_map<Operator, std::unordered_map<std::string, boost::any>, OperatorHash> OperatorMap;
  extern OperatorMap opsMap;

  class Object : Stringifyable {
  public:
    typedef std::function<Object*(Object*, Object*)> BinaryOp;
    typedef std::function<Object*(Object*)> UnaryOp;

    Object();
    virtual ~Object();

    virtual std::string toString() = 0;
    virtual std::string getTypeData() = 0; // Pure virtual, derived classes must implement this
  };

  inline std::ostream& operator<<(std::ostream& os, Object& obj) {
    return os << "Object[" << obj.toString() << "]";
  }

  void concatenateNames(std::string& result);

  template<typename... Args>
  void concatenateNames(std::string& result, Object* obj, Args... args) {
    result += obj->getTypeData() + " ";
    concatenateNames(result, args...);
  }

  // TODO: check for nullptr in any of the arguments, throw SyntaxError. Get line numbers from higher up, maybe default param
  template<typename... Args>
  Object* runOperator(Operator* op, Args... pr) {
    std::string funSig = "";
    concatenateNames(funSig, pr...);
    // TODO: handle case where operator function is undefined for given types
    // 1. Get a boost::any instance from the OperatorMap
    // 2. Use boost::any_cast to get a pointer to the operator function
    // 3. Dereference pointer and call function
    auto result = (*boost::any_cast<std::function<Object*(Args...)>*>(opsMap[*op][funSig]))(pr...);
    return result;
  }

  class Variable : public Object {
  private:
    Object* internal = nullptr;
  public:
    Variable();
    Variable(Object* obj);

    std::string toString();
    std::string getTypeData();

    void assign(Object* newObj);
    Object* read();
  };

  class String : public Object {
  private:
    std::string internal = "";
  public:
    String();
    String(std::string str);

    std::string toString();
    std::string getTypeData();

    std::string getString();
  };

  // TODO: Number<T> class, with T = int64 || double64

  class Float : public Object {
  private:
    double64 internal = 0.0;
  public:
    Float();
    Float(std::string str);
    Float(double64 f);

    std::string toString();
    std::string getTypeData();

    double64 getNumber();
  };

  class Integer : public Object {
  private:
    int64 internal = 0;
  public:
    Integer();
    Integer(std::string str, int base);
    Integer(int64 i);

    std::string toString();
    std::string getTypeData();

    int64 getNumber();
  };

}; /* namespace lang */

#endif /* BUILTINS_H_ */
<|endoftext|>


<commit_before>#if defined (__GNUG__)

#include <string>
#include <iostream>
#include <stdexcept>
#include <tuple>
#include <iostream>
#include <type_traits>
#include <unistd.h>

#include "tpunit++.hpp"
#include "fakeit.h"
#include "mockutils/Formatter.h"

using namespace fakeit;

struct GccTypeInfoTests: tpunit::TestFixture {

	GccTypeInfoTests() :
			tpunit::TestFixture( //
					TEST(GccTypeInfoTests::simple_inheritance_dynamic_down_cast), TEST(GccTypeInfoTests::mutiple_inheritance_upcast)) {
	}

	struct TopLeft {
		int topLeft;
		virtual int f()=0;
	};

	struct Left: public TopLeft {
		int left;
		virtual int f() override = 0;
	};

	struct A: public Left {
		int a;
		virtual int f() override = 0;
	};

	void simple_inheritance_dynamic_down_cast() {
		Mock<A> aMock; // no need for base classes list on gcc.
		Stub(aMock[&A::f]);
		A& a = aMock.get();
		Left* left = &a;
		TopLeft* topLeft = &a;

		A* aPtr = dynamic_cast<A*>(left);
		ASSERT_EQUAL(0, aPtr->f());

		aPtr = dynamic_cast<A*>(topLeft);
		ASSERT_EQUAL(0, aPtr->f());

		left = dynamic_cast<Left*>(topLeft);
		ASSERT_EQUAL(0, left->f());
	}

	struct TopRight {
		int topRight;
		virtual int f()=0;
	};

	struct Right: public TopRight {
		int right;
		virtual int f() override = 0;
	};

	struct B: public Left, public Right {
		int b;
		virtual int f() override = 0;
	};

	void mutiple_inheritance_upcast() {
		//Mock<B> bMock; // should not compile
	}
//
} __GccTypeInfoTests;

#endif
<commit_msg>cleanup<commit_after>#if defined (__GNUG__)

#include <string>
#include <iostream>
#include <stdexcept>
#include <tuple>
#include <iostream>
#include <type_traits>

#include "tpunit++.hpp"
#include "fakeit.h"
#include "mockutils/Formatter.h"

using namespace fakeit;

struct GccTypeInfoTests: tpunit::TestFixture {

	GccTypeInfoTests() :
			tpunit::TestFixture( //
					TEST(GccTypeInfoTests::simple_inheritance_dynamic_down_cast), TEST(GccTypeInfoTests::mutiple_inheritance_upcast)) {
	}

	struct TopLeft {
		int topLeft;
		virtual int f()=0;
	};

	struct Left: public TopLeft {
		int left;
		virtual int f() override = 0;
	};

	struct A: public Left {
		int a;
		virtual int f() override = 0;
	};

	void simple_inheritance_dynamic_down_cast() {
		Mock<A> aMock; // no need for base classes list on gcc.
		Stub(aMock[&A::f]);
		A& a = aMock.get();
		Left* left = &a;
		TopLeft* topLeft = &a;

		A* aPtr = dynamic_cast<A*>(left);
		ASSERT_EQUAL(0, aPtr->f());

		aPtr = dynamic_cast<A*>(topLeft);
		ASSERT_EQUAL(0, aPtr->f());

		left = dynamic_cast<Left*>(topLeft);
		ASSERT_EQUAL(0, left->f());
	}

	struct TopRight {
		int topRight;
		virtual int f()=0;
	};

	struct Right: public TopRight {
		int right;
		virtual int f() override = 0;
	};

	struct B: public Left, public Right {
		int b;
		virtual int f() override = 0;
	};

	void mutiple_inheritance_upcast() {
		//Mock<B> bMock; // should not compile
	}
//
} __GccTypeInfoTests;

#endif
<|endoftext|>


<commit_before>#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <deque>
#include <map>
#include <string>

//#define debug(...) fprintf(stderr, ## __VA_ARGS__)
#define debug(...) (void)0

static const bool USE_HUFFMAN = true;

using std::deque;
using std::map;
using std::string;

struct TableEntry
{
    const string name, value;

    TableEntry(string name, string value = ""): name(name), value(value) {}

    unsigned size() const {
        return 32 + name.length() + value.length();
    }
};

#include "constants.h"

template <class It>
static int find(string name, string value, It p, It end, int offset)
{
    for (size_t i = 0; p != end; p++, i++) {
        if (p->name == name && p->value == value) {
            return i + offset;
        }
    }
    return 0;
}

template <class It>
static int find(string name, It p, It end, int offset)
{
    for (size_t i = 0; p != end; p++, i++) {
        if (p->name == name) {
            return i + offset;
        }
    }
    return 0;
}

static int find_static(string name)
{
    return find(name, static_table, static_table + STATIC_TABLE_COUNT, 1);
}
static int find_static(string name, string value)
{
    return find(name, value, static_table, static_table + STATIC_TABLE_COUNT, 1);
}

struct DynamicTable
{
    deque<TableEntry> table;
    unsigned size;

    DynamicTable(): size(0) {}

    void shrink(unsigned max_size) {
        while (size > max_size && table.size()) {
            TableEntry &e = table.back();
            debug("%u bytes over budget, evicting %s = %s for %u bytes\n", size - max_size, e.name.c_str(), e.value.c_str(), e.size());
            size -= e.size();
            table.pop_back();
        }
    }

    int find(string name, string value) {
        if (int i = find_static(name, value)) {
            return i;
        } else {
            return ::find(name, value, table.begin(), table.end(), dynamic_table_start);
        }
    }

    int find(string name) {
        if (int i = find_static(name)) {
            return i;
        } else {
            return ::find(name, table.begin(), table.end(), dynamic_table_start);
        }
    }

    void push(string name, string value) {
        table.push_front(TableEntry(name, value));
        size += table.front().size();
    }
};

static void put8(uint8_t v)
{
    fwrite(&v, 1, 1, stdout);
}

static void put_vint(unsigned value)
{
    while (value >= 0x80) {
        put8(0x80 | (value & 0x7f));
        value >>= 7;
    }
    put8(value);
}

static void put_int(uint8_t prebyte, unsigned prebits, unsigned value)
{
    const unsigned maxval = (1 << prebits) - 1;
    if (value < maxval) {
        put8(prebyte | value);
    } else {
        put8(prebyte | maxval);
        put_vint(value - maxval);
    }
}

static unsigned drain(string& out, unsigned& bits, unsigned len)
{
    while (len >= 8) {
        len -= 8;
        out += (char)(uint8_t)(bits >> len);
        bits &= (1 << len) - 1;
    }
    return len;
}

static string huff(const string &h)
{
    unsigned bits = 0;
    unsigned n = 0;

    string out;
    const char *p = h.c_str();
    while (uint8_t c = *p++) {
        uint32_t code = huff_codes[c];
        unsigned len = huff_lengths[c];
        if (len > 24) {
            bits <<= len - 24;
            bits |= (code >> (len - 25));
            n += len - 24;
            len = 24;
            n = drain(out, bits, n);
        }
        bits <<= len;
        bits |= code;
        n = drain(out, bits, n + len);
    }
    if (n) {
        bits <<= 7;
        bits |= 0x7f;
        n = drain(out, bits, n + 7);
    }
    return out;
}

static void put_string(const string &s)
{
    if (USE_HUFFMAN) {
        string h = huff(s);
        if (h.size() < s.size()) {
            put_int(0x80, 7, h.size());
            fwrite(h.c_str(), 1, h.length(), stdout);
            return;
        }
    }
    put_int(0, 7, s.size());
    fwrite(s.c_str(), 1, s.length(), stdout);
}

static string read_fully(FILE *fp)
{
    string t;
    while (!feof(fp)) {
        char tmp[1024];
        size_t n = fread(tmp, 1, sizeof(tmp), fp);
        t.append(tmp, n);
        assert(!ferror(fp));
    }
    return t;
}

int main(int argc, const char *argv[])
{
    const unsigned max_dynamic_size = 256;
    DynamicTable dyn_table;

    string input = read_fully(stdin);
    const char *pos = input.c_str();
    const char *input_end = pos + input.length();
    while (*pos) {
        const char *start = pos;
        const char *end = strchr(start, '\n');
        pos = end ? end + 1 : input_end;
        const char *name_end = strchr(start + 1, ':');
        const char *value_start = name_end + 1;
        value_start += strspn(value_start, " ");

        string name = string(start, name_end);
        string value = string(value_start, end ? end : input_end);

        debug("\nparsed %s = %s\n", name.c_str(), value.c_str());

        bool push = true;
        if (int i = dyn_table.find(name, value)) {
            debug("index (both): %d\n", i);
            push = false; // References are never added to the table.
            put_int(0x80, 7, i);
        } else if (int i = dyn_table.find(name)) {
            debug("index (name): %d\n", i);
            // put value as literal, may want to decide on indexed or not.
            put_int(0x40, 6, i);
            put_string(value);
        } else {
            debug("literal\n");
            // always indexed, but may want to decide :)
            put8(0x40);
            put_string(name);
            put_string(value);
        }
        if (push) {
            dyn_table.push(name, value);
            dyn_table.shrink(max_dynamic_size);
            debug("adding to dyn table: %s = %s (size = %u)\n", name.c_str(), value.c_str(), dyn_table.size);
        }
    }
}
<commit_msg>Set default dynamic size to 4kB<commit_after>#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <deque>
#include <map>
#include <string>

//#define debug(...) fprintf(stderr, ## __VA_ARGS__)
#define debug(...) (void)0

static const bool USE_HUFFMAN = true;

using std::deque;
using std::map;
using std::string;

struct TableEntry
{
    const string name, value;

    TableEntry(string name, string value = ""): name(name), value(value) {}

    unsigned size() const {
        return 32 + name.length() + value.length();
    }
};

#include "constants.h"

template <class It>
static int find(string name, string value, It p, It end, int offset)
{
    for (size_t i = 0; p != end; p++, i++) {
        if (p->name == name && p->value == value) {
            return i + offset;
        }
    }
    return 0;
}

template <class It>
static int find(string name, It p, It end, int offset)
{
    for (size_t i = 0; p != end; p++, i++) {
        if (p->name == name) {
            return i + offset;
        }
    }
    return 0;
}

static int find_static(string name)
{
    return find(name, static_table, static_table + STATIC_TABLE_COUNT, 1);
}
static int find_static(string name, string value)
{
    return find(name, value, static_table, static_table + STATIC_TABLE_COUNT, 1);
}

struct DynamicTable
{
    deque<TableEntry> table;
    unsigned size;

    DynamicTable(): size(0) {}

    void shrink(unsigned max_size) {
        while (size > max_size && table.size()) {
            TableEntry &e = table.back();
            debug("%u bytes over budget, evicting %s = %s for %u bytes\n", size - max_size, e.name.c_str(), e.value.c_str(), e.size());
            size -= e.size();
            table.pop_back();
        }
    }

    int find(string name, string value) {
        if (int i = find_static(name, value)) {
            return i;
        } else {
            return ::find(name, value, table.begin(), table.end(), dynamic_table_start);
        }
    }

    int find(string name) {
        if (int i = find_static(name)) {
            return i;
        } else {
            return ::find(name, table.begin(), table.end(), dynamic_table_start);
        }
    }

    void push(string name, string value) {
        table.push_front(TableEntry(name, value));
        size += table.front().size();
    }
};

static void put8(uint8_t v)
{
    fwrite(&v, 1, 1, stdout);
}

static void put_vint(unsigned value)
{
    while (value >= 0x80) {
        put8(0x80 | (value & 0x7f));
        value >>= 7;
    }
    put8(value);
}

static void put_int(uint8_t prebyte, unsigned prebits, unsigned value)
{
    const unsigned maxval = (1 << prebits) - 1;
    if (value < maxval) {
        put8(prebyte | value);
    } else {
        put8(prebyte | maxval);
        put_vint(value - maxval);
    }
}

static unsigned drain(string& out, unsigned& bits, unsigned len)
{
    while (len >= 8) {
        len -= 8;
        out += (char)(uint8_t)(bits >> len);
        bits &= (1 << len) - 1;
    }
    return len;
}

static string huff(const string &h)
{
    unsigned bits = 0;
    unsigned n = 0;

    string out;
    const char *p = h.c_str();
    while (uint8_t c = *p++) {
        uint32_t code = huff_codes[c];
        unsigned len = huff_lengths[c];
        if (len > 24) {
            bits <<= len - 24;
            bits |= (code >> (len - 25));
            n += len - 24;
            len = 24;
            n = drain(out, bits, n);
        }
        bits <<= len;
        bits |= code;
        n = drain(out, bits, n + len);
    }
    if (n) {
        bits <<= 7;
        bits |= 0x7f;
        n = drain(out, bits, n + 7);
    }
    return out;
}

static void put_string(const string &s)
{
    if (USE_HUFFMAN) {
        string h = huff(s);
        if (h.size() < s.size()) {
            put_int(0x80, 7, h.size());
            fwrite(h.c_str(), 1, h.length(), stdout);
            return;
        }
    }
    put_int(0, 7, s.size());
    fwrite(s.c_str(), 1, s.length(), stdout);
}

static string read_fully(FILE *fp)
{
    string t;
    while (!feof(fp)) {
        char tmp[1024];
        size_t n = fread(tmp, 1, sizeof(tmp), fp);
        t.append(tmp, n);
        assert(!ferror(fp));
    }
    return t;
}

int main(int argc, const char *argv[])
{
    const unsigned max_dynamic_size = 4096;
    DynamicTable dyn_table;

    string input = read_fully(stdin);
    const char *pos = input.c_str();
    const char *input_end = pos + input.length();
    while (*pos) {
        const char *start = pos;
        const char *end = strchr(start, '\n');
        pos = end ? end + 1 : input_end;
        const char *name_end = strchr(start + 1, ':');
        const char *value_start = name_end + 1;
        value_start += strspn(value_start, " ");

        string name = string(start, name_end);
        string value = string(value_start, end ? end : input_end);

        debug("\nparsed %s = %s\n", name.c_str(), value.c_str());

        bool push = true;
        if (int i = dyn_table.find(name, value)) {
            debug("index (both): %d\n", i);
            push = false; // References are never added to the table.
            put_int(0x80, 7, i);
        } else if (int i = dyn_table.find(name)) {
            debug("index (name): %d\n", i);
            // put value as literal, may want to decide on indexed or not.
            put_int(0x40, 6, i);
            put_string(value);
        } else {
            debug("literal\n");
            // always indexed, but may want to decide :)
            put8(0x40);
            put_string(name);
            put_string(value);
        }
        if (push) {
            dyn_table.push(name, value);
            dyn_table.shrink(max_dynamic_size);
            debug("adding to dyn table: %s = %s (size = %u)\n", name.c_str(), value.c_str(), dyn_table.size);
        }
    }
}
<|endoftext|>


<commit_before>// Copyright (c) 2009-2016 The Regents of the University of Michigan
// This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

// this include is necessary to get MPI included before anything else to support intel MPI
#include "hoomd/ExecutionConfiguration.h"

#include <iostream>

#include <memory>

#include "hoomd/ComputeThermo.h"
#include "hoomd/md/TempRescaleUpdater.h"

#ifdef ENABLE_CUDA
#include "hoomd/ComputeThermoGPU.h"
#endif

#include <math.h>

using namespace std;

#include "hoomd/test/upp11_config.h"
HOOMD_UP_MAIN();

/*! \file temp_rescale_updater_test.cc
    \brief Unit tests for the ComputeThermo and TempRescaleUpdater classes.
    \ingroup unit_tests
*/

//! test case to verify proper operation of ComputeThermo
UP_TEST( ComputeThermo_basic )
    {
    // verify that we can constructe a TempCompute properly
    // create a simple particle data to test with
    std::shared_ptr<SystemDefinition> sysdef(new SystemDefinition(2, BoxDim(1000.0), 4));
    std::shared_ptr<ParticleData> pdata = sysdef->getParticleData();

    {
    ArrayHandle<Scalar4> h_pos(pdata->getPositions(), access_location::host, access_mode::readwrite);
    ArrayHandle<Scalar4> h_vel(pdata->getVelocities(), access_location::host, access_mode::readwrite);

    h_pos.data[0].x = h_pos.data[0].y = h_pos.data[0].z = 0.0;
    h_vel.data[0].x = 1.0; h_vel.data[0].y = 2.0; h_vel.data[0].z = 3.0;
    h_pos.data[1].x = h_pos.data[1].y = h_pos.data[1].z = 1.0;
    h_vel.data[1].x = 4.0; h_vel.data[1].y = 5.0; h_vel.data[1].z = 6.0;
    }

    // construct a TempCompute and see that everything is set properly
    std::shared_ptr<ParticleSelector> selector_all(new ParticleSelectorTag(sysdef, 0, pdata->getN()-1));
    std::shared_ptr<ParticleGroup> group_all(new ParticleGroup(sysdef, selector_all));
    std::shared_ptr<ComputeThermo> tc(new ComputeThermo(sysdef, group_all));

    // check that we can actually compute temperature
    tc->setNDOF(3*pdata->getN());
    tc->compute(0);
    MY_CHECK_CLOSE(tc->getTemperature(), 15.1666666666666666666667, tol);
    }

#ifdef ENABLE_CUDA
//! test case to verify proper operation of ComputeThermoGPU
UP_TEST( ComputeThermoGPU_basic )
    {
    // verify that we can constructe a TempCompute properly
    // create a simple particle data to test with
    std::shared_ptr<SystemDefinition> sysdef(new SystemDefinition(2, BoxDim(1000.0), 4));
    std::shared_ptr<ParticleData> pdata = sysdef->getParticleData();

    {
    ArrayHandle<Scalar4> h_pos(pdata->getPositions(), access_location::host, access_mode::readwrite);
    ArrayHandle<Scalar4> h_vel(pdata->getVelocities(), access_location::host, access_mode::readwrite);
    h_pos.data[0].x = h_pos.data[0].y = h_pos.data[0].z = 0.0;
    h_vel.data[0].x = 3.0; h_vel.data[0].y = 2.0; h_vel.data[0].z = 3.0;
    h_pos.data[1].x = h_pos.data[1].y = h_pos.data[1].z = 1.0;
    h_vel.data[1].x = 4.0; h_vel.data[1].y = 5.0; h_vel.data[1].z = 6.0;
    }

    // construct a TempCompute and see that everything is set properly
    std::shared_ptr<ParticleSelector> selector_all(new ParticleSelectorTag(sysdef, 0, pdata->getN()-1));
    std::shared_ptr<ParticleGroup> group_all(new ParticleGroup(sysdef, selector_all));
    std::shared_ptr<ComputeThermoGPU> tc(new ComputeThermoGPU(sysdef, group_all));

    // check that we can actually compute temperature
    tc->setNDOF(3*pdata->getN());
    tc->compute(0);
    MY_CHECK_CLOSE(tc->getTemperature(), 16.5, tol);
    }
#endif

//! test case to verify proper operation of TempRescaleUpdater
UP_TEST( TempRescaleUpdater_basic )
    {
    // create a simple particle data to test with
    std::shared_ptr<SystemDefinition> sysdef(new SystemDefinition(2, BoxDim(1000.0), 4));
    std::shared_ptr<ParticleData> pdata = sysdef->getParticleData();

    {
    ArrayHandle<Scalar4> h_pos(pdata->getPositions(), access_location::host, access_mode::readwrite);
    ArrayHandle<Scalar4> h_vel(pdata->getVelocities(), access_location::host, access_mode::readwrite);
    h_pos.data[0].x = h_pos.data[0].y = h_pos.data[0].z = 0.0;
    h_vel.data[0].x = 1.0; h_vel.data[0].y = 2.0; h_vel.data[0].z = 3.0;
    h_pos.data[1].x = h_pos.data[1].y = h_pos.data[1].z = 1.0;
    h_vel.data[1].x = 4.0; h_vel.data[1].y = 5.0; h_vel.data[1].z = 6.0;
    }

    // construct a Computethermo for the updater
    std::shared_ptr<ParticleSelector> selector_all(new ParticleSelectorTag(sysdef, 0, pdata->getN()-1));
    std::shared_ptr<ParticleGroup> group_all(new ParticleGroup(sysdef, selector_all));
    std::shared_ptr<ComputeThermo> tc(new ComputeThermo(sysdef, group_all));

    // variant T for the rescaler
    std::shared_ptr<VariantConst> T_variant(new VariantConst(1.2));

    // construct the updater and make sure everything is set properly
    std::shared_ptr<TempRescaleUpdater> rescaler(new TempRescaleUpdater(sysdef, tc, T_variant));

    // run the updater and check the new temperature
    rescaler->update(0);
    tc->compute(1);
    MY_CHECK_CLOSE(tc->getTemperature(), 1.2, tol);

    // check that the setT method works
    std::shared_ptr<VariantConst> T_variant2(new VariantConst(2.0));
    rescaler->setT(T_variant2);
    rescaler->update(1);
    tc->compute(2);
    MY_CHECK_CLOSE(tc->getTemperature(), 2.0, tol);
    }
<commit_msg>Attempting to debug failing temp_rescale test<commit_after>// Copyright (c) 2009-2016 The Regents of the University of Michigan
// This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

// this include is necessary to get MPI included before anything else to support intel MPI
#include "hoomd/ExecutionConfiguration.h"

#include <iostream>

#include <memory>

#include "hoomd/ComputeThermo.h"
#include "hoomd/md/TempRescaleUpdater.h"

#ifdef ENABLE_CUDA
#include "hoomd/ComputeThermoGPU.h"
#endif

#include <math.h>

using namespace std;

#include "hoomd/test/upp11_config.h"
HOOMD_UP_MAIN();

/*! \file temp_rescale_updater_test.cc
    \brief Unit tests for the ComputeThermo and TempRescaleUpdater classes.
    \ingroup unit_tests
*/

//! test case to verify proper operation of ComputeThermo
UP_TEST( ComputeThermo_basic )
    {
    // verify that we can constructe a TempCompute properly
    // create a simple particle data to test with
    std::shared_ptr<SystemDefinition> sysdef(new SystemDefinition(2, BoxDim(1000.0), 4));
    std::shared_ptr<ParticleData> pdata = sysdef->getParticleData();

    {
    ArrayHandle<Scalar4> h_pos(pdata->getPositions(), access_location::host, access_mode::readwrite);
    ArrayHandle<Scalar4> h_vel(pdata->getVelocities(), access_location::host, access_mode::readwrite);

    h_pos.data[0].x = h_pos.data[0].y = h_pos.data[0].z = 0.0;
    h_vel.data[0].x = 1.0; h_vel.data[0].y = 2.0; h_vel.data[0].z = 3.0;
    h_pos.data[1].x = h_pos.data[1].y = h_pos.data[1].z = 1.0;
    h_vel.data[1].x = 4.0; h_vel.data[1].y = 5.0; h_vel.data[1].z = 6.0;
    }

    // construct a TempCompute and see that everything is set properly
    std::shared_ptr<ParticleSelector> selector_all(new ParticleSelectorTag(sysdef, 0, pdata->getN()-1));
    std::shared_ptr<ParticleGroup> group_all(new ParticleGroup(sysdef, selector_all));
    std::shared_ptr<ComputeThermo> tc(new ComputeThermo(sysdef, group_all));

    // check that we can actually compute temperature
    tc->setNDOF(3*pdata->getN());
    tc->compute(0);
    MY_CHECK_CLOSE(tc->getTemperature(), 15.1666666666666666666667, tol);
    }

#ifdef ENABLE_CUDA
//! test case to verify proper operation of ComputeThermoGPU
UP_TEST( ComputeThermoGPU_basic )
    {
    // verify that we can constructe a TempCompute properly
    // create a simple particle data to test with
    std::shared_ptr<SystemDefinition> sysdef(new SystemDefinition(2, BoxDim(1000.0), 4));
    std::shared_ptr<ParticleData> pdata = sysdef->getParticleData();

    {
    ArrayHandle<Scalar4> h_pos(pdata->getPositions(), access_location::host, access_mode::readwrite);
    ArrayHandle<Scalar4> h_vel(pdata->getVelocities(), access_location::host, access_mode::readwrite);
    h_pos.data[0].x = h_pos.data[0].y = h_pos.data[0].z = 0.0;
    h_vel.data[0].x = 3.0; h_vel.data[0].y = 2.0; h_vel.data[0].z = 3.0;
    h_pos.data[1].x = h_pos.data[1].y = h_pos.data[1].z = 1.0;
    h_vel.data[1].x = 4.0; h_vel.data[1].y = 5.0; h_vel.data[1].z = 6.0;
    }

    // construct a TempCompute and see that everything is set properly
    std::shared_ptr<ParticleSelector> selector_all(new ParticleSelectorTag(sysdef, 0, pdata->getN()-1));
    std::shared_ptr<ParticleGroup> group_all(new ParticleGroup(sysdef, selector_all));
    std::shared_ptr<ComputeThermoGPU> tc(new ComputeThermoGPU(sysdef, group_all));

    // check that we can actually compute temperature
    tc->setNDOF(3*pdata->getN());
    tc->compute(0);
    Scalar cur_T = tc->getTemperature();
    cout << "Testing: T=" << cur_T << endl;
    MY_CHECK_CLOSE(T, 16.5, tol);
    }
#endif

//! test case to verify proper operation of TempRescaleUpdater
UP_TEST( TempRescaleUpdater_basic )
    {
    // create a simple particle data to test with
    std::shared_ptr<SystemDefinition> sysdef(new SystemDefinition(2, BoxDim(1000.0), 4));
    std::shared_ptr<ParticleData> pdata = sysdef->getParticleData();

    {
    ArrayHandle<Scalar4> h_pos(pdata->getPositions(), access_location::host, access_mode::readwrite);
    ArrayHandle<Scalar4> h_vel(pdata->getVelocities(), access_location::host, access_mode::readwrite);
    h_pos.data[0].x = h_pos.data[0].y = h_pos.data[0].z = 0.0;
    h_vel.data[0].x = 1.0; h_vel.data[0].y = 2.0; h_vel.data[0].z = 3.0;
    h_pos.data[1].x = h_pos.data[1].y = h_pos.data[1].z = 1.0;
    h_vel.data[1].x = 4.0; h_vel.data[1].y = 5.0; h_vel.data[1].z = 6.0;
    }

    // construct a Computethermo for the updater
    std::shared_ptr<ParticleSelector> selector_all(new ParticleSelectorTag(sysdef, 0, pdata->getN()-1));
    std::shared_ptr<ParticleGroup> group_all(new ParticleGroup(sysdef, selector_all));
    std::shared_ptr<ComputeThermo> tc(new ComputeThermo(sysdef, group_all));

    // variant T for the rescaler
    std::shared_ptr<VariantConst> T_variant(new VariantConst(1.2));

    // construct the updater and make sure everything is set properly
    std::shared_ptr<TempRescaleUpdater> rescaler(new TempRescaleUpdater(sysdef, tc, T_variant));

    // run the updater and check the new temperature
    rescaler->update(0);
    tc->compute(1);
    MY_CHECK_CLOSE(tc->getTemperature(), 1.2, tol);

    // check that the setT method works
    std::shared_ptr<VariantConst> T_variant2(new VariantConst(2.0));
    rescaler->setT(T_variant2);
    rescaler->update(1);
    tc->compute(2);
    MY_CHECK_CLOSE(tc->getTemperature(), 2.0, tol);
    }
<|endoftext|>


<commit_before>/* BEGIN_COMMON_COPYRIGHT_HEADER
 * (c)LGPL2+
 *
 * LXQt - a lightweight, Qt based, desktop toolset
 * http://razor-qt.org
 *
 * Copyright: 2012 Razor team
 * Authors:
 *   Alexander Sokoloff <sokoloff.a@gmail.com>
 *
 * This program or library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * END_COMMON_COPYRIGHT_HEADER */

#include "lxqtthemeconfig.h"
#include "ui_lxqtthemeconfig.h"
#include <QTreeWidget>
#include <QStandardPaths>
#include <QProcess>
#include <QItemDelegate>
#include <QPainter>

/*!
 * \brief Simple delegate to draw system background color below decoration/icon
 * (needed by System theme, which uses widget background and therefore provides semi-transparent preview)
 */
class ThemeDecorator : public QItemDelegate
{
public:
    using QItemDelegate::QItemDelegate;
protected:
    virtual void drawDecoration(QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect, const QPixmap & pixmap) const override
    {
        //Note: can't use QItemDelegate::drawDecoration, because it is ignoring pixmap,
        //if the icon is valid (and that is set in paint())
        if (pixmap.isNull() || !rect.isValid())
            return;

        QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmap.size(), rect).topLeft();
        painter->fillRect(QRect{p, pixmap.size()}, QApplication::palette().color(QPalette::Window));
        painter->drawPixmap(p, pixmap);
    }
};

/*!
 * \brief Check if currently configured wallpaper (read from pcmanfm-qt's
 * settings) is the same as \param themeWallpaper
 */
static bool isWallpaperChanged(const QString & themeWallpaper)
{
    static const QString config_path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
        + QStringLiteral("/pcmanfm-qt/lxqt/settings.conf");
    static const QString wallpaper_key = QStringLiteral("Desktop/Wallpaper");
    const QString current_wallpaper = QSettings{config_path, QSettings::IniFormat}.value(wallpaper_key).toString();
    return themeWallpaper != current_wallpaper;
}

LXQtThemeConfig::LXQtThemeConfig(LXQt::Settings *settings, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LXQtThemeConfig),
    mSettings(settings)
{
    ui->setupUi(this);
    {
        QScopedPointer<QAbstractItemDelegate> p{ui->lxqtThemeList->itemDelegate()};
        ui->lxqtThemeList->setItemDelegate(new ThemeDecorator{this});
    }

    connect(ui->lxqtThemeList, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
            this, SLOT(lxqtThemeSelected(QTreeWidgetItem*,int)));
    connect(ui->wallpaperOverride, &QAbstractButton::toggled, [this] (bool checked) {
            if (checked)
                lxqtThemeSelected(ui->lxqtThemeList->currentItem(), 0/*not used*/);
    });

    QList<LXQt::LXQtTheme> themes = LXQt::LXQtTheme::allThemes();
    foreach(LXQt::LXQtTheme theme, themes)
    {
        QString themeName = theme.name();
        themeName[0] = themeName[0].toTitleCase();
        QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(themeName));
        if (!theme.previewImage().isEmpty())
        {
            item->setIcon(0, QIcon(theme.previewImage()));
        }
        item->setSizeHint(0, QSize(42,42)); // make icons non-cropped
        item->setData(0, Qt::UserRole, theme.name());
        ui->lxqtThemeList->addTopLevelItem(item);
    }

    initControls();
}

LXQtThemeConfig::~LXQtThemeConfig()
{
    delete ui;
}

void LXQtThemeConfig::initControls()
{
    QString currentTheme = mSettings->value("theme").toString();

    QTreeWidgetItemIterator it(ui->lxqtThemeList);
    while (*it) {
        if ((*it)->data(0, Qt::UserRole).toString() == currentTheme)
        {
            ui->lxqtThemeList->setCurrentItem((*it));
            break;
        }
        ++it;
    }

    update();
}

void LXQtThemeConfig::lxqtThemeSelected(QTreeWidgetItem* item, int column)
{
    Q_UNUSED(column);
    if (!item)
        return;

    LXQt::LXQtTheme currentTheme{mSettings->value("theme").toString()};
    QVariant themeName = item->data(0, Qt::UserRole);
    mSettings->setValue("theme", themeName);
    LXQt::LXQtTheme theme(themeName.toString());
    if(theme.isValid()) {
		QString wallpaper = theme.desktopBackground();
		if(!wallpaper.isEmpty() && (ui->wallpaperOverride->isChecked() || !isWallpaperChanged(currentTheme.desktopBackground()))) {
			// call pcmanfm-qt to update wallpaper
			QProcess process;
			QStringList args;
			args << "--set-wallpaper" << wallpaper;
			process.start("pcmanfm-qt", args, QIODevice::NotOpen);
			process.waitForFinished();
		}
	}
}
<commit_msg>appearance: Avoid blocking when setting wallpaper<commit_after>/* BEGIN_COMMON_COPYRIGHT_HEADER
 * (c)LGPL2+
 *
 * LXQt - a lightweight, Qt based, desktop toolset
 * http://razor-qt.org
 *
 * Copyright: 2012 Razor team
 * Authors:
 *   Alexander Sokoloff <sokoloff.a@gmail.com>
 *
 * This program or library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * END_COMMON_COPYRIGHT_HEADER */

#include "lxqtthemeconfig.h"
#include "ui_lxqtthemeconfig.h"
#include <QTreeWidget>
#include <QStandardPaths>
#include <QProcess>
#include <QItemDelegate>
#include <QPainter>

/*!
 * \brief Simple delegate to draw system background color below decoration/icon
 * (needed by System theme, which uses widget background and therefore provides semi-transparent preview)
 */
class ThemeDecorator : public QItemDelegate
{
public:
    using QItemDelegate::QItemDelegate;
protected:
    virtual void drawDecoration(QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect, const QPixmap & pixmap) const override
    {
        //Note: can't use QItemDelegate::drawDecoration, because it is ignoring pixmap,
        //if the icon is valid (and that is set in paint())
        if (pixmap.isNull() || !rect.isValid())
            return;

        QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmap.size(), rect).topLeft();
        painter->fillRect(QRect{p, pixmap.size()}, QApplication::palette().color(QPalette::Window));
        painter->drawPixmap(p, pixmap);
    }
};

/*!
 * \brief Check if currently configured wallpaper (read from pcmanfm-qt's
 * settings) is the same as \param themeWallpaper
 */
static bool isWallpaperChanged(const QString & themeWallpaper)
{
    static const QString config_path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
        + QStringLiteral("/pcmanfm-qt/lxqt/settings.conf");
    static const QString wallpaper_key = QStringLiteral("Desktop/Wallpaper");
    const QString current_wallpaper = QSettings{config_path, QSettings::IniFormat}.value(wallpaper_key).toString();
    return themeWallpaper != current_wallpaper;
}

LXQtThemeConfig::LXQtThemeConfig(LXQt::Settings *settings, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LXQtThemeConfig),
    mSettings(settings)
{
    ui->setupUi(this);
    {
        QScopedPointer<QAbstractItemDelegate> p{ui->lxqtThemeList->itemDelegate()};
        ui->lxqtThemeList->setItemDelegate(new ThemeDecorator{this});
    }

    connect(ui->lxqtThemeList, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
            this, SLOT(lxqtThemeSelected(QTreeWidgetItem*,int)));
    connect(ui->wallpaperOverride, &QAbstractButton::toggled, [this] (bool checked) {
            if (checked)
                lxqtThemeSelected(ui->lxqtThemeList->currentItem(), 0/*not used*/);
    });

    QList<LXQt::LXQtTheme> themes = LXQt::LXQtTheme::allThemes();
    foreach(LXQt::LXQtTheme theme, themes)
    {
        QString themeName = theme.name();
        themeName[0] = themeName[0].toTitleCase();
        QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(themeName));
        if (!theme.previewImage().isEmpty())
        {
            item->setIcon(0, QIcon(theme.previewImage()));
        }
        item->setSizeHint(0, QSize(42,42)); // make icons non-cropped
        item->setData(0, Qt::UserRole, theme.name());
        ui->lxqtThemeList->addTopLevelItem(item);
    }

    initControls();
}

LXQtThemeConfig::~LXQtThemeConfig()
{
    delete ui;
}

void LXQtThemeConfig::initControls()
{
    QString currentTheme = mSettings->value("theme").toString();

    QTreeWidgetItemIterator it(ui->lxqtThemeList);
    while (*it) {
        if ((*it)->data(0, Qt::UserRole).toString() == currentTheme)
        {
            ui->lxqtThemeList->setCurrentItem((*it));
            break;
        }
        ++it;
    }

    update();
}

void LXQtThemeConfig::lxqtThemeSelected(QTreeWidgetItem* item, int column)
{
    Q_UNUSED(column);
    if (!item)
        return;

    LXQt::LXQtTheme currentTheme{mSettings->value("theme").toString()};
    QVariant themeName = item->data(0, Qt::UserRole);
    mSettings->setValue("theme", themeName);
    LXQt::LXQtTheme theme(themeName.toString());
    if(theme.isValid()) {
		QString wallpaper = theme.desktopBackground();
		if(!wallpaper.isEmpty() && (ui->wallpaperOverride->isChecked() || !isWallpaperChanged(currentTheme.desktopBackground()))) {
			// call pcmanfm-qt to update wallpaper
			QStringList args;
			args << "--set-wallpaper" << wallpaper;
			QProcess::startDetached("pcmanfm-qt", args);
		}
	}
}
<|endoftext|>


<commit_before><commit_msg>Bugfix: `delete` -> `delete[]` x 3.<commit_after><|endoftext|>


<commit_before>// ***************************************************************************
//
//   Generated automatically by genwrapper.
//   Please DO NOT EDIT this file!
//
// ***************************************************************************

#include <osgIntrospection/ReflectionMacros>
#include <osgIntrospection/TypedMethodInfo>
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>

#include <osg/CopyOp>
#include <osg/Image>
#include <osg/Object>
#include <osg/TransferFunction>
#include <osg/Vec4>

// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
#undef IN
#endif
#ifdef OUT
#undef OUT
#endif

BEGIN_OBJECT_REFLECTOR(osg::TransferFunction)
	I_DeclaringFile("osg/TransferFunction");
	I_BaseType(osg::Object);
	I_Constructor0(____TransferFunction,
	               "",
	               "");
	I_ConstructorWithDefaults2(IN, const osg::TransferFunction &, tf, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY,
	                           ____TransferFunction__C5_TransferFunction_R1__C5_CopyOp_R1,
	                           "Copy constructor using CopyOp to manage deep vs shallow copy. ",
	                           "");
	I_Method0(osg::Object *, cloneType,
	          Properties::VIRTUAL,
	          __osg_Object_P1__cloneType,
	          "Clone the type of an object, with Object* return type. ",
	          "Must be defined by derived classes. ");
	I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop,
	          Properties::VIRTUAL,
	          __osg_Object_P1__clone__C5_osg_CopyOp_R1,
	          "Clone an object, with Object* return type. ",
	          "Must be defined by derived classes. ");
	I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj,
	          Properties::VIRTUAL,
	          __bool__isSameKindAs__C5_osg_Object_P1,
	          "",
	          "");
	I_Method0(const char *, libraryName,
	          Properties::VIRTUAL,
	          __C5_char_P1__libraryName,
	          "return the name of the object's library. ",
	          "Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. ");
	I_Method0(const char *, className,
	          Properties::VIRTUAL,
	          __C5_char_P1__className,
	          "return the name of the object's class type. ",
	          "Must be defined by derived classes. ");
	I_Method0(osg::Image *, getImage,
	          Properties::NON_VIRTUAL,
	          __osg_Image_P1__getImage,
	          "",
	          "");
	I_Method0(const osg::Image *, getImage,
	          Properties::NON_VIRTUAL,
	          __C5_osg_Image_P1__getImage,
	          "",
	          "");
	I_SimpleProperty(osg::Image *, Image,
	                 __osg_Image_P1__getImage,
	                 0);
END_REFLECTOR

TYPE_NAME_ALIAS(std::map< float COMMA  osg::Vec4 >, osg::TransferFunction1D::ColorMap)

BEGIN_OBJECT_REFLECTOR(osg::TransferFunction1D)
	I_DeclaringFile("osg/TransferFunction");
	I_BaseType(osg::TransferFunction);
	I_Constructor0(____TransferFunction1D,
	               "",
	               "");
	I_ConstructorWithDefaults2(IN, const osg::TransferFunction1D &, tf, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY,
	                           ____TransferFunction1D__C5_TransferFunction1D_R1__C5_CopyOp_R1,
	                           "Copy constructor using CopyOp to manage deep vs shallow copy. ",
	                           "");
	I_Method0(osg::Object *, cloneType,
	          Properties::VIRTUAL,
	          __osg_Object_P1__cloneType,
	          "Clone the type of an object, with Object* return type. ",
	          "Must be defined by derived classes. ");
	I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop,
	          Properties::VIRTUAL,
	          __osg_Object_P1__clone__C5_osg_CopyOp_R1,
	          "Clone an object, with Object* return type. ",
	          "Must be defined by derived classes. ");
	I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj,
	          Properties::VIRTUAL,
	          __bool__isSameKindAs__C5_osg_Object_P1,
	          "",
	          "");
	I_Method0(const char *, libraryName,
	          Properties::VIRTUAL,
	          __C5_char_P1__libraryName,
	          "return the name of the object's library. ",
	          "Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. ");
	I_Method0(const char *, className,
	          Properties::VIRTUAL,
	          __C5_char_P1__className,
	          "return the name of the object's class type. ",
	          "Must be defined by derived classes. ");
	I_Method0(float, getMinimum,
	          Properties::NON_VIRTUAL,
	          __float__getMinimum,
	          "Get the mnimum transfer function value. ",
	          "");
	I_Method0(float, getMaximum,
	          Properties::NON_VIRTUAL,
	          __float__getMaximum,
	          "Get the maximum transfer function value. ",
	          "");
	I_Method1(void, allocate, IN, unsigned int, numImageCells,
	          Properties::NON_VIRTUAL,
	          __void__allocate__unsigned_int,
	          "allocate the osg::Image with specified dimension. ",
	          "The Image tracks the color map, and is used to represent the transfer function when download to the graphics card. ");
	I_MethodWithDefaults1(void, clear, IN, const osg::Vec4 &, color, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
	                      Properties::NON_VIRTUAL,
	                      __void__clear__C5_osg_Vec4_R1,
	                      "Clear the whole range to just represet a single color. ",
	                      "");
	I_Method1(osg::Vec4, getPixelValue, IN, unsigned int, i,
	          Properties::NON_VIRTUAL,
	          __osg_Vec4__getPixelValue__unsigned_int,
	          "Get pixel value from the image. ",
	          "");
	I_Method0(unsigned int, getNumberImageCells,
	          Properties::NON_VIRTUAL,
	          __unsigned_int__getNumberImageCells,
	          "Get the number of image cells that are assigned to the represent the transfer function when download to the graphics card. ",
	          "");
	I_MethodWithDefaults3(void, setColor, IN, float, v, , IN, const osg::Vec4 &, color, , IN, bool, updateImage, true,
	                      Properties::NON_VIRTUAL,
	                      __void__setColor__float__C5_osg_Vec4_R1__bool,
	                      "Set the color for a specified transfer function value. ",
	                      "updateImage defaults to true, and tells the setColor function to update the associate osg::Image that tracks the color map. Pass in false as the updateImage parameter if you are setting up many values at once to avoid recomputating og the image data, then once all setColor calls are made explictly call updateImage() to bring the osg::Image back into sync with the color map. ");
	I_Method1(osg::Vec4, getColor, IN, float, v,
	          Properties::NON_VIRTUAL,
	          __osg_Vec4__getColor__float,
	          "Get the color for a specified transfer function value, interpolating the value if no exact match is found. ",
	          "");
	I_Method0(osg::TransferFunction1D::ColorMap &, getColorMap,
	          Properties::NON_VIRTUAL,
	          __ColorMap_R1__getColorMap,
	          "Get the color map that stores the mapping between the the tranfser function value and the colour it maps to. ",
	          "");
	I_Method0(const osg::TransferFunction1D::ColorMap &, getColorMap,
	          Properties::NON_VIRTUAL,
	          __C5_ColorMap_R1__getColorMap,
	          "Get the const color map that stores the mapping between the the tranfser function value and the colour it maps to. ",
	          "");
	I_Method1(void, assign, IN, const osg::TransferFunction1D::ColorMap &, vcm,
	          Properties::NON_VIRTUAL,
	          __void__assign__C5_ColorMap_R1,
	          "Assign a color map and automatically update the image to make sure they are in sync. ",
	          "");
	I_Method0(void, updateImage,
	          Properties::NON_VIRTUAL,
	          __void__updateImage,
	          "Manually update the associate osg::Image to represent the colors assigned in the color map. ",
	          "");
	I_ProtectedMethod4(void, assignToImage, IN, float, lower_v, IN, const osg::Vec4 &, lower_c, IN, float, upper_v, IN, const osg::Vec4 &, upper_c,
	                   Properties::NON_VIRTUAL,
	                   Properties::NON_CONST,
	                   __void__assignToImage__float__C5_osg_Vec4_R1__float__C5_osg_Vec4_R1,
	                   "",
	                   "");
	I_SimpleProperty(osg::TransferFunction1D::ColorMap &, ColorMap,
	                 __ColorMap_R1__getColorMap,
	                 0);
	I_SimpleProperty(float, Maximum,
	                 __float__getMaximum,
	                 0);
	I_SimpleProperty(float, Minimum,
	                 __float__getMinimum,
	                 0);
	I_SimpleProperty(unsigned int, NumberImageCells,
	                 __unsigned_int__getNumberImageCells,
	                 0);
END_REFLECTOR

STD_MAP_REFLECTOR(std::map< float COMMA  osg::Vec4 >)

<commit_msg>Updated wrappers<commit_after>// ***************************************************************************
//
//   Generated automatically by genwrapper.
//   Please DO NOT EDIT this file!
//
// ***************************************************************************

#include <osgIntrospection/ReflectionMacros>
#include <osgIntrospection/TypedMethodInfo>
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>

#include <osg/CopyOp>
#include <osg/Image>
#include <osg/Object>
#include <osg/TransferFunction>
#include <osg/Vec4>

// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
#undef IN
#endif
#ifdef OUT
#undef OUT
#endif

BEGIN_OBJECT_REFLECTOR(osg::TransferFunction)
	I_DeclaringFile("osg/TransferFunction");
	I_BaseType(osg::Object);
	I_Constructor0(____TransferFunction,
	               "",
	               "");
	I_ConstructorWithDefaults2(IN, const osg::TransferFunction &, tf, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY,
	                           ____TransferFunction__C5_TransferFunction_R1__C5_CopyOp_R1,
	                           "Copy constructor using CopyOp to manage deep vs shallow copy. ",
	                           "");
	I_Method0(osg::Object *, cloneType,
	          Properties::VIRTUAL,
	          __osg_Object_P1__cloneType,
	          "Clone the type of an object, with Object* return type. ",
	          "Must be defined by derived classes. ");
	I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop,
	          Properties::VIRTUAL,
	          __osg_Object_P1__clone__C5_osg_CopyOp_R1,
	          "Clone an object, with Object* return type. ",
	          "Must be defined by derived classes. ");
	I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj,
	          Properties::VIRTUAL,
	          __bool__isSameKindAs__C5_osg_Object_P1,
	          "",
	          "");
	I_Method0(const char *, libraryName,
	          Properties::VIRTUAL,
	          __C5_char_P1__libraryName,
	          "return the name of the object's library. ",
	          "Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. ");
	I_Method0(const char *, className,
	          Properties::VIRTUAL,
	          __C5_char_P1__className,
	          "return the name of the object's class type. ",
	          "Must be defined by derived classes. ");
	I_Method0(osg::Image *, getImage,
	          Properties::NON_VIRTUAL,
	          __osg_Image_P1__getImage,
	          "Get the image that is used for passing the transfer function data to the GPU. ",
	          "");
	I_Method0(const osg::Image *, getImage,
	          Properties::NON_VIRTUAL,
	          __C5_osg_Image_P1__getImage,
	          "Get the const image that is used for passing the transfer function data to the GPU. ",
	          "");
	I_SimpleProperty(osg::Image *, Image,
	                 __osg_Image_P1__getImage,
	                 0);
END_REFLECTOR

TYPE_NAME_ALIAS(std::map< float COMMA  osg::Vec4 >, osg::TransferFunction1D::ColorMap)

BEGIN_OBJECT_REFLECTOR(osg::TransferFunction1D)
	I_DeclaringFile("osg/TransferFunction");
	I_BaseType(osg::TransferFunction);
	I_Constructor0(____TransferFunction1D,
	               "",
	               "");
	I_ConstructorWithDefaults2(IN, const osg::TransferFunction1D &, tf, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY,
	                           ____TransferFunction1D__C5_TransferFunction1D_R1__C5_CopyOp_R1,
	                           "Copy constructor using CopyOp to manage deep vs shallow copy. ",
	                           "");
	I_Method0(osg::Object *, cloneType,
	          Properties::VIRTUAL,
	          __osg_Object_P1__cloneType,
	          "Clone the type of an object, with Object* return type. ",
	          "Must be defined by derived classes. ");
	I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop,
	          Properties::VIRTUAL,
	          __osg_Object_P1__clone__C5_osg_CopyOp_R1,
	          "Clone an object, with Object* return type. ",
	          "Must be defined by derived classes. ");
	I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj,
	          Properties::VIRTUAL,
	          __bool__isSameKindAs__C5_osg_Object_P1,
	          "",
	          "");
	I_Method0(const char *, libraryName,
	          Properties::VIRTUAL,
	          __C5_char_P1__libraryName,
	          "return the name of the object's library. ",
	          "Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. ");
	I_Method0(const char *, className,
	          Properties::VIRTUAL,
	          __C5_char_P1__className,
	          "return the name of the object's class type. ",
	          "Must be defined by derived classes. ");
	I_Method0(float, getMinimum,
	          Properties::NON_VIRTUAL,
	          __float__getMinimum,
	          "Get the mnimum transfer function value. ",
	          "");
	I_Method0(float, getMaximum,
	          Properties::NON_VIRTUAL,
	          __float__getMaximum,
	          "Get the maximum transfer function value. ",
	          "");
	I_Method1(void, allocate, IN, unsigned int, numImageCells,
	          Properties::NON_VIRTUAL,
	          __void__allocate__unsigned_int,
	          "allocate the osg::Image with specified dimension. ",
	          "The Image tracks the color map, and is used to represent the transfer function when download to GPU. ");
	I_MethodWithDefaults1(void, clear, IN, const osg::Vec4 &, color, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
	                      Properties::NON_VIRTUAL,
	                      __void__clear__C5_osg_Vec4_R1,
	                      "Clear the whole range to just represet a single color. ",
	                      "");
	I_Method1(osg::Vec4, getPixelValue, IN, unsigned int, i,
	          Properties::NON_VIRTUAL,
	          __osg_Vec4__getPixelValue__unsigned_int,
	          "Get pixel value from the image. ",
	          "");
	I_Method0(unsigned int, getNumberImageCells,
	          Properties::NON_VIRTUAL,
	          __unsigned_int__getNumberImageCells,
	          "Get the number of image cells that are assigned to the represent the transfer function when download to the GPU. ",
	          "");
	I_MethodWithDefaults3(void, setColor, IN, float, v, , IN, const osg::Vec4 &, color, , IN, bool, updateImage, true,
	                      Properties::NON_VIRTUAL,
	                      __void__setColor__float__C5_osg_Vec4_R1__bool,
	                      "Set the color for a specified transfer function value. ",
	                      "updateImage defaults to true, and tells the setColor function to update the associate osg::Image that tracks the color map. Pass in false as the updateImage parameter if you are setting up many values at once to avoid recomputating og the image data, then once all setColor calls are made explictly call updateImage() to bring the osg::Image back into sync with the color map. ");
	I_Method1(osg::Vec4, getColor, IN, float, v,
	          Properties::NON_VIRTUAL,
	          __osg_Vec4__getColor__float,
	          "Get the color for a specified transfer function value, interpolating the value if no exact match is found. ",
	          "");
	I_Method0(osg::TransferFunction1D::ColorMap &, getColorMap,
	          Properties::NON_VIRTUAL,
	          __ColorMap_R1__getColorMap,
	          "Get the color map that stores the mapping between the the tranfser function value and the colour it maps to. ",
	          "");
	I_Method0(const osg::TransferFunction1D::ColorMap &, getColorMap,
	          Properties::NON_VIRTUAL,
	          __C5_ColorMap_R1__getColorMap,
	          "Get the const color map that stores the mapping between the the tranfser function value and the colour it maps to. ",
	          "");
	I_Method1(void, assign, IN, const osg::TransferFunction1D::ColorMap &, vcm,
	          Properties::NON_VIRTUAL,
	          __void__assign__C5_ColorMap_R1,
	          "Assign a color map and automatically update the image to make sure they are in sync. ",
	          "");
	I_Method0(void, updateImage,
	          Properties::NON_VIRTUAL,
	          __void__updateImage,
	          "Manually update the associate osg::Image to represent the colors assigned in the color map. ",
	          "");
	I_ProtectedMethod4(void, assignToImage, IN, float, lower_v, IN, const osg::Vec4 &, lower_c, IN, float, upper_v, IN, const osg::Vec4 &, upper_c,
	                   Properties::NON_VIRTUAL,
	                   Properties::NON_CONST,
	                   __void__assignToImage__float__C5_osg_Vec4_R1__float__C5_osg_Vec4_R1,
	                   "",
	                   "");
	I_SimpleProperty(osg::TransferFunction1D::ColorMap &, ColorMap,
	                 __ColorMap_R1__getColorMap,
	                 0);
	I_SimpleProperty(float, Maximum,
	                 __float__getMaximum,
	                 0);
	I_SimpleProperty(float, Minimum,
	                 __float__getMinimum,
	                 0);
	I_SimpleProperty(unsigned int, NumberImageCells,
	                 __unsigned_int__getNumberImageCells,
	                 0);
END_REFLECTOR

STD_MAP_REFLECTOR(std::map< float COMMA  osg::Vec4 >)

<|endoftext|>