<commit_before>/*********************************************************************
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2013, Unbounded Robotics Inc.
 *  Copyright (c) 2012, Willow Garage, Inc.
 *  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 Willow Garage 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.
 *********************************************************************/

/* Author: Michael Ferguson, Ioan Sucan, E. Gil Jones */

#include <moveit_simple_controller_manager/follow_joint_trajectory_controller_handle.h>
#include <moveit/utils/xmlrpc_casts.h>

using namespace moveit::core;
static const std::string LOGNAME("SimpleControllerManager");

namespace moveit_simple_controller_manager
{
bool FollowJointTrajectoryControllerHandle::sendTrajectory(const moveit_msgs::RobotTrajectory& trajectory)
{
  ROS_DEBUG_STREAM_NAMED(LOGNAME, "new trajectory to " << name_);

  if (!controller_action_client_)
    return false;

  if (!trajectory.multi_dof_joint_trajectory.points.empty())
  {
    ROS_WARN_NAMED(LOGNAME, "%s cannot execute multi-dof trajectories.", name_.c_str());
  }

  if (done_)
    ROS_DEBUG_STREAM_NAMED(LOGNAME, "sending trajectory to " << name_);
  else
    ROS_DEBUG_STREAM_NAMED(LOGNAME, "sending continuation for the currently executed trajectory to " << name_);

  control_msgs::FollowJointTrajectoryGoal goal = goal_template_;
  goal.trajectory = trajectory.joint_trajectory;
  controller_action_client_->sendGoal(
      goal, boost::bind(&FollowJointTrajectoryControllerHandle::controllerDoneCallback, this, _1, _2),
      boost::bind(&FollowJointTrajectoryControllerHandle::controllerActiveCallback, this),
      boost::bind(&FollowJointTrajectoryControllerHandle::controllerFeedbackCallback, this, _1));
  done_ = false;
  last_exec_ = moveit_controller_manager::ExecutionStatus::RUNNING;
  return true;
}

void FollowJointTrajectoryControllerHandle::configure(XmlRpc::XmlRpcValue& config)
{
  if (config.hasMember("path_tolerance"))
    configure(config["path_tolerance"], "path_tolerance", goal_template_.path_tolerance);
  if (config.hasMember("goal_tolerance"))
    configure(config["goal_tolerance"], "goal_tolerance", goal_template_.goal_tolerance);
  if (config.hasMember("goal_time_tolerance"))
    goal_template_.goal_time_tolerance = ros::Duration(parseDouble(config["goal_time_tolerance"]));
}

namespace
{
enum ToleranceVariables
{
  POSITION,
  VELOCITY,
  ACCELERATION
};
template <ToleranceVariables>
double& variable(control_msgs::JointTolerance& msg);

template <>
inline double& variable<POSITION>(control_msgs::JointTolerance& msg)
{
  return msg.position;
}
template <>
inline double& variable<VELOCITY>(control_msgs::JointTolerance& msg)
{
  return msg.velocity;
}
template <>
inline double& variable<ACCELERATION>(control_msgs::JointTolerance& msg)
{
  return msg.acceleration;
}

static std::map<ToleranceVariables, std::string> VAR_NAME = { { POSITION, "position" },
                                                              { VELOCITY, "velocity" },
                                                              { ACCELERATION, "acceleration" } };
static std::map<ToleranceVariables, decltype(&variable<POSITION>)> VAR_ACCESS = { { POSITION, &variable<POSITION> },
                                                                                { VELOCITY, &variable<VELOCITY> },
                                                                                { ACCELERATION,
                                                                                &variable<ACCELERATION> } };

const char* errorCodeToMessage(int error_code)
{
  switch (error_code)
  {
    case control_msgs::FollowJointTrajectoryResult::SUCCESSFUL:
      return "SUCCESSFUL";
    case control_msgs::FollowJointTrajectoryResult::INVALID_GOAL:
      return "INVALID_GOAL";
    case control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS:
      return "INVALID_JOINTS";
    case control_msgs::FollowJointTrajectoryResult::OLD_HEADER_TIMESTAMP:
      return "OLD_HEADER_TIMESTAMP";
    case control_msgs::FollowJointTrajectoryResult::PATH_TOLERANCE_VIOLATED:
      return "PATH_TOLERANCE_VIOLATED";
    case control_msgs::FollowJointTrajectoryResult::GOAL_TOLERANCE_VIOLATED:
      return "GOAL_TOLERANCE_VIOLATED";
    default:
      return "unknown error";
  }
}
}

void FollowJointTrajectoryControllerHandle::configure(XmlRpc::XmlRpcValue& config, const std::string& config_name,
                                                      std::vector<control_msgs::JointTolerance>& tolerances)
{
  if (isStruct(config))  // config should be either a struct of position, velocity, acceleration
  {
    for (ToleranceVariables var : { POSITION, VELOCITY, ACCELERATION })
    {
      if (!config.hasMember(VAR_NAME[var]))
        continue;
      XmlRpc::XmlRpcValue values = config[VAR_NAME[var]];
      if (isArray(values, joints_.size()))
      {
        size_t i = 0;
        for (const auto& joint_name : joints_)
          VAR_ACCESS[var](getTolerance(tolerances, joint_name)) = parseDouble(values[i++]);
      }
      else
      {  // use common value for all joints
        double value = parseDouble(values);
        for (const auto& joint_name : joints_)
          VAR_ACCESS[var](getTolerance(tolerances, joint_name)) = value;
      }
    }
  }
  else if (isArray(config))  // or an array of JointTolerance msgs
  {
    for (size_t i = 0; i < config.size(); ++i)
    {
      control_msgs::JointTolerance& tol = getTolerance(tolerances, config[i]["name"]);
      for (ToleranceVariables var : { POSITION, VELOCITY, ACCELERATION })
      {
        if (!config[i].hasMember(VAR_NAME[var]))
          continue;
        VAR_ACCESS[var](tol) = parseDouble(config[i][VAR_NAME[var]]);
      }
    }
  }
  else
    ROS_WARN_STREAM_NAMED(LOGNAME, "Invalid " << config_name);
}

control_msgs::JointTolerance& FollowJointTrajectoryControllerHandle::getTolerance(
    std::vector<control_msgs::JointTolerance>& tolerances, const std::string& name)
{
  auto it =
      std::lower_bound(tolerances.begin(), tolerances.end(), name,
                       [](const control_msgs::JointTolerance& lhs, const std::string& rhs) { return lhs.name < rhs; });
  if (it == tolerances.cend() || it->name != name)
  {  // insert new entry if not yet available
    it = tolerances.insert(it, control_msgs::JointTolerance());
    it->name = name;
  }
  return *it;
}

void FollowJointTrajectoryControllerHandle::controllerDoneCallback(
    const actionlib::SimpleClientGoalState& state, const control_msgs::FollowJointTrajectoryResultConstPtr& result)
{
  // Output custom error message for FollowJointTrajectoryResult if necessary
  if (!result)
    ROS_WARN_STREAM_NAMED(LOGNAME, "Controller " << name_ << " done, no result returned");
  else if (result->error_code == control_msgs::FollowJointTrajectoryResult::SUCCESSFUL)
    ROS_INFO_STREAM_NAMED(LOGNAME, "Controller " << name_ << " successfully finished");
  else
    ROS_WARN_STREAM_NAMED(LOGNAME, "Controller " << name_ << "failed with error "
                                                 << errorCodeToMessage(result->error_code));
  finishControllerExecution(state);
}

void FollowJointTrajectoryControllerHandle::controllerActiveCallback()
{
  ROS_DEBUG_STREAM_NAMED(LOGNAME, name_ << " started execution");
}

void FollowJointTrajectoryControllerHandle::controllerFeedbackCallback(
    const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback)
{
}

}  // end namespace moveit_simple_controller_manager
<commit_msg>fixup! cleanup SimpleControllerManager<commit_after>/*********************************************************************
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2013, Unbounded Robotics Inc.
 *  Copyright (c) 2012, Willow Garage, Inc.
 *  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 Willow Garage 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.
 *********************************************************************/

/* Author: Michael Ferguson, Ioan Sucan, E. Gil Jones */

#include <moveit_simple_controller_manager/follow_joint_trajectory_controller_handle.h>
#include <moveit/utils/xmlrpc_casts.h>

using namespace moveit::core;
static const std::string LOGNAME("SimpleControllerManager");

namespace moveit_simple_controller_manager
{
bool FollowJointTrajectoryControllerHandle::sendTrajectory(const moveit_msgs::RobotTrajectory& trajectory)
{
  ROS_DEBUG_STREAM_NAMED(LOGNAME, "new trajectory to " << name_);

  if (!controller_action_client_)
    return false;

  if (!trajectory.multi_dof_joint_trajectory.points.empty())
  {
    ROS_WARN_NAMED(LOGNAME, "%s cannot execute multi-dof trajectories.", name_.c_str());
  }

  if (done_)
    ROS_DEBUG_STREAM_NAMED(LOGNAME, "sending trajectory to " << name_);
  else
    ROS_DEBUG_STREAM_NAMED(LOGNAME, "sending continuation for the currently executed trajectory to " << name_);

  control_msgs::FollowJointTrajectoryGoal goal = goal_template_;
  goal.trajectory = trajectory.joint_trajectory;
  controller_action_client_->sendGoal(
      goal, boost::bind(&FollowJointTrajectoryControllerHandle::controllerDoneCallback, this, _1, _2),
      boost::bind(&FollowJointTrajectoryControllerHandle::controllerActiveCallback, this),
      boost::bind(&FollowJointTrajectoryControllerHandle::controllerFeedbackCallback, this, _1));
  done_ = false;
  last_exec_ = moveit_controller_manager::ExecutionStatus::RUNNING;
  return true;
}

void FollowJointTrajectoryControllerHandle::configure(XmlRpc::XmlRpcValue& config)
{
  if (config.hasMember("path_tolerance"))
    configure(config["path_tolerance"], "path_tolerance", goal_template_.path_tolerance);
  if (config.hasMember("goal_tolerance"))
    configure(config["goal_tolerance"], "goal_tolerance", goal_template_.goal_tolerance);
  if (config.hasMember("goal_time_tolerance"))
    goal_template_.goal_time_tolerance = ros::Duration(parseDouble(config["goal_time_tolerance"]));
}

namespace
{
enum ToleranceVariables
{
  POSITION,
  VELOCITY,
  ACCELERATION
};
template <ToleranceVariables>
double& variable(control_msgs::JointTolerance& msg);

template <>
inline double& variable<POSITION>(control_msgs::JointTolerance& msg)
{
  return msg.position;
}
template <>
inline double& variable<VELOCITY>(control_msgs::JointTolerance& msg)
{
  return msg.velocity;
}
template <>
inline double& variable<ACCELERATION>(control_msgs::JointTolerance& msg)
{
  return msg.acceleration;
}

static std::map<ToleranceVariables, std::string> VAR_NAME = { { POSITION, "position" },
                                                              { VELOCITY, "velocity" },
                                                              { ACCELERATION, "acceleration" } };
static std::map<ToleranceVariables, decltype(&variable<POSITION>)> VAR_ACCESS = { { POSITION, &variable<POSITION> },
                                                                                { VELOCITY, &variable<VELOCITY> },
                                                                                { ACCELERATION,
                                                                                &variable<ACCELERATION> } };

const char* errorCodeToMessage(int error_code)
{
  switch (error_code)
  {
    case control_msgs::FollowJointTrajectoryResult::SUCCESSFUL:
      return "SUCCESSFUL";
    case control_msgs::FollowJointTrajectoryResult::INVALID_GOAL:
      return "INVALID_GOAL";
    case control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS:
      return "INVALID_JOINTS";
    case control_msgs::FollowJointTrajectoryResult::OLD_HEADER_TIMESTAMP:
      return "OLD_HEADER_TIMESTAMP";
    case control_msgs::FollowJointTrajectoryResult::PATH_TOLERANCE_VIOLATED:
      return "PATH_TOLERANCE_VIOLATED";
    case control_msgs::FollowJointTrajectoryResult::GOAL_TOLERANCE_VIOLATED:
      return "GOAL_TOLERANCE_VIOLATED";
    default:
      return "unknown error";
  }
}
}

void FollowJointTrajectoryControllerHandle::configure(XmlRpc::XmlRpcValue& config, const std::string& config_name,
                                                      std::vector<control_msgs::JointTolerance>& tolerances)
{
  if (isStruct(config))  // config should be either a struct of position, velocity, acceleration
  {
    for (ToleranceVariables var : { POSITION, VELOCITY, ACCELERATION })
    {
      if (!config.hasMember(VAR_NAME[var]))
        continue;
      XmlRpc::XmlRpcValue values = config[VAR_NAME[var]];
      if (isArray(values, joints_.size()))
      {
        size_t i = 0;
        for (const auto& joint_name : joints_)
          VAR_ACCESS[var](getTolerance(tolerances, joint_name)) = parseDouble(values[i++]);
      }
      else
      {  // use common value for all joints
        double value = parseDouble(values);
        for (const auto& joint_name : joints_)
          VAR_ACCESS[var](getTolerance(tolerances, joint_name)) = value;
      }
    }
  }
  else if (isArray(config))  // or an array of JointTolerance msgs
  {
    for (size_t i = 0; i < config.size(); ++i)
    {
      control_msgs::JointTolerance& tol = getTolerance(tolerances, config[i]["name"]);
      for (ToleranceVariables var : { POSITION, VELOCITY, ACCELERATION })
      {
        if (!config[i].hasMember(VAR_NAME[var]))
          continue;
        VAR_ACCESS[var](tol) = parseDouble(config[i][VAR_NAME[var]]);
      }
    }
  }
  else
    ROS_WARN_STREAM_NAMED(LOGNAME, "Invalid " << config_name);
}

control_msgs::JointTolerance& FollowJointTrajectoryControllerHandle::getTolerance(
    std::vector<control_msgs::JointTolerance>& tolerances, const std::string& name)
{
  auto it =
      std::lower_bound(tolerances.begin(), tolerances.end(), name,
                       [](const control_msgs::JointTolerance& lhs, const std::string& rhs) { return lhs.name < rhs; });
  if (it == tolerances.cend() || it->name != name)
  {  // insert new entry if not yet available
    it = tolerances.insert(it, control_msgs::JointTolerance());
    it->name = name;
  }
  return *it;
}

void FollowJointTrajectoryControllerHandle::controllerDoneCallback(
    const actionlib::SimpleClientGoalState& state, const control_msgs::FollowJointTrajectoryResultConstPtr& result)
{
  // Output custom error message for FollowJointTrajectoryResult if necessary
  if (!result)
    ROS_WARN_STREAM_NAMED(LOGNAME, "Controller " << name_ << " done, no result returned");
  else if (result->error_code == control_msgs::FollowJointTrajectoryResult::SUCCESSFUL)
    ROS_INFO_STREAM_NAMED(LOGNAME, "Controller " << name_ << " successfully finished");
  else
    ROS_WARN_STREAM_NAMED(LOGNAME, "Controller " << name_ << "failed with error "
                                                 << errorCodeToMessage(result->error_code) << ": "
                                                 << result->error_string);
  finishControllerExecution(state);
}

void FollowJointTrajectoryControllerHandle::controllerActiveCallback()
{
  ROS_DEBUG_STREAM_NAMED(LOGNAME, name_ << " started execution");
}

void FollowJointTrajectoryControllerHandle::controllerFeedbackCallback(
    const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback)
{
}

}  // end namespace moveit_simple_controller_manager
<|endoftext|>


<commit_before>/*************************************************************\
 * TextEngine.cpp                                            *
 * This file was created by Jeremy Greenburg                 *
 * As part of The God Core game for the University of        *
 * Tennessee at Martin's University Scholars Organization    *
 *                                                           *
 * This file contains the definition of the TextEngine class *
 * For more information, see TextEngine.h                    *
\*************************************************************/

// TextEngine declaration and std::string
#include "TextEngine.h"

// std::ifstream
#include <fstream>

// Standard I/O for debugging
#include <iostream>

// OpenGL API
#include <gl\glew.h>
#include <gl\glut.h>

using namespace std;

// Initializing the constants
const char* TextEngine::TEXT_PATH = "Resources\\Scripts\\";
const char* TextEngine::SAVE_PATH = "Resources\\Save Data\\";
const float TextEngine::LINE_OFFSET = 10;

void TextEngine::displayText(float x, float y,
	float r, float g, float b,
	void* font, vector<string> text)
{
	vector<string>::iterator it;

	// Iterates throguh the text vector and prints it to the screen
	for (it = text.begin(); it != text.end(); it++)
	{
		glColor3f(r, g, b);
		glRasterPos2f(x, y);

		for (unsigned int i = 0; i < it->length(); i++)
		{
			glutBitmapCharacter(font, (*it)[i]);
		}

		// Because glut does not print newlines
		y += LINE_OFFSET;
	}
}

vector<string> TextEngine::findText(string fileName, string tag)
{
	// The tags are listed between dollar signs
	string fullTag = '$' + tag + '$';

	string fullPath = TEXT_PATH + fileName;

	ifstream infile(fullPath);

	// Buffer to read in data
	string buff;
	// Array to store strings
	vector<string> data;

	// Find the string(s) to read in
	getline(infile, buff);
	while (infile && buff != fullTag)
	{
		getline(infile, buff);
	}

	// Store the string(s)
	getline(infile, buff);
	while (infile && buff != "$END$")
	{
		data.push_back(buff);
		getline(infile, buff);
	}

	infile.close();

	return data;
}

void TextEngine::openFile(float x, float y,
	float r, float g, float b,
	string fileName, string tag)
{
	vector<string> input = findText(fileName, tag);

	displayText(x, y, r, g, b,
		GLUT_BITMAP_HELVETICA_12,
		input);
}

vector<string> TextEngine::getText(string fileName, string tag)
{
	vector<string> input = findText(fileName, tag);

	return input;
}

void TextEngine::printString(float x, float y, float r, float g, float b,
	string text)
{
	glColor3f(r, g, b);
	glRasterPos2f(x, y);

	for (unsigned int i = 0; i < text.length(); i++)
	{
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, text[i]);
	}

	// Vertical spacing
	y += LINE_OFFSET;
}<commit_msg>Removed unnecessary code<commit_after>/*************************************************************\
 * TextEngine.cpp                                            *
 * This file was created by Jeremy Greenburg                 *
 * As part of The God Core game for the University of        *
 * Tennessee at Martin's University Scholars Organization    *
 *                                                           *
 * This file contains the definition of the TextEngine class *
 * For more information, see TextEngine.h                    *
\*************************************************************/

// TextEngine declaration and std::string
#include "TextEngine.h"

// std::ifstream
#include <fstream>

// Standard I/O for debugging
#include <iostream>

// OpenGL API
#include <gl\glew.h>
#include <gl\glut.h>

using namespace std;

// Initializing the constants
const char* TextEngine::TEXT_PATH = "Resources\\Scripts\\";
const float TextEngine::LINE_OFFSET = 10;

void TextEngine::displayText(float x, float y,
	float r, float g, float b,
	void* font, vector<string> text)
{
	vector<string>::iterator it;

	// Iterates throguh the text vector and prints it to the screen
	for (it = text.begin(); it != text.end(); it++)
	{
		glColor3f(r, g, b);
		glRasterPos2f(x, y);

		for (unsigned int i = 0; i < it->length(); i++)
		{
			glutBitmapCharacter(font, (*it)[i]);
		}

		// Because glut does not print newlines
		y += LINE_OFFSET;
	}
}

vector<string> TextEngine::findText(string fileName, string tag)
{
	// The tags are listed between dollar signs
	string fullTag = '$' + tag + '$';

	string fullPath = TEXT_PATH + fileName;

	ifstream infile(fullPath);

	// Buffer to read in data
	string buff;
	// Array to store strings
	vector<string> data;

	// Find the string(s) to read in
	getline(infile, buff);
	while (infile && buff != fullTag)
	{
		getline(infile, buff);
	}

	// Store the string(s)
	getline(infile, buff);
	while (infile && buff != "$END$")
	{
		data.push_back(buff);
		getline(infile, buff);
	}

	infile.close();

	return data;
}

void TextEngine::openFile(float x, float y,
	float r, float g, float b,
	string fileName, string tag)
{
	vector<string> input = findText(fileName, tag);

	displayText(x, y, r, g, b,
		GLUT_BITMAP_HELVETICA_12,
		input);
}

vector<string> TextEngine::getText(string fileName, string tag)
{
	vector<string> input = findText(fileName, tag);

	return input;
}

void TextEngine::printString(float x, float y, float r, float g, float b,
	string text)
{
	glColor3f(r, g, b);
	glRasterPos2f(x, y);

	for (unsigned int i = 0; i < text.length(); i++)
	{
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, text[i]);
	}

	// Vertical spacing
	y += LINE_OFFSET;
}
<|endoftext|>


<commit_before>/*************************************************************************
> File Name: main.cpp
> Project Name: Hearthstone++
> Author: Chan-Ho Chris Ohk
> Purpose: Main entry of Hearthstone++ tool.
> Created Time: 2018/08/18
> Copyright (c) 2018, Chan-Ho Chris Ohk
*************************************************************************/
int main()
{
    return 0;
}<commit_msg>[ci skip] Implement basic structure<commit_after>/*************************************************************************
> File Name: main.cpp
> Project Name: Hearthstone++
> Author: Chan-Ho Chris Ohk
> Purpose: Main entry of Hearthstone++ tool.
> Created Time: 2018/08/18
> Copyright (c) 2018, Chan-Ho Chris Ohk
*************************************************************************/
#include <clara.hpp>

#include <fstream>
#include <iostream>
#include <string>

inline std::string ToString(const clara::Opt& opt)
{
    std::ostringstream oss;
    oss << (clara::Parser() | opt);
    return oss.str();
}

inline std::string ToString(const clara::Parser& p)
{
    std::ostringstream oss;
    oss << p;
    return oss.str();
}

inline void ExportFile(const std::string& fileName)
{
    std::ofstream outputFile(fileName + ".md");
    if (outputFile)
    {
        // TODO: export card data
    }
    else
    {
        fprintf(stderr, "Failed to write file %s\n", fileName.c_str());
        exit(EXIT_FAILURE);
    }
}

int main(int argc, char* argv[])
{
    // Parse command
    bool showHelp = false;
    std::string expansionNameA, expansionNameU, expansionNameI;

    // Parsing
    auto parser =
        clara::Help(showHelp) |
        clara::Opt(expansionNameA, "expansionName")["-a"]["--all"](
            "Export all card list to markdown format by grouping the "
            "expansion") |
        clara::Opt(expansionNameU, "expansionName")["-u"]["--unique"](
            "Export unique card list to markdown format by grouping the "
            "expansion") |
        clara::Opt(expansionNameI, "expansionName")["-i"]["--implemented"](
            "Export implemented card list to markdown format by "
            "grouping "
            "the expansion");

    auto result = parser.parse(clara::Args(argc, argv));
    if (!result)
    {
        std::cerr << "Error in command line: " << result.errorMessage() << '\n';
        exit(EXIT_FAILURE);
    }

    if (showHelp)
    {
        std::cout << ToString(parser) << '\n';
        exit(EXIT_SUCCESS);
    }

    if (!expansionNameA.empty())
    {
    }

    if (!expansionNameU.empty())
    {
    }

    if (!expansionNameI.empty())
    {
    }

    exit(EXIT_SUCCESS);
}<|endoftext|>


<commit_before>#include <babylon/materials/node/blocks/worley_noise3d_block.h>

#include <babylon/core/json_util.h>
#include <babylon/materials/node/node_material_build_state.h>
#include <babylon/materials/node/node_material_connection_point.h>
#include <babylon/misc/string_tools.h>

namespace BABYLON {

WorleyNoise3DBlock::WorleyNoise3DBlock(const std::string& iName)
    : NodeMaterialBlock{iName, NodeMaterialBlockTargets::Neutral}
    , manhattanDistance{false}
    , seed{this, &WorleyNoise3DBlock::get_seed}
    , jitter{this, &WorleyNoise3DBlock::get_jitter}
    , output{this, &WorleyNoise3DBlock::get_output}
{
  registerInput("seed", NodeMaterialBlockConnectionPointTypes::Vector3);
  registerInput("jitter", NodeMaterialBlockConnectionPointTypes::Float);

  registerOutput("output", NodeMaterialBlockConnectionPointTypes::Vector2);
}

WorleyNoise3DBlock::~WorleyNoise3DBlock() = default;

std::string WorleyNoise3DBlock::getClassName() const
{
  return "WorleyNoise3DBlock";
}

NodeMaterialConnectionPointPtr& WorleyNoise3DBlock::get_seed()
{
  return _inputs[0];
}

NodeMaterialConnectionPointPtr& WorleyNoise3DBlock::get_jitter()
{
  return _inputs[1];
}

NodeMaterialConnectionPointPtr& WorleyNoise3DBlock::get_output()
{
  return _outputs[0];
}

WorleyNoise3DBlock& WorleyNoise3DBlock::_buildBlock(NodeMaterialBuildState& state)
{
  NodeMaterialBlock::_buildBlock(state);

  if (!seed()->isConnected()) {
    return *this;
  }

  if (!_outputs[0]->hasEndpoints()) {
    return *this;
  }

  const char* functionString = R"ShaderCode(

           vec3 permute(vec3 x){
               return mod((34.0 * x + 1.0) * x, 289.0);
           }

           vec3 dist(vec3 x, vec3 y, vec3 z,  bool manhattanDistance){
               return manhattanDistance ?  abs(x) + abs(y) + abs(z) :  (x * x + y * y + z * z);
           }

           vec2 worley(vec3 P, float jitter, bool manhattanDistance){
               float K = 0.142857142857; // 1/7
               float Ko = 0.428571428571; // 1/2-K/2
               float  K2 = 0.020408163265306; // 1/(7*7)
               float Kz = 0.166666666667; // 1/6
               float Kzo = 0.416666666667; // 1/2-1/6*2

               vec3 Pi = mod(floor(P), 289.0);
               vec3 Pf = fract(P) - 0.5;

               vec3 Pfx = Pf.x + vec3(1.0, 0.0, -1.0);
               vec3 Pfy = Pf.y + vec3(1.0, 0.0, -1.0);
               vec3 Pfz = Pf.z + vec3(1.0, 0.0, -1.0);

               vec3 p = permute(Pi.x + vec3(-1.0, 0.0, 1.0));
               vec3 p1 = permute(p + Pi.y - 1.0);
               vec3 p2 = permute(p + Pi.y);
               vec3 p3 = permute(p + Pi.y + 1.0);

               vec3 p11 = permute(p1 + Pi.z - 1.0);
               vec3 p12 = permute(p1 + Pi.z);
               vec3 p13 = permute(p1 + Pi.z + 1.0);

               vec3 p21 = permute(p2 + Pi.z - 1.0);
               vec3 p22 = permute(p2 + Pi.z);
               vec3 p23 = permute(p2 + Pi.z + 1.0);

               vec3 p31 = permute(p3 + Pi.z - 1.0);
               vec3 p32 = permute(p3 + Pi.z);
               vec3 p33 = permute(p3 + Pi.z + 1.0);

               vec3 ox11 = fract(p11*K) - Ko;
               vec3 oy11 = mod(floor(p11*K), 7.0)*K - Ko;
               vec3 oz11 = floor(p11*K2)*Kz - Kzo; // p11 < 289 guaranteed

               vec3 ox12 = fract(p12*K) - Ko;
               vec3 oy12 = mod(floor(p12*K), 7.0)*K - Ko;
               vec3 oz12 = floor(p12*K2)*Kz - Kzo;

               vec3 ox13 = fract(p13*K) - Ko;
               vec3 oy13 = mod(floor(p13*K), 7.0)*K - Ko;
               vec3 oz13 = floor(p13*K2)*Kz - Kzo;

               vec3 ox21 = fract(p21*K) - Ko;
               vec3 oy21 = mod(floor(p21*K), 7.0)*K - Ko;
               vec3 oz21 = floor(p21*K2)*Kz - Kzo;

               vec3 ox22 = fract(p22*K) - Ko;
               vec3 oy22 = mod(floor(p22*K), 7.0)*K - Ko;
               vec3 oz22 = floor(p22*K2)*Kz - Kzo;

               vec3 ox23 = fract(p23*K) - Ko;
               vec3 oy23 = mod(floor(p23*K), 7.0)*K - Ko;
               vec3 oz23 = floor(p23*K2)*Kz - Kzo;

               vec3 ox31 = fract(p31*K) - Ko;
               vec3 oy31 = mod(floor(p31*K), 7.0)*K - Ko;
               vec3 oz31 = floor(p31*K2)*Kz - Kzo;

               vec3 ox32 = fract(p32*K) - Ko;
               vec3 oy32 = mod(floor(p32*K), 7.0)*K - Ko;
               vec3 oz32 = floor(p32*K2)*Kz - Kzo;

               vec3 ox33 = fract(p33*K) - Ko;
               vec3 oy33 = mod(floor(p33*K), 7.0)*K - Ko;
               vec3 oz33 = floor(p33*K2)*Kz - Kzo;

               vec3 dx11 = Pfx + jitter*ox11;
               vec3 dy11 = Pfy.x + jitter*oy11;
               vec3 dz11 = Pfz.x + jitter*oz11;

               vec3 dx12 = Pfx + jitter*ox12;
               vec3 dy12 = Pfy.x + jitter*oy12;
               vec3 dz12 = Pfz.y + jitter*oz12;

               vec3 dx13 = Pfx + jitter*ox13;
               vec3 dy13 = Pfy.x + jitter*oy13;
               vec3 dz13 = Pfz.z + jitter*oz13;

               vec3 dx21 = Pfx + jitter*ox21;
               vec3 dy21 = Pfy.y + jitter*oy21;
               vec3 dz21 = Pfz.x + jitter*oz21;

               vec3 dx22 = Pfx + jitter*ox22;
               vec3 dy22 = Pfy.y + jitter*oy22;
               vec3 dz22 = Pfz.y + jitter*oz22;

               vec3 dx23 = Pfx + jitter*ox23;
               vec3 dy23 = Pfy.y + jitter*oy23;
               vec3 dz23 = Pfz.z + jitter*oz23;

               vec3 dx31 = Pfx + jitter*ox31;
               vec3 dy31 = Pfy.z + jitter*oy31;
               vec3 dz31 = Pfz.x + jitter*oz31;

               vec3 dx32 = Pfx + jitter*ox32;
               vec3 dy32 = Pfy.z + jitter*oy32;
               vec3 dz32 = Pfz.y + jitter*oz32;

               vec3 dx33 = Pfx + jitter*ox33;
               vec3 dy33 = Pfy.z + jitter*oy33;
               vec3 dz33 = Pfz.z + jitter*oz33;

               vec3 d11 = dist(dx11, dy11, dz11, manhattanDistance);
               vec3 d12 =dist(dx12, dy12, dz12, manhattanDistance);
               vec3 d13 = dist(dx13, dy13, dz13, manhattanDistance);
               vec3 d21 = dist(dx21, dy21, dz21, manhattanDistance);
               vec3 d22 = dist(dx22, dy22, dz22, manhattanDistance);
               vec3 d23 = dist(dx23, dy23, dz23, manhattanDistance);
               vec3 d31 = dist(dx31, dy31, dz31, manhattanDistance);
               vec3 d32 = dist(dx32, dy32, dz32, manhattanDistance);
               vec3 d33 = dist(dx33, dy33, dz33, manhattanDistance);

               vec3 d1a = min(d11, d12);
               d12 = max(d11, d12);
               d11 = min(d1a, d13); // Smallest now not in d12 or d13
               d13 = max(d1a, d13);
               d12 = min(d12, d13); // 2nd smallest now not in d13
               vec3 d2a = min(d21, d22);
               d22 = max(d21, d22);
               d21 = min(d2a, d23); // Smallest now not in d22 or d23
               d23 = max(d2a, d23);
               d22 = min(d22, d23); // 2nd smallest now not in d23
               vec3 d3a = min(d31, d32);
               d32 = max(d31, d32);
               d31 = min(d3a, d33); // Smallest now not in d32 or d33
               d33 = max(d3a, d33);
               d32 = min(d32, d33); // 2nd smallest now not in d33
               vec3 da = min(d11, d21);
               d21 = max(d11, d21);
               d11 = min(da, d31); // Smallest now in d11
               d31 = max(da, d31); // 2nd smallest now not in d31
               d11.xy = (d11.x < d11.y) ? d11.xy : d11.yx;
               d11.xz = (d11.x < d11.z) ? d11.xz : d11.zx; // d11.x now smallest
               d12 = min(d12, d21); // 2nd smallest now not in d21
               d12 = min(d12, d22); // nor in d22
               d12 = min(d12, d31); // nor in d31
               d12 = min(d12, d32); // nor in d32
               d11.yz = min(d11.yz,d12.xy); // nor in d12.yz
               d11.y = min(d11.y,d12.z); // Only two more to go
               d11.y = min(d11.y,d11.z); // Done! (Phew!)
               return sqrt(d11.xy); // F1, F2
           }

          )ShaderCode";

  state._emitFunction("worley3D", functionString, "// Worley3D");
  state.compilationString
    += _declareOutput(_outputs[0], state)
       + StringTools::printf(" = worley(%s, %s, %d);\r\n", seed()->associatedVariableName().c_str(),
                             jitter()->associatedVariableName().c_str(), manhattanDistance);

  return *this;
}

std::string WorleyNoise3DBlock::_dumpPropertiesCode()
{
  auto codeString = StringTools::printf("%s.manhattanDistance = %d;\r\n", _codeVariableName.c_str(),
                                        manhattanDistance);

  return codeString;
}

json WorleyNoise3DBlock::serialize() const
{
  return nullptr;
}

void WorleyNoise3DBlock::_deserialize(const json& /*serializationObject*/, Scene* /*scene*/,
                                      const std::string& /*rootUrl*/)
{
}

} // end of namespace BABYLON
<commit_msg>Updated WorleyNoise3DBlock::_dumpPropertiesCode function to use base code string from superclass<commit_after>#include <babylon/materials/node/blocks/worley_noise3d_block.h>

#include <babylon/core/json_util.h>
#include <babylon/materials/node/node_material_build_state.h>
#include <babylon/materials/node/node_material_connection_point.h>
#include <babylon/misc/string_tools.h>

namespace BABYLON {

WorleyNoise3DBlock::WorleyNoise3DBlock(const std::string& iName)
    : NodeMaterialBlock{iName, NodeMaterialBlockTargets::Neutral}
    , manhattanDistance{false}
    , seed{this, &WorleyNoise3DBlock::get_seed}
    , jitter{this, &WorleyNoise3DBlock::get_jitter}
    , output{this, &WorleyNoise3DBlock::get_output}
{
  registerInput("seed", NodeMaterialBlockConnectionPointTypes::Vector3);
  registerInput("jitter", NodeMaterialBlockConnectionPointTypes::Float);

  registerOutput("output", NodeMaterialBlockConnectionPointTypes::Vector2);
}

WorleyNoise3DBlock::~WorleyNoise3DBlock() = default;

std::string WorleyNoise3DBlock::getClassName() const
{
  return "WorleyNoise3DBlock";
}

NodeMaterialConnectionPointPtr& WorleyNoise3DBlock::get_seed()
{
  return _inputs[0];
}

NodeMaterialConnectionPointPtr& WorleyNoise3DBlock::get_jitter()
{
  return _inputs[1];
}

NodeMaterialConnectionPointPtr& WorleyNoise3DBlock::get_output()
{
  return _outputs[0];
}

WorleyNoise3DBlock& WorleyNoise3DBlock::_buildBlock(NodeMaterialBuildState& state)
{
  NodeMaterialBlock::_buildBlock(state);

  if (!seed()->isConnected()) {
    return *this;
  }

  if (!_outputs[0]->hasEndpoints()) {
    return *this;
  }

  const char* functionString = R"ShaderCode(

           vec3 permute(vec3 x){
               return mod((34.0 * x + 1.0) * x, 289.0);
           }

           vec3 dist(vec3 x, vec3 y, vec3 z,  bool manhattanDistance){
               return manhattanDistance ?  abs(x) + abs(y) + abs(z) :  (x * x + y * y + z * z);
           }

           vec2 worley(vec3 P, float jitter, bool manhattanDistance){
               float K = 0.142857142857; // 1/7
               float Ko = 0.428571428571; // 1/2-K/2
               float  K2 = 0.020408163265306; // 1/(7*7)
               float Kz = 0.166666666667; // 1/6
               float Kzo = 0.416666666667; // 1/2-1/6*2

               vec3 Pi = mod(floor(P), 289.0);
               vec3 Pf = fract(P) - 0.5;

               vec3 Pfx = Pf.x + vec3(1.0, 0.0, -1.0);
               vec3 Pfy = Pf.y + vec3(1.0, 0.0, -1.0);
               vec3 Pfz = Pf.z + vec3(1.0, 0.0, -1.0);

               vec3 p = permute(Pi.x + vec3(-1.0, 0.0, 1.0));
               vec3 p1 = permute(p + Pi.y - 1.0);
               vec3 p2 = permute(p + Pi.y);
               vec3 p3 = permute(p + Pi.y + 1.0);

               vec3 p11 = permute(p1 + Pi.z - 1.0);
               vec3 p12 = permute(p1 + Pi.z);
               vec3 p13 = permute(p1 + Pi.z + 1.0);

               vec3 p21 = permute(p2 + Pi.z - 1.0);
               vec3 p22 = permute(p2 + Pi.z);
               vec3 p23 = permute(p2 + Pi.z + 1.0);

               vec3 p31 = permute(p3 + Pi.z - 1.0);
               vec3 p32 = permute(p3 + Pi.z);
               vec3 p33 = permute(p3 + Pi.z + 1.0);

               vec3 ox11 = fract(p11*K) - Ko;
               vec3 oy11 = mod(floor(p11*K), 7.0)*K - Ko;
               vec3 oz11 = floor(p11*K2)*Kz - Kzo; // p11 < 289 guaranteed

               vec3 ox12 = fract(p12*K) - Ko;
               vec3 oy12 = mod(floor(p12*K), 7.0)*K - Ko;
               vec3 oz12 = floor(p12*K2)*Kz - Kzo;

               vec3 ox13 = fract(p13*K) - Ko;
               vec3 oy13 = mod(floor(p13*K), 7.0)*K - Ko;
               vec3 oz13 = floor(p13*K2)*Kz - Kzo;

               vec3 ox21 = fract(p21*K) - Ko;
               vec3 oy21 = mod(floor(p21*K), 7.0)*K - Ko;
               vec3 oz21 = floor(p21*K2)*Kz - Kzo;

               vec3 ox22 = fract(p22*K) - Ko;
               vec3 oy22 = mod(floor(p22*K), 7.0)*K - Ko;
               vec3 oz22 = floor(p22*K2)*Kz - Kzo;

               vec3 ox23 = fract(p23*K) - Ko;
               vec3 oy23 = mod(floor(p23*K), 7.0)*K - Ko;
               vec3 oz23 = floor(p23*K2)*Kz - Kzo;

               vec3 ox31 = fract(p31*K) - Ko;
               vec3 oy31 = mod(floor(p31*K), 7.0)*K - Ko;
               vec3 oz31 = floor(p31*K2)*Kz - Kzo;

               vec3 ox32 = fract(p32*K) - Ko;
               vec3 oy32 = mod(floor(p32*K), 7.0)*K - Ko;
               vec3 oz32 = floor(p32*K2)*Kz - Kzo;

               vec3 ox33 = fract(p33*K) - Ko;
               vec3 oy33 = mod(floor(p33*K), 7.0)*K - Ko;
               vec3 oz33 = floor(p33*K2)*Kz - Kzo;

               vec3 dx11 = Pfx + jitter*ox11;
               vec3 dy11 = Pfy.x + jitter*oy11;
               vec3 dz11 = Pfz.x + jitter*oz11;

               vec3 dx12 = Pfx + jitter*ox12;
               vec3 dy12 = Pfy.x + jitter*oy12;
               vec3 dz12 = Pfz.y + jitter*oz12;

               vec3 dx13 = Pfx + jitter*ox13;
               vec3 dy13 = Pfy.x + jitter*oy13;
               vec3 dz13 = Pfz.z + jitter*oz13;

               vec3 dx21 = Pfx + jitter*ox21;
               vec3 dy21 = Pfy.y + jitter*oy21;
               vec3 dz21 = Pfz.x + jitter*oz21;

               vec3 dx22 = Pfx + jitter*ox22;
               vec3 dy22 = Pfy.y + jitter*oy22;
               vec3 dz22 = Pfz.y + jitter*oz22;

               vec3 dx23 = Pfx + jitter*ox23;
               vec3 dy23 = Pfy.y + jitter*oy23;
               vec3 dz23 = Pfz.z + jitter*oz23;

               vec3 dx31 = Pfx + jitter*ox31;
               vec3 dy31 = Pfy.z + jitter*oy31;
               vec3 dz31 = Pfz.x + jitter*oz31;

               vec3 dx32 = Pfx + jitter*ox32;
               vec3 dy32 = Pfy.z + jitter*oy32;
               vec3 dz32 = Pfz.y + jitter*oz32;

               vec3 dx33 = Pfx + jitter*ox33;
               vec3 dy33 = Pfy.z + jitter*oy33;
               vec3 dz33 = Pfz.z + jitter*oz33;

               vec3 d11 = dist(dx11, dy11, dz11, manhattanDistance);
               vec3 d12 =dist(dx12, dy12, dz12, manhattanDistance);
               vec3 d13 = dist(dx13, dy13, dz13, manhattanDistance);
               vec3 d21 = dist(dx21, dy21, dz21, manhattanDistance);
               vec3 d22 = dist(dx22, dy22, dz22, manhattanDistance);
               vec3 d23 = dist(dx23, dy23, dz23, manhattanDistance);
               vec3 d31 = dist(dx31, dy31, dz31, manhattanDistance);
               vec3 d32 = dist(dx32, dy32, dz32, manhattanDistance);
               vec3 d33 = dist(dx33, dy33, dz33, manhattanDistance);

               vec3 d1a = min(d11, d12);
               d12 = max(d11, d12);
               d11 = min(d1a, d13); // Smallest now not in d12 or d13
               d13 = max(d1a, d13);
               d12 = min(d12, d13); // 2nd smallest now not in d13
               vec3 d2a = min(d21, d22);
               d22 = max(d21, d22);
               d21 = min(d2a, d23); // Smallest now not in d22 or d23
               d23 = max(d2a, d23);
               d22 = min(d22, d23); // 2nd smallest now not in d23
               vec3 d3a = min(d31, d32);
               d32 = max(d31, d32);
               d31 = min(d3a, d33); // Smallest now not in d32 or d33
               d33 = max(d3a, d33);
               d32 = min(d32, d33); // 2nd smallest now not in d33
               vec3 da = min(d11, d21);
               d21 = max(d11, d21);
               d11 = min(da, d31); // Smallest now in d11
               d31 = max(da, d31); // 2nd smallest now not in d31
               d11.xy = (d11.x < d11.y) ? d11.xy : d11.yx;
               d11.xz = (d11.x < d11.z) ? d11.xz : d11.zx; // d11.x now smallest
               d12 = min(d12, d21); // 2nd smallest now not in d21
               d12 = min(d12, d22); // nor in d22
               d12 = min(d12, d31); // nor in d31
               d12 = min(d12, d32); // nor in d32
               d11.yz = min(d11.yz,d12.xy); // nor in d12.yz
               d11.y = min(d11.y,d12.z); // Only two more to go
               d11.y = min(d11.y,d11.z); // Done! (Phew!)
               return sqrt(d11.xy); // F1, F2
           }

          )ShaderCode";

  state._emitFunction("worley3D", functionString, "// Worley3D");
  state.compilationString
    += _declareOutput(_outputs[0], state)
       + StringTools::printf(" = worley(%s, %s, %d);\r\n", seed()->associatedVariableName().c_str(),
                             jitter()->associatedVariableName().c_str(), manhattanDistance);

  return *this;
}

std::string WorleyNoise3DBlock::_dumpPropertiesCode()
{
  auto codeString = NodeMaterialBlock::_dumpPropertiesCode()
                    + StringTools::printf("%s.manhattanDistance = %d;\r\n",
                                          _codeVariableName.c_str(), manhattanDistance);

  return codeString;
}

json WorleyNoise3DBlock::serialize() const
{
  return nullptr;
}

void WorleyNoise3DBlock::_deserialize(const json& /*serializationObject*/, Scene* /*scene*/,
                                      const std::string& /*rootUrl*/)
{
}

} // end of namespace BABYLON
<|endoftext|>


<commit_before><commit_msg>Add stats test<commit_after><|endoftext|>


<commit_before>#ifndef STAN_MATH_FWD_FUN_QUAD_FORM_HPP
#define STAN_MATH_FWD_FUN_QUAD_FORM_HPP

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/dot_product.hpp>
#include <stan/math/fwd/fun/multiply.hpp>

namespace stan {
namespace math {

/**
 * Return the quadratic form \f$ B^T A B \f$.
 *
 * Symmetry of the resulting matrix is not guaranteed due to numerical
 * precision.
 *
 * @tparam Ta type of elements in the square matrix
 * @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
 * @tparam Ca number of columns in the square matrix, can be Eigen::Dynamic
 * @tparam Tb type of elements in the second matrix
 * @tparam Rb number of rows in the second matrix, can be Eigen::Dynamic
 * @tparam Cb number of columns in the second matrix, can be Eigen::Dynamic
 *
 * @param A square matrix
 * @param B second matrix
 * @return The quadratic form, which is a symmetric matrix of size Cb.
 * @throws std::invalid_argument if A is not square, or if A cannot be
 * multiplied by B
 */
template <typename Ta, int Ra, int Ca, typename Tb, int Rb, int Cb,
          require_any_fvar_t<Ta, Tb>...>
inline Eigen::Matrix<return_type_t<Ta, Tb>, Cb, Cb> quad_form(
    const Eigen::Matrix<Ta, Ra, Ca>& A, const Eigen::Matrix<Tb, Rb, Cb>& B) {
  check_square("quad_form", "A", A);
  check_multiplicable("quad_form", "A", A, "B", B);
  return multiply(transpose(B), multiply(A, B));
}

/**
 * Return the quadratic form \f$ B^T A B \f$.
 *
 * @tparam Ta type of elements in the square matrix
 * @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
 * @tparam Ca number of columns in the square matrix, can be Eigen::Dynamic
 * @tparam Tb type of elements in the vector
 * @tparam Rb number of rows in the vector, can be Eigen::Dynamic
 *
 * @param A square matrix
 * @param B vector
 * @return The quadratic form (a scalar).
 * @throws std::invalid_argument if A is not square, or if A cannot be
 * multiplied by B
 */
template <typename Ta, int Ra, int Ca, typename Tb, int Rb,
          require_any_fvar_t<Ta, Tb>...>
inline return_type_t<Ta, Tb> quad_form(const Eigen::Matrix<Ta, Ra, Ca>& A,
                                       const Eigen::Matrix<Tb, Rb, 1>& B) {
  check_square("quad_form", "A", A);
  check_multiplicable("quad_form", "A", A, "B", B);
  return dot_product(B, multiply(A, B));
}

}  // namespace math
}  // namespace stan

#endif
<commit_msg>fix for a header<commit_after>#ifndef STAN_MATH_FWD_FUN_QUAD_FORM_HPP
#define STAN_MATH_FWD_FUN_QUAD_FORM_HPP

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/multiply.hpp>
#include <stan/math/prim/fun/dot_product.hpp>

namespace stan {
namespace math {

/**
 * Return the quadratic form \f$ B^T A B \f$.
 *
 * Symmetry of the resulting matrix is not guaranteed due to numerical
 * precision.
 *
 * @tparam Ta type of elements in the square matrix
 * @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
 * @tparam Ca number of columns in the square matrix, can be Eigen::Dynamic
 * @tparam Tb type of elements in the second matrix
 * @tparam Rb number of rows in the second matrix, can be Eigen::Dynamic
 * @tparam Cb number of columns in the second matrix, can be Eigen::Dynamic
 *
 * @param A square matrix
 * @param B second matrix
 * @return The quadratic form, which is a symmetric matrix of size Cb.
 * @throws std::invalid_argument if A is not square, or if A cannot be
 * multiplied by B
 */
template <typename Ta, int Ra, int Ca, typename Tb, int Rb, int Cb,
          require_any_fvar_t<Ta, Tb>...>
inline Eigen::Matrix<return_type_t<Ta, Tb>, Cb, Cb> quad_form(
    const Eigen::Matrix<Ta, Ra, Ca>& A, const Eigen::Matrix<Tb, Rb, Cb>& B) {
  check_square("quad_form", "A", A);
  check_multiplicable("quad_form", "A", A, "B", B);
  return multiply(transpose(B), multiply(A, B));
}

/**
 * Return the quadratic form \f$ B^T A B \f$.
 *
 * @tparam Ta type of elements in the square matrix
 * @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
 * @tparam Ca number of columns in the square matrix, can be Eigen::Dynamic
 * @tparam Tb type of elements in the vector
 * @tparam Rb number of rows in the vector, can be Eigen::Dynamic
 *
 * @param A square matrix
 * @param B vector
 * @return The quadratic form (a scalar).
 * @throws std::invalid_argument if A is not square, or if A cannot be
 * multiplied by B
 */
template <typename Ta, int Ra, int Ca, typename Tb, int Rb,
          require_any_fvar_t<Ta, Tb>...>
inline return_type_t<Ta, Tb> quad_form(const Eigen::Matrix<Ta, Ra, Ca>& A,
                                       const Eigen::Matrix<Tb, Rb, 1>& B) {
  check_square("quad_form", "A", A);
  check_multiplicable("quad_form", "A", A, "B", B);
  return dot_product(B, multiply(A, B));
}

}  // namespace math
}  // namespace stan

#endif
<|endoftext|>


<commit_before><commit_msg>Revert "Avoid bogus warnings (GCC 4.4.6)"<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: aeitem.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 14:58:07 $
 *
 *  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_svtools.hxx"
#ifndef GCC
#endif

#include <tools/string.hxx>

#define _SVSTDARR_USHORTS
#include <svstdarr.hxx>
#include <svarray.hxx>
#include "aeitem.hxx"

// STATIC DATA -----------------------------------------------------------

DBG_NAME(SfxAllEnumItem)

TYPEINIT1_AUTOFACTORY(SfxAllEnumItem, SfxEnumItem)

// -----------------------------------------------------------------------

struct SfxAllEnumValue_Impl
{
    USHORT nValue;
    XubString aText;
};

SV_DECL_PTRARR_DEL(SfxAllEnumValueArr, SfxAllEnumValue_Impl*, 0, 8)
SV_IMPL_PTRARR(SfxAllEnumValueArr, SfxAllEnumValue_Impl*)

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem() :
    SfxEnumItem(),
    pValues( 0 ),
    pDisabledValues( 0 )
{
}

SfxAllEnumItem::SfxAllEnumItem( USHORT which, USHORT nVal, const XubString &rText ):
    SfxEnumItem(which, nVal),
    pValues( 0 ),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
    InsertValue( nVal, rText );
}

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem(USHORT which, USHORT nVal):
    SfxEnumItem(which, nVal),
    pValues( 0 ),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
    InsertValue( nVal );
}

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem( USHORT which, SvStream &rStream ):
    SfxEnumItem(which, rStream),
    pValues( 0 ),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
    InsertValue( GetValue() );
}

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem(USHORT which):
    SfxEnumItem(which, 0),
    pValues( 0 ),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
}

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem(const SfxAllEnumItem &rCopy):
    SfxEnumItem(rCopy),
    pValues(0),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
    if ( !rCopy.pValues )
        return;

    pValues = new SfxAllEnumValueArr;

    for ( USHORT nPos = 0; nPos < rCopy.pValues->Count(); ++nPos )
    {
        SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
        pVal->nValue = rCopy.pValues->GetObject(nPos)->nValue;
        pVal->aText = rCopy.pValues->GetObject(nPos)->aText;
        const SfxAllEnumValue_Impl *pTemp = pVal;
        pValues->Insert( pTemp, nPos );
    }

    if( rCopy.pDisabledValues )
    {
        pDisabledValues = new SvUShorts;
        for ( USHORT nPos = 0; nPos < rCopy.pDisabledValues->Count(); ++nPos )
        {
            pDisabledValues->Insert( rCopy.pDisabledValues->GetObject(nPos),
                                     nPos );
        }
    }
}

// -----------------------------------------------------------------------

SfxAllEnumItem::~SfxAllEnumItem()
{
    DBG_DTOR(SfxAllEnumItem, 0);
    delete pValues;
    delete pDisabledValues;
}

// -----------------------------------------------------------------------

USHORT SfxAllEnumItem::GetValueCount() const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    return pValues ? pValues->Count() : 0;
}

// -----------------------------------------------------------------------

XubString SfxAllEnumItem::GetValueTextByPos( USHORT nPos ) const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    DBG_ASSERT( pValues && nPos < pValues->Count(), "enum overflow" );
    return pValues->GetObject(nPos)->aText;
}

// -----------------------------------------------------------------------

USHORT SfxAllEnumItem::GetValueByPos( USHORT nPos ) const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    DBG_ASSERT( pValues && nPos < pValues->Count(), "enum overflow" );
    return pValues->GetObject(nPos)->nValue;
}

// -----------------------------------------------------------------------

SfxPoolItem* SfxAllEnumItem::Clone( SfxItemPool * ) const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    return new SfxAllEnumItem(*this);
}

// -----------------------------------------------------------------------

SfxPoolItem* SfxAllEnumItem::Create( SvStream & rStream, USHORT ) const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    return new SfxAllEnumItem( Which(), rStream );
}

// -----------------------------------------------------------------------

USHORT SfxAllEnumItem::_GetPosByValue( USHORT nVal ) const

/*  [Beschreibung]

    Im Ggs. zu <SfxEnumItemInterface::GetPosByValue(USHORT)const> liefert
    diese interne Methode bei nicht vorhandenen Values die Position,
    an der der Wert liegen w"urde.
*/

{
    DBG_CHKTHIS(SfxAllEnumItem, 0);

    if ( !pValues )
        return 0;

    //!O: binaere Suche oder SortArray verwenden
    USHORT nPos;
    for ( nPos = 0; nPos < pValues->Count(); ++nPos )
        if ( pValues->GetObject(nPos)->nValue >= nVal )
            return nPos;
    return nPos;
}

// -----------------------------------------------------------------------

USHORT SfxAllEnumItem::GetPosByValue( USHORT nValue ) const

/*  [Beschreibung]

    Liefert im Gegensatz zu <SfxEnumItemInterface::GetPosByValue(USHORT)const>
    immer nValue zur"uck, solange nicht mindestens ein Wert mit einer der
    Methoden <SfxAllEnumItem::InsertValue()> eingef"ugt wurde.
*/

{
    DBG_CHKTHIS(SfxAllEnumItem, 0);

    if ( !pValues || !pValues->Count() )
        return nValue;

    return SfxEnumItem::GetPosByValue( nValue );
}

// -----------------------------------------------------------------------

void SfxAllEnumItem::InsertValue( USHORT nValue, const XubString &rValue )
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
    pVal->nValue = nValue;
    pVal->aText = rValue;
    const SfxAllEnumValue_Impl *pTemp = pVal;
    if ( !pValues )
        pValues = new SfxAllEnumValueArr;
    else if ( GetPosByValue( nValue ) != USHRT_MAX )
        // remove when exists
        RemoveValue( nValue );
    // then insert
    pValues->Insert( pTemp, _GetPosByValue(nValue) ); //! doppelte?!
}

// -----------------------------------------------------------------------

void SfxAllEnumItem::InsertValue( USHORT nValue )
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
    pVal->nValue = nValue;
    pVal->aText = XubString::CreateFromInt32( nValue );
    const SfxAllEnumValue_Impl *pTemp = pVal;
    if ( !pValues )
        pValues = new SfxAllEnumValueArr;

    pValues->Insert( pTemp, _GetPosByValue(nValue) ); //! doppelte?!
}

void SfxAllEnumItem::DisableValue( USHORT nValue )
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    if ( !pDisabledValues )
        pDisabledValues = new SvUShorts;

    pDisabledValues->Insert( nValue, pDisabledValues->Count() );
}

BOOL SfxAllEnumItem::IsEnabled( USHORT nValue ) const
{
    if ( pDisabledValues )
    {
        for ( USHORT i=0; i<pDisabledValues->Count(); i++ )
            if ( (*pDisabledValues)[i] == nValue )
                return FALSE;
    }

    return TRUE;
}

// -----------------------------------------------------------------------

void SfxAllEnumItem::RemoveValue( USHORT nValue )
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    USHORT nPos = GetPosByValue(nValue);
    DBG_ASSERT( nPos != USHRT_MAX, "removing value not in enum" );
    pValues->Remove( nPos );
}

// -----------------------------------------------------------------------

void SfxAllEnumItem::RemoveAllValues()
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    if ( pValues )
        pValues->DeleteAndDestroy( 0, pValues->Count() );
}

<commit_msg>INTEGRATION: CWS vgbugs07 (1.9.200); FILE MERGED 2007/06/04 13:31:38 vg 1.9.200.1: #i76605# Remove -I .../inc/module hack introduced by hedaburemove01<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: aeitem.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: hr $ $Date: 2007-06-27 21:38:06 $
 *
 *  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_svtools.hxx"
#ifndef GCC
#endif

#include <tools/string.hxx>

#define _SVSTDARR_USHORTS
#include <svtools/svstdarr.hxx>
#include <svtools/svarray.hxx>
#include <svtools/aeitem.hxx>

// STATIC DATA -----------------------------------------------------------

DBG_NAME(SfxAllEnumItem)

TYPEINIT1_AUTOFACTORY(SfxAllEnumItem, SfxEnumItem)

// -----------------------------------------------------------------------

struct SfxAllEnumValue_Impl
{
    USHORT nValue;
    XubString aText;
};

SV_DECL_PTRARR_DEL(SfxAllEnumValueArr, SfxAllEnumValue_Impl*, 0, 8)
SV_IMPL_PTRARR(SfxAllEnumValueArr, SfxAllEnumValue_Impl*)

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem() :
    SfxEnumItem(),
    pValues( 0 ),
    pDisabledValues( 0 )
{
}

SfxAllEnumItem::SfxAllEnumItem( USHORT which, USHORT nVal, const XubString &rText ):
    SfxEnumItem(which, nVal),
    pValues( 0 ),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
    InsertValue( nVal, rText );
}

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem(USHORT which, USHORT nVal):
    SfxEnumItem(which, nVal),
    pValues( 0 ),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
    InsertValue( nVal );
}

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem( USHORT which, SvStream &rStream ):
    SfxEnumItem(which, rStream),
    pValues( 0 ),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
    InsertValue( GetValue() );
}

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem(USHORT which):
    SfxEnumItem(which, 0),
    pValues( 0 ),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
}

// -----------------------------------------------------------------------

SfxAllEnumItem::SfxAllEnumItem(const SfxAllEnumItem &rCopy):
    SfxEnumItem(rCopy),
    pValues(0),
    pDisabledValues( 0 )
{
    DBG_CTOR(SfxAllEnumItem, 0);
    if ( !rCopy.pValues )
        return;

    pValues = new SfxAllEnumValueArr;

    for ( USHORT nPos = 0; nPos < rCopy.pValues->Count(); ++nPos )
    {
        SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
        pVal->nValue = rCopy.pValues->GetObject(nPos)->nValue;
        pVal->aText = rCopy.pValues->GetObject(nPos)->aText;
        const SfxAllEnumValue_Impl *pTemp = pVal;
        pValues->Insert( pTemp, nPos );
    }

    if( rCopy.pDisabledValues )
    {
        pDisabledValues = new SvUShorts;
        for ( USHORT nPos = 0; nPos < rCopy.pDisabledValues->Count(); ++nPos )
        {
            pDisabledValues->Insert( rCopy.pDisabledValues->GetObject(nPos),
                                     nPos );
        }
    }
}

// -----------------------------------------------------------------------

SfxAllEnumItem::~SfxAllEnumItem()
{
    DBG_DTOR(SfxAllEnumItem, 0);
    delete pValues;
    delete pDisabledValues;
}

// -----------------------------------------------------------------------

USHORT SfxAllEnumItem::GetValueCount() const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    return pValues ? pValues->Count() : 0;
}

// -----------------------------------------------------------------------

XubString SfxAllEnumItem::GetValueTextByPos( USHORT nPos ) const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    DBG_ASSERT( pValues && nPos < pValues->Count(), "enum overflow" );
    return pValues->GetObject(nPos)->aText;
}

// -----------------------------------------------------------------------

USHORT SfxAllEnumItem::GetValueByPos( USHORT nPos ) const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    DBG_ASSERT( pValues && nPos < pValues->Count(), "enum overflow" );
    return pValues->GetObject(nPos)->nValue;
}

// -----------------------------------------------------------------------

SfxPoolItem* SfxAllEnumItem::Clone( SfxItemPool * ) const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    return new SfxAllEnumItem(*this);
}

// -----------------------------------------------------------------------

SfxPoolItem* SfxAllEnumItem::Create( SvStream & rStream, USHORT ) const
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    return new SfxAllEnumItem( Which(), rStream );
}

// -----------------------------------------------------------------------

USHORT SfxAllEnumItem::_GetPosByValue( USHORT nVal ) const

/*  [Beschreibung]

    Im Ggs. zu <SfxEnumItemInterface::GetPosByValue(USHORT)const> liefert
    diese interne Methode bei nicht vorhandenen Values die Position,
    an der der Wert liegen w"urde.
*/

{
    DBG_CHKTHIS(SfxAllEnumItem, 0);

    if ( !pValues )
        return 0;

    //!O: binaere Suche oder SortArray verwenden
    USHORT nPos;
    for ( nPos = 0; nPos < pValues->Count(); ++nPos )
        if ( pValues->GetObject(nPos)->nValue >= nVal )
            return nPos;
    return nPos;
}

// -----------------------------------------------------------------------

USHORT SfxAllEnumItem::GetPosByValue( USHORT nValue ) const

/*  [Beschreibung]

    Liefert im Gegensatz zu <SfxEnumItemInterface::GetPosByValue(USHORT)const>
    immer nValue zur"uck, solange nicht mindestens ein Wert mit einer der
    Methoden <SfxAllEnumItem::InsertValue()> eingef"ugt wurde.
*/

{
    DBG_CHKTHIS(SfxAllEnumItem, 0);

    if ( !pValues || !pValues->Count() )
        return nValue;

    return SfxEnumItem::GetPosByValue( nValue );
}

// -----------------------------------------------------------------------

void SfxAllEnumItem::InsertValue( USHORT nValue, const XubString &rValue )
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
    pVal->nValue = nValue;
    pVal->aText = rValue;
    const SfxAllEnumValue_Impl *pTemp = pVal;
    if ( !pValues )
        pValues = new SfxAllEnumValueArr;
    else if ( GetPosByValue( nValue ) != USHRT_MAX )
        // remove when exists
        RemoveValue( nValue );
    // then insert
    pValues->Insert( pTemp, _GetPosByValue(nValue) ); //! doppelte?!
}

// -----------------------------------------------------------------------

void SfxAllEnumItem::InsertValue( USHORT nValue )
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
    pVal->nValue = nValue;
    pVal->aText = XubString::CreateFromInt32( nValue );
    const SfxAllEnumValue_Impl *pTemp = pVal;
    if ( !pValues )
        pValues = new SfxAllEnumValueArr;

    pValues->Insert( pTemp, _GetPosByValue(nValue) ); //! doppelte?!
}

void SfxAllEnumItem::DisableValue( USHORT nValue )
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    if ( !pDisabledValues )
        pDisabledValues = new SvUShorts;

    pDisabledValues->Insert( nValue, pDisabledValues->Count() );
}

BOOL SfxAllEnumItem::IsEnabled( USHORT nValue ) const
{
    if ( pDisabledValues )
    {
        for ( USHORT i=0; i<pDisabledValues->Count(); i++ )
            if ( (*pDisabledValues)[i] == nValue )
                return FALSE;
    }

    return TRUE;
}

// -----------------------------------------------------------------------

void SfxAllEnumItem::RemoveValue( USHORT nValue )
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    USHORT nPos = GetPosByValue(nValue);
    DBG_ASSERT( nPos != USHRT_MAX, "removing value not in enum" );
    pValues->Remove( nPos );
}

// -----------------------------------------------------------------------

void SfxAllEnumItem::RemoveAllValues()
{
    DBG_CHKTHIS(SfxAllEnumItem, 0);
    if ( pValues )
        pValues->DeleteAndDestroy( 0, pValues->Count() );
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ddeimp.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: vg $ $Date: 2007-09-20 16:30:19 $
 *
 *  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
 *
 ************************************************************************/

#ifndef _DDEIMP_HXX
#define _DDEIMP_HXX

#ifdef OS2

#include "ddemlos2.h"

#define WORD USHORT
#define DWORD ULONG
#define LPBYTE BYTE*
#define LPWORD USHORT*
#define LPDWORD ULONG*
#define LPCTSTR PCSZ

#else

#include <tools/prewin.h>
#include <ddeml.h>
#include <tools/postwin.h>
#include "ddewrap.hxx"

/*
extern "C"
{
#define BOOL WIN_BOOL
#define BYTE WIN_BYTE
#undef BOOL
#undef BYTE
};
*/

#endif

#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#ifndef _LIST_HXX //autogen
#include <tools/list.hxx>
#endif
#ifndef _SHL_HXX //autogen
#include <tools/shl.hxx>
#endif

class DdeService;
class DdeTopic;
class DdeItem;
class DdeTopics;
class DdeItems;

// ----------------
// - Conversation -
// ----------------

struct Conversation
{
    HCONV       hConv;
    DdeTopic*   pTopic;
};

DECLARE_LIST( ConvList, Conversation* );

// ---------------
// - DdeInternal -
// ---------------

class DdeInternal
{
public:
#ifdef WNT
    static HDDEDATA CALLBACK CliCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK SvrCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK InfCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
#else
#if defined ( MTW ) || ( defined ( GCC ) && defined ( OS2 )) || defined( ICC )
    static HDDEDATA CALLBACK __EXPORT CliCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK __EXPORT SvrCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK __EXPORT InfCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
#else
    static HDDEDATA CALLBACK _export CliCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK _export SvrCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK _export InfCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
#endif
#endif
    static DdeService*      FindService( HSZ );
    static DdeTopic*        FindTopic( DdeService&, HSZ );
    static DdeItem*         FindItem( DdeTopic&, HSZ );
};

// -------------
// - DdeString -
// -------------

class DdeString : public String
{
protected:
    HSZ         hString;
    DWORD       hInst;

public:
                DdeString( DWORD, const sal_Unicode* );
                DdeString( DWORD, const String& );
                ~DdeString();

    int         operator==( HSZ );
                operator HSZ();
};

// --------------
// - DdeDataImp -
// --------------

struct DdeDataImp
{
    HDDEDATA        hData;
    LPBYTE          pData;
    long            nData;
    ULONG           nFmt;
};

class DdeConnections;
class DdeServices;

struct DdeInstData
{
    USHORT          nRefCount;
    DdeConnections* pConnections;
    // Server
    long            hCurConvSvr;
    ULONG           hDdeInstSvr;
    short           nInstanceSvr;
    DdeServices*    pServicesSvr;
    // Client
    ULONG           hDdeInstCli;
    short           nInstanceCli;
};

#ifndef SHL_SVDDE
#define SHL_SVDDE   SHL_SHL2
#endif

inline DdeInstData* ImpGetInstData()
{
    return (DdeInstData*)(*GetAppData( SHL_SVDDE ));
}
DdeInstData* ImpInitInstData();
void ImpDeinitInstData();

#endif // _DDEIMP_HXX
<commit_msg>INTEGRATION: CWS changefileheader (1.6.170); FILE MERGED 2008/04/01 15:45:28 thb 1.6.170.2: #i85898# Stripping all external header guards 2008/03/31 13:02:31 rt 1.6.170.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: ddeimp.hxx,v $
 * $Revision: 1.7 $
 *
 * 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.
 *
 ************************************************************************/

#ifndef _DDEIMP_HXX
#define _DDEIMP_HXX

#ifdef OS2

#include "ddemlos2.h"

#define WORD USHORT
#define DWORD ULONG
#define LPBYTE BYTE*
#define LPWORD USHORT*
#define LPDWORD ULONG*
#define LPCTSTR PCSZ

#else

#include <tools/prewin.h>
#include <ddeml.h>
#include <tools/postwin.h>
#include "ddewrap.hxx"

/*
extern "C"
{
#define BOOL WIN_BOOL
#define BYTE WIN_BYTE
#undef BOOL
#undef BYTE
};
*/

#endif
#include <tools/string.hxx>
#include <tools/list.hxx>
#include <tools/shl.hxx>

class DdeService;
class DdeTopic;
class DdeItem;
class DdeTopics;
class DdeItems;

// ----------------
// - Conversation -
// ----------------

struct Conversation
{
    HCONV       hConv;
    DdeTopic*   pTopic;
};

DECLARE_LIST( ConvList, Conversation* );

// ---------------
// - DdeInternal -
// ---------------

class DdeInternal
{
public:
#ifdef WNT
    static HDDEDATA CALLBACK CliCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK SvrCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK InfCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
#else
#if defined ( MTW ) || ( defined ( GCC ) && defined ( OS2 )) || defined( ICC )
    static HDDEDATA CALLBACK __EXPORT CliCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK __EXPORT SvrCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK __EXPORT InfCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
#else
    static HDDEDATA CALLBACK _export CliCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK _export SvrCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
    static HDDEDATA CALLBACK _export InfCallback
           ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD );
#endif
#endif
    static DdeService*      FindService( HSZ );
    static DdeTopic*        FindTopic( DdeService&, HSZ );
    static DdeItem*         FindItem( DdeTopic&, HSZ );
};

// -------------
// - DdeString -
// -------------

class DdeString : public String
{
protected:
    HSZ         hString;
    DWORD       hInst;

public:
                DdeString( DWORD, const sal_Unicode* );
                DdeString( DWORD, const String& );
                ~DdeString();

    int         operator==( HSZ );
                operator HSZ();
};

// --------------
// - DdeDataImp -
// --------------

struct DdeDataImp
{
    HDDEDATA        hData;
    LPBYTE          pData;
    long            nData;
    ULONG           nFmt;
};

class DdeConnections;
class DdeServices;

struct DdeInstData
{
    USHORT          nRefCount;
    DdeConnections* pConnections;
    // Server
    long            hCurConvSvr;
    ULONG           hDdeInstSvr;
    short           nInstanceSvr;
    DdeServices*    pServicesSvr;
    // Client
    ULONG           hDdeInstCli;
    short           nInstanceCli;
};

#ifndef SHL_SVDDE
#define SHL_SVDDE   SHL_SHL2
#endif

inline DdeInstData* ImpGetInstData()
{
    return (DdeInstData*)(*GetAppData( SHL_SVDDE ));
}
DdeInstData* ImpInitInstData();
void ImpDeinitInstData();

#endif // _DDEIMP_HXX
<|endoftext|>