<commit_before>// Copyright (c) 2013-2014 Flowgrammable, LLC.
//
// 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.

namespace freeflow {

// -------------------------------------------------------------------------- //
// Error

/// Construct an error value that signifies success.
inline
Error::Error()
  : code_(), data_() { }

/// Construt an error value with the given code. Additiional data
/// may also be associated with the error.
inline
Error::Error(Code c, Data d)
  : code_(c), data_(d) { }

/// Allows contextual conversion to bool, returning true if and only
/// if there is no error (i.e., the underlying code has value 0).
inline
Error::operator bool() const { return (bool)code_; }

/// Returns the error category.
inline const Error_category&
Error::category() const { return code_.category(); }

/// Returns the error code.
inline Error::Code
Error::code() const { return code_; }

/// Returns associated error data.
inline Error::Data
Error::data() const { return data_; }

inline std::string
Error::message() const { return code_.message(); }

/// Returns true when two errors have the same error code.
inline bool
operator==(Error a, Error b) { return a.code() == b.code(); }

inline bool
operator!=(Error a, Error b) { return not(a == b); }

// -------------------------------------------------------------------------- //
// Error constructors

/// Returns an error condition based on a predicate.
///
/// If the condition b is true, the resulting error condition will evaluate
/// to SUCCESS. Otherwise, the condition will evaluate to the code c.
inline Error
ok(bool b, Error err) { return b ? Error() : err; }

/// Returns an error code that encapsulates the current system error.
inline Error
system_error() { return system_error(errno); }

/// Returns an error value corresponding to the given system error.
inline Error
system_error(int n) { return make_error_code(static_cast<std::errc>(n)); }

// -------------------------------------------------------------------------- //
// Trap

/// Initialzie the trap with an error. This allows implicit conversions
/// to trap objects.
inline
Trap::Trap(Error e)
  : err_(e) { }

/// Allows contextual conversion to bool, returning true if and only if
/// the underlying error indicates failure.
inline
Trap::operator bool() const { return !err_; }

/// Returns the underlying error.
inline Error
Trap::error() const { return err_; }

/// Returns the error code.
inline Error::Code
Trap::code() const { return err_.code(); }

/// Returns the error data.
inline Error::Data
Trap::data() const { return err_.data(); }

} // namespace freeflow
<commit_msg>Fixing error conversion bug.<commit_after>// Copyright (c) 2013-2014 Flowgrammable, LLC.
//
// 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.

namespace freeflow {

// -------------------------------------------------------------------------- //
// Error

/// Construct an error value that signifies success.
inline
Error::Error()
  : code_(), data_() { }

/// Construt an error value with the given code. Additiional data
/// may also be associated with the error.
inline
Error::Error(Code c, Data d)
  : code_(c), data_(d) { }

/// Allows contextual conversion to bool, returning true if and only
/// if there is no error (i.e., the underlying code has value 0).
inline
Error::operator bool() const { return !code_; }

/// Returns the error category.
inline const Error_category&
Error::category() const { return code_.category(); }

/// Returns the error code.
inline Error::Code
Error::code() const { return code_; }

/// Returns associated error data.
inline Error::Data
Error::data() const { return data_; }

inline std::string
Error::message() const { return code_.message(); }

/// Returns true when two errors have the same error code.
inline bool
operator==(Error a, Error b) { return a.code() == b.code(); }

inline bool
operator!=(Error a, Error b) { return not(a == b); }

// -------------------------------------------------------------------------- //
// Error constructors

/// Returns an error condition based on a predicate.
///
/// If the condition b is true, the resulting error condition will evaluate
/// to SUCCESS. Otherwise, the condition will evaluate to the code c.
inline Error
ok(bool b, Error err) { return b ? Error() : err; }

/// Returns an error code that encapsulates the current system error.
inline Error
system_error() { return system_error(errno); }

/// Returns an error value corresponding to the given system error.
inline Error
system_error(int n) { return make_error_code(static_cast<std::errc>(n)); }

// -------------------------------------------------------------------------- //
// Trap

/// Initialzie the trap with an error. This allows implicit conversions
/// to trap objects.
inline
Trap::Trap(Error e)
  : err_(e) { }

/// Allows contextual conversion to bool, returning true if and only if
/// the underlying error does not indicate success.
inline
Trap::operator bool() const { return (bool)err_.code(); }

/// Returns the underlying error.
inline Error
Trap::error() const { return err_; }

/// Returns the error code.
inline Error::Code
Trap::code() const { return err_.code(); }

/// Returns the error data.
inline Error::Data
Trap::data() const { return err_.data(); }

} // namespace freeflow
<|endoftext|>


<commit_before>#include <reactive/bridge.hpp>
#include <reactive/ref.hpp>
#include <reactive/transform.hpp>
#include <reactive/while.hpp>
#include <reactive/finite_state_machine.hpp>
#include <reactive/filter.hpp>
#include <reactive/generate.hpp>
#include <reactive/ptr_observable.hpp>
#include <reactive/cache.hpp>
#include <reactive/get.hpp>
#include <boost/scope_exit.hpp>
#include <boost/variant.hpp>
#include <vector>

#ifdef _MSC_VER
#	include <SDL.h>
#else
#	include <SDL2/SDL.h>
#endif

namespace
{
	void throw_error()
	{
		throw std::runtime_error(std::string("SDL error :") + SDL_GetError());
	}

	void check_sdl(int rc)
	{
		if (rc < 0)
		{
			throw_error();
		}
	}

	struct window_destructor
	{
		void operator()(SDL_Window *w) const
		{
			SDL_DestroyWindow(w);
		}
	};

	struct renderer_destructor
	{
		void operator()(SDL_Renderer *r) const
		{
			SDL_DestroyRenderer(r);
		}
	};

	void set_render_draw_color(SDL_Renderer &renderer, SDL_Color color)
	{
		SDL_SetRenderDrawColor(&renderer, color.r, color.g, color.b, color.a);
	}

	SDL_Color make_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
	{
		SDL_Color result;
		result.r = red;
		result.g = green;
		result.b = blue;
		result.a = alpha;
		return result;
	}

	SDL_Rect make_rect(int x, int y, int w, int h)
	{
		SDL_Rect result;
		result.x = x;
		result.y = y;
		result.w = w;
		result.h = h;
		return result;
	}

	struct draw_filled_rect
	{
		SDL_Color color;
		SDL_Rect where;
	};

	typedef boost::variant<
		draw_filled_rect
	> draw_operation;

	struct frame
	{
		std::vector<draw_operation> operations;
	};

	struct draw_operation_renderer : boost::static_visitor<>
	{
		explicit draw_operation_renderer(SDL_Renderer &sdl)
			: sdl(&sdl)
		{
		}

		void operator()(draw_filled_rect const &operation) const
		{
			set_render_draw_color(*sdl, operation.color);
			SDL_RenderDrawRect(sdl, &operation.where);
		}

	private:

		SDL_Renderer *sdl;
	};

	void render_frame(SDL_Renderer &sdl, frame const &frame_)
	{
		set_render_draw_color(sdl, make_color(0, 0, 0, 0xff));
		SDL_RenderClear(&sdl);
		for (auto const &operation : frame_.operations)
		{
			boost::apply_visitor(draw_operation_renderer{sdl}, operation);
		}
		SDL_RenderPresent(&sdl);
	}

	struct game_state
	{
		int x = 100;
		int y = 100;
		int count = 1;
	};

	int const max_rect_count = 5;

	frame draw_game_state(game_state const &state)
	{
		std::vector<draw_operation> operations;
		for (int i = 0; i < state.count; ++i)
		{
			int const max_width = 80;
			int const single_offset = (max_width / 2) / max_rect_count;
			int const total_offset = single_offset * i;
			int const width = max_width - total_offset * 2;
			operations.emplace_back(draw_filled_rect{make_color(0xff, 0x00, 0x00, 0xff), make_rect(state.x + total_offset, state.y + total_offset, width, width)});
		}
		return frame
		{
			std::move(operations)
		};
	}

	boost::optional<game_state> step_game_state(game_state previous, SDL_Event event_)
	{
		switch (event_.type)
		{
		case SDL_QUIT:
			return boost::none;

		case SDL_KEYUP:
			{
				switch (event_.key.keysym.sym)
				{
				case SDLK_LEFT:
					previous.x -= 10;
					break;

				case SDLK_RIGHT:
					previous.x += 10;
					break;

				case SDLK_UP:
					previous.y -= 10;
					break;

				case SDLK_DOWN:
					previous.y += 10;
					break;

				case SDLK_PLUS:
					previous.count = std::min(max_rect_count, previous.count + 1);
					break;

				case SDLK_MINUS:
					previous.count = std::max(1, previous.count - 1);
					break;

				case SDLK_ESCAPE:
					return boost::none;
				}
				break;
			}
		}
		return previous;
	}

	template <class Events>
	auto make_frames(Events &&input)
#ifdef _MSC_VER
		-> rx::unique_observable<frame>
#endif
	{
		game_state initial_state;
		auto model = rx::make_finite_state_machine(std::forward<Events>(input), initial_state, step_game_state);
		return
#ifdef _MSC_VER
			rx::box<frame>
#endif
			(rx::transform(std::move(model), draw_game_state));
	}
}

int main()
{
	check_sdl(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS));
	BOOST_SCOPE_EXIT(void)
	{
		SDL_Quit();
	}
	BOOST_SCOPE_EXIT_END;

	std::unique_ptr<SDL_Window, window_destructor> window(SDL_CreateWindow("Silicium react.cpp", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, 0));
	if (!window)
	{
		throw_error();
		return 1;
	}

	std::unique_ptr<SDL_Renderer, renderer_destructor> renderer(SDL_CreateRenderer(window.get(), -1, 0));

	rx::bridge<SDL_Event> frame_events;
	auto frames = rx::cache(make_frames(rx::ref(frame_events)), frame{{}});

	for (;;)
	{
		SDL_Event event{};
		while (frame_events.is_waiting() && SDL_PollEvent(&event))
		{
			frame_events.got_element(event);
		}

		auto f = rx::get(frames);
		if (!f)
		{
			break;
		}

		render_frame(*renderer, *f);

		SDL_Delay(16);
	}
}
<commit_msg>avoid VC++ 2013 compiler crash; fix linker problem<commit_after>#include <reactive/bridge.hpp>
#include <reactive/ref.hpp>
#include <reactive/transform.hpp>
#include <reactive/while.hpp>
#include <reactive/finite_state_machine.hpp>
#include <reactive/filter.hpp>
#include <reactive/generate.hpp>
#include <reactive/ptr_observable.hpp>
#include <reactive/cache.hpp>
#include <reactive/get.hpp>
#include <boost/scope_exit.hpp>
#include <boost/variant.hpp>
#include <vector>

#ifdef _MSC_VER
#	include <SDL.h>
#else
#	include <SDL2/SDL.h>
#endif

namespace
{
	void throw_error()
	{
		throw std::runtime_error(std::string("SDL error :") + SDL_GetError());
	}

	void check_sdl(int rc)
	{
		if (rc < 0)
		{
			throw_error();
		}
	}

	struct window_destructor
	{
		void operator()(SDL_Window *w) const
		{
			SDL_DestroyWindow(w);
		}
	};

	struct renderer_destructor
	{
		void operator()(SDL_Renderer *r) const
		{
			SDL_DestroyRenderer(r);
		}
	};

	void set_render_draw_color(SDL_Renderer &renderer, SDL_Color color)
	{
		SDL_SetRenderDrawColor(&renderer, color.r, color.g, color.b, color.a);
	}

	SDL_Color make_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
	{
		SDL_Color result;
		result.r = red;
		result.g = green;
		result.b = blue;
		result.a = alpha;
		return result;
	}

	SDL_Rect make_rect(int x, int y, int w, int h)
	{
		SDL_Rect result;
		result.x = x;
		result.y = y;
		result.w = w;
		result.h = h;
		return result;
	}

	struct draw_filled_rect
	{
		SDL_Color color;
		SDL_Rect where;
	};

	typedef boost::variant<
		draw_filled_rect
	> draw_operation;

	struct frame
	{
		std::vector<draw_operation> operations;
	};

	struct draw_operation_renderer : boost::static_visitor<>
	{
		explicit draw_operation_renderer(SDL_Renderer &sdl)
			: sdl(&sdl)
		{
		}

		void operator()(draw_filled_rect const &operation) const
		{
			set_render_draw_color(*sdl, operation.color);
			SDL_RenderDrawRect(sdl, &operation.where);
		}

	private:

		SDL_Renderer *sdl;
	};

	void render_frame(SDL_Renderer &sdl, frame const &frame_)
	{
		set_render_draw_color(sdl, make_color(0, 0, 0, 0xff));
		SDL_RenderClear(&sdl);
		for (auto const &operation : frame_.operations)
		{
			boost::apply_visitor(draw_operation_renderer{sdl}, operation);
		}
		SDL_RenderPresent(&sdl);
	}

	struct game_state
	{
		int x = 100;
		int y = 100;
		int count = 1;
	};

	int const max_rect_count = 5;

	frame draw_game_state(game_state const &state)
	{
		std::vector<draw_operation> operations;
		for (int i = 0; i < state.count; ++i)
		{
			int const max_width = 80;
			int const single_offset = (max_width / 2) / max_rect_count;
			int const total_offset = single_offset * i;
			int const width = max_width - total_offset * 2;
			operations.emplace_back(draw_filled_rect{make_color(0xff, 0x00, 0x00, 0xff), make_rect(state.x + total_offset, state.y + total_offset, width, width)});
		}
		return frame
		{
			std::move(operations)
		};
	}

	boost::optional<game_state> step_game_state(game_state previous, SDL_Event event_)
	{
		switch (event_.type)
		{
		case SDL_QUIT:
			return boost::none;

		case SDL_KEYUP:
			{
				switch (event_.key.keysym.sym)
				{
				case SDLK_LEFT:
					previous.x -= 10;
					break;

				case SDLK_RIGHT:
					previous.x += 10;
					break;

				case SDLK_UP:
					previous.y -= 10;
					break;

				case SDLK_DOWN:
					previous.y += 10;
					break;

				case SDLK_PLUS:
					previous.count = std::min(max_rect_count, previous.count + 1);
					break;

				case SDLK_MINUS:
					previous.count = std::max(1, previous.count - 1);
					break;

				case SDLK_ESCAPE:
					return boost::none;
				}
				break;
			}
		}
		return previous;
	}

	template <class Events>
	auto make_frames(Events &&input)
#ifdef _MSC_VER
		-> rx::unique_observable<frame>
#endif
	{
		game_state initial_state;
		auto model = rx::make_finite_state_machine(std::forward<Events>(input), initial_state, step_game_state);
		return
#ifdef _MSC_VER
			rx::box<frame>
#endif
			(rx::transform(std::move(model), draw_game_state));
	}
}

int main(int argc, char* argv[]) //SDL2 requires the parameters on Windows
{
	check_sdl(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS));
	BOOST_SCOPE_EXIT(void)
	{
		SDL_Quit();
	}
	BOOST_SCOPE_EXIT_END;

	std::unique_ptr<SDL_Window, window_destructor> window(SDL_CreateWindow("Silicium react.cpp", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, 0));
	if (!window)
	{
		throw_error();
		return 1;
	}

	std::unique_ptr<SDL_Renderer, renderer_destructor> renderer(SDL_CreateRenderer(window.get(), -1, 0));

	rx::bridge<SDL_Event> frame_events;
	auto frames = rx::cache(make_frames(rx::ref(frame_events)), frame());

	for (;;)
	{
		SDL_Event event{};
		while (frame_events.is_waiting() && SDL_PollEvent(&event))
		{
			frame_events.got_element(event);
		}

		auto f = rx::get(frames);
		if (!f)
		{
			break;
		}

		render_frame(*renderer, *f);

		SDL_Delay(16);
	}
	return 0;
}
<|endoftext|>


<commit_before>#include <gtest/gtest.h>
#include "stan/prob/distributions/multivariate/continuous/gaussian_dlm.hpp"

using Eigen::Dynamic;
using Eigen::Matrix;
using Eigen::MatrixXd;

using boost::math::policies::policy;
using boost::math::policies::evaluation_error;
using boost::math::policies::domain_error;
using boost::math::policies::overflow_error;
using boost::math::policies::domain_error;
using boost::math::policies::pole_error;
using boost::math::policies::errno_on_error;
using stan::prob::gaussian_dlm_log;

// NOTE: what does this do?
typedef policy<
  domain_error<errno_on_error>,
  pole_error<errno_on_error>,
  overflow_error<errno_on_error>,
  evaluation_error<errno_on_error>
  > errno_policy;

TEST(ProbDistributionsGaussianDLM,LoglikeUU) {
  Matrix<double, Dynamic, Dynamic> FF(1, 1);
  FF << 0.585528817843856;
  Matrix<double, Dynamic, Dynamic> GG(1, 1);
  GG << -0.109303314681054;
  Matrix<double, Dynamic, Dynamic> V(1, 1);
  V << 2.25500747900521;
  Matrix<double, Dynamic, Dynamic> W(1, 1);
  W << 0.461487989960454;
  Matrix<double, Dynamic, Dynamic> y(1, 10);
  y << 0.435794268894196, 1.22755796113506, 0.193264580222731, 1.76021889445093, 1.6470149263738, 0.059988547306031, -0.4980979884018, 1.77794742623532, -0.435458536090977, 1.1733293160216;
  double ll_expected = -21.0504107180498;

  double lp_ref = gaussian_dlm_log(y, FF, GG, V, W);
  EXPECT_FLOAT_EQ(lp_ref, ll_expected);
}

TEST(ProbDistributionsGaussianDLM,LoglikeMM) {
  Matrix<double, Dynamic, Dynamic> FF(2, 3);
  FF << 0.585528817843856,0.709466017509524,-0.109303314681054,-0.453497173462763,0.605887455840394,-1.81795596770373;
  Matrix<double, Dynamic, Dynamic> GG(2, 2);
  GG << 0.520216457554957,0.816899839520583,-0.750531994502331,-0.886357521243213;
  Matrix<double, Dynamic, Dynamic> V(3, 3);
  V << 7.19105866377728,-0.311731853764732,4.87333111936296,-0.311731853764732,3.27048576782842,0.457616661474554,4.87333111936296,0.457616661474554,5.86564522448303;
  Matrix<double, Dynamic, Dynamic> W(2, 2);
  W << 2.24277594357501,-1.65863136283477,-1.65863136283477,6.69010664813895;
  Matrix<double, Dynamic, Dynamic> y(3, 10);
  y << 0.663454889128383, 1.84506567787219, -0.887054506009854, -2.41521382778332, 3.70875481434455, -4.55234499588754, -0.605128307725781, 1.37074056153151, -2.12107763131894, 2.24236743746261, 0.386569006173759, 3.91825641599579, 3.33368860016417, -0.469849046245645, -2.19806833413509, -1.45754611697235, 2.32377488296413, 4.8514565931381, -3.3192402890674, -4.86325482585216, -1.29504029175967, -1.15116681671907, -1.20273925104474, -2.53276712020605, -1.06306293348278, -2.38535359596865, 0.693389700056057, -3.25137196974247, 1.32287059182635, 0.745762191888096;
  double ll_expected = -90.0322237154493;

  // the error adds up in the multivariate version due to the inversion
  double lp_ref = gaussian_dlm_log(y, FF, GG, V, W);
  EXPECT_NEAR(lp_ref, ll_expected, 1e-4);
}

TEST(ProbDistributionsGaussianDLM,LoglikeUUSeq) {
  Matrix<double, Dynamic, Dynamic> FF(1, 1);
  FF << 0.585528817843856;
  Matrix<double, Dynamic, Dynamic> GG(1, 1);
  GG << -0.109303314681054;
  Matrix<double, Dynamic, Dynamic> W(1, 1);
  W << 0.461487989960454;
  Matrix<double, Dynamic, 1> V(1);
  V << 2.25500747900521;
  Matrix<double, Dynamic, Dynamic> y(1, 10);
  y << -30.2383237005506, 4.58034073011305, -0.173205689832086, 1.80027530969998, 1.64263662741284, 0.0604671098951288, -0.49815029687907, 1.77795314372528, -0.435459161031581, 1.17332938432968;
  double ll_expected = -21.0616654161768;
  double lp_ref = gaussian_dlm_log(y, FF, GG, V, W);
  EXPECT_FLOAT_EQ(lp_ref, ll_expected);
}

TEST(ProbDistributionsGaussianDLM,LoglikeMMSeq) {
  Matrix<double, Dynamic, Dynamic> FF(2, 3);
 FF << 0.585528817843856,0.709466017509524,-0.109303314681054,-0.453497173462763,0.605887455840394,-1.81795596770373;
 Matrix<double, Dynamic, Dynamic> GG(2, 2);
 GG << 0.520216457554957,0.816899839520583,-0.750531994502331,-0.886357521243213;
 Matrix<double, Dynamic, Dynamic> W(2, 2);
 W << 2.24277594357501,-1.65863136283477,-1.65863136283477,6.69010664813895;
 Matrix<double, Dynamic, 1> V(3);
 V << 7.19105866377728,3.27048576782842,5.86564522448303;
 Matrix<double, Dynamic, Dynamic> y(3, 10);
 y << -645.337793038888, -85.2449543825825, -1027.80947332792, 115.550478561317, 83.7383685001328, 79.50821971367, 52.2957712041988, -15.0415380740324, 124.483546197942, -34.6937213615964, -5.72301661410856, -55.3761417070498, 8.80290702350217, 4.44692709691049, -2.07768404916278, 1.57843833028236, 1.23783669851953, 15.5659876348306, -6.86188181853719, -5.50621793641665, -3.62888602818304, -0.145891471793544, -0.825028473757867, -2.52251372025581, -1.19867033251869, -2.47536209021952, 1.41122996270707, -5.95624742000524, 0.832231787736836, 2.38404919543544;
 double ll_expected = -82647.3683004951;
 double lp_ref = gaussian_dlm_log(y, FF, GG, V, W);
 EXPECT_FLOAT_EQ(lp_ref, ll_expected);
}

<commit_msg>updated DLM test for sizes of matrices<commit_after>#include <gtest/gtest.h>
#include "stan/prob/distributions/multivariate/continuous/gaussian_dlm.hpp"

using Eigen::Dynamic;
using Eigen::Matrix;
using Eigen::MatrixXd;

using boost::math::policies::policy;
using boost::math::policies::evaluation_error;
using boost::math::policies::domain_error;
using boost::math::policies::overflow_error;
using boost::math::policies::domain_error;
using boost::math::policies::pole_error;
using boost::math::policies::errno_on_error;
using stan::prob::gaussian_dlm_log;

// NOTE: what does this do?
typedef policy<
  domain_error<errno_on_error>,
  pole_error<errno_on_error>,
  overflow_error<errno_on_error>,
  evaluation_error<errno_on_error>
  > errno_policy;

TEST(ProbDistributionsGaussianDLM,LoglikeUU) {
  Matrix<double, Dynamic, Dynamic> FF(1, 1);
  FF << 0.585528817843856;
  Matrix<double, Dynamic, Dynamic> GG(1, 1);
  GG << -0.109303314681054;
  Matrix<double, Dynamic, Dynamic> V(1, 1);
  V << 2.25500747900521;
  Matrix<double, Dynamic, Dynamic> W(1, 1);
  W << 0.461487989960454;
  Matrix<double, Dynamic, Dynamic> y(1, 10);
  y << 0.435794268894196, 1.22755796113506, 0.193264580222731, 1.76021889445093, 1.6470149263738, 0.059988547306031, -0.4980979884018, 1.77794742623532, -0.435458536090977, 1.1733293160216;
  double ll_expected = -21.0504107180498;

  double lp_ref = gaussian_dlm_log(y, FF, GG, V, W);
  EXPECT_FLOAT_EQ(lp_ref, ll_expected);
}

TEST(ProbDistributionsGaussianDLM,LoglikeMM) {
  Matrix<double, Dynamic, Dynamic> FF(2, 3);
  FF << 0.585528817843856,0.709466017509524,-0.109303314681054,-0.453497173462763,0.605887455840394,-1.81795596770373;
  Matrix<double, Dynamic, Dynamic> GG(2, 2);
  GG << 0.520216457554957,0.816899839520583,-0.750531994502331,-0.886357521243213;
  Matrix<double, Dynamic, Dynamic> V(3, 3);
  V << 7.19105866377728,-0.311731853764732,4.87333111936296,-0.311731853764732,3.27048576782842,0.457616661474554,4.87333111936296,0.457616661474554,5.86564522448303;
  Matrix<double, Dynamic, Dynamic> W(2, 2);
  W << 2.24277594357501,-1.65863136283477,-1.65863136283477,6.69010664813895;
  Matrix<double, Dynamic, Dynamic> y(3, 10);
  y << 0.663454889128383, 1.84506567787219, -0.887054506009854, -2.41521382778332, 3.70875481434455, -4.55234499588754, -0.605128307725781, 1.37074056153151, -2.12107763131894, 2.24236743746261, 0.386569006173759, 3.91825641599579, 3.33368860016417, -0.469849046245645, -2.19806833413509, -1.45754611697235, 2.32377488296413, 4.8514565931381, -3.3192402890674, -4.86325482585216, -1.29504029175967, -1.15116681671907, -1.20273925104474, -2.53276712020605, -1.06306293348278, -2.38535359596865, 0.693389700056057, -3.25137196974247, 1.32287059182635, 0.745762191888096;
  double ll_expected = -90.0322237154493;

  // the error adds up in the multivariate version due to the inversion
  double lp_ref = gaussian_dlm_log(y, FF, GG, V, W);
  EXPECT_NEAR(lp_ref, ll_expected, 1e-4);
}

TEST(ProbDistributionsGaussianDLM,LoglikeUUSeq) {
  Matrix<double, Dynamic, Dynamic> FF(1, 1);
  FF << 0.585528817843856;
  Matrix<double, Dynamic, Dynamic> GG(1, 1);
  GG << -0.109303314681054;
  Matrix<double, Dynamic, Dynamic> W(1, 1);
  W << 0.461487989960454;
  Matrix<double, Dynamic, 1> V(1);
  V << 2.25500747900521;
  Matrix<double, Dynamic, Dynamic> y(1, 10);
  y << -30.2383237005506, 4.58034073011305, -0.173205689832086, 1.80027530969998, 1.64263662741284, 0.0604671098951288, -0.49815029687907, 1.77795314372528, -0.435459161031581, 1.17332938432968;
  double ll_expected = -21.0616654161768;
  double lp_ref = gaussian_dlm_log(y, FF, GG, V, W);
  EXPECT_FLOAT_EQ(lp_ref, ll_expected);
}

TEST(ProbDistributionsGaussianDLM,LoglikeMMSeq) {
  Matrix<double, Dynamic, Dynamic> FF(2, 3);
 FF << 0.585528817843856,0.709466017509524,-0.109303314681054,-0.453497173462763,0.605887455840394,-1.81795596770373;
 Matrix<double, Dynamic, Dynamic> GG(2, 2);
 GG << 0.520216457554957,0.816899839520583,-0.750531994502331,-0.886357521243213;
 Matrix<double, Dynamic, Dynamic> W(2, 2);
 W << 2.24277594357501,-1.65863136283477,-1.65863136283477,6.69010664813895;
 Matrix<double, Dynamic, 1> V(3);
 V << 7.19105866377728,3.27048576782842,5.86564522448303;
 Matrix<double, Dynamic, Dynamic> y(3, 10);
 y << -645.337793038888, -85.2449543825825, -1027.80947332792, 115.550478561317, 83.7383685001328, 79.50821971367, 52.2957712041988, -15.0415380740324, 124.483546197942, -34.6937213615964, -5.72301661410856, -55.3761417070498, 8.80290702350217, 4.44692709691049, -2.07768404916278, 1.57843833028236, 1.23783669851953, 15.5659876348306, -6.86188181853719, -5.50621793641665, -3.62888602818304, -0.145891471793544, -0.825028473757867, -2.52251372025581, -1.19867033251869, -2.47536209021952, 1.41122996270707, -5.95624742000524, 0.832231787736836, 2.38404919543544;
 double ll_expected = -82647.3683004951;
 double lp_ref = gaussian_dlm_log(y, FF, GG, V, W);
 EXPECT_FLOAT_EQ(lp_ref, ll_expected);
}

TEST(ProbDistributionsGaussianDLM,Sizing) {
  // consistent matrices
  Matrix<double, Dynamic, Dynamic> FF = MatrixXd::Random(2, 3);
  Matrix<double, Dynamic, Dynamic> GG = MatrixXd::Random(2, 2);
  Matrix<double, Dynamic, Dynamic> V = MatrixXd::Identity(3, 3);
  Matrix<double, Dynamic, Dynamic> W = MatrixXd::Identity(2, 2);
  Matrix<double, Dynamic, Dynamic> y = MatrixXd::Identity(3, 5);

  Matrix<double, Dynamic, Dynamic> bad_FF_1 = MatrixXd::Random(4, 3);
  EXPECT_ANY_THROW(gaussian_dlm_log(y, bad_FF_1, GG, V, W));

  Matrix<double, Dynamic, Dynamic> bad_FF_2 = MatrixXd::Random(2, 4);
  EXPECT_ANY_THROW(gaussian_dlm_log(y, bad_FF_2, GG, V, W));

  Matrix<double, Dynamic, Dynamic> bad_GG_1 = MatrixXd::Random(3, 3);
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, bad_GG_1, V, W));
  Matrix<double, Dynamic, Dynamic> bad_GG_2 = MatrixXd::Random(2, 3);
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, bad_GG_2, V, W));

  //Not symmetric
  V(0, 2) = 1;
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, GG, V, W));
  // negative
  V(0, 2) = -1;
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, GG, V, W));

  // wrong size
  Matrix<double, Dynamic, Dynamic> V1 = MatrixXd::Identity(2, 2);
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, GG, V1, W));
  // not square
  Matrix<double, Dynamic, Dynamic> V2 = MatrixXd::Identity(2, 3);
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, GG, V2, W));

  //Not symmetric
  W(0, 1) = 1;
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, GG, V, W));
  // negative
  W(0, 1) = -1;
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, GG, V, W));
  // wrong size
  Matrix<double, Dynamic, Dynamic> W1 = MatrixXd::Identity(3, 3);
  EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, GG, V, W1));
  // not square
  Matrix<double, Dynamic, Dynamic> W2 = MatrixXd::Identity(2, 3);
  // EXPECT_ANY_THROW(gaussian_dlm_log(y, FF, GG, V, W2));

}
<|endoftext|>


<commit_before>#include "Base.h"
#include "ScriptController.h"
#include "ScriptTarget.h"

namespace gameplay
{

extern void splitURL(const std::string& url, std::string* file, std::string* id);

ScriptTarget::~ScriptTarget()
{
    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.begin();
    for (; iter != _callbacks.end(); iter++)
    {
        SAFE_DELETE(iter->second);
    }
}

template<> void ScriptTarget::fireEvent<void>(const char* eventName, ...)
{
    va_list list;
    va_start(list, eventName);

    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.find(eventName);
    if (iter != _callbacks.end() && iter->second != NULL)
    {
        ScriptController* sc = Game::getInstance()->getScriptController();

        if (_events[eventName].size() > 0)
        {
            for (unsigned int i = 0; i < iter->second->size(); i++)
            {
                sc->executeFunction<void>((*iter->second)[i].function.c_str(), _events[eventName].c_str(), &list);
            }
        }
        else
        {
            for (unsigned int i = 0; i < iter->second->size(); i++)
            {
                sc->executeFunction<void>((*iter->second)[i].function.c_str(), _events[eventName].c_str());
            }
        }
    }

    va_end(list);
}

template<> bool ScriptTarget::fireEvent<bool>(const char* eventName, ...)
{
    va_list list;
    va_start(list, eventName);

    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.find(eventName);
    if (iter != _callbacks.end())
    {
        ScriptController* sc = Game::getInstance()->getScriptController();

        if (_events[eventName].size() > 0)
        {
            for (unsigned int i = 0; i < iter->second->size(); i++)
            {
                if (sc->executeFunction<bool>((*iter->second)[i].function.c_str(), _events[eventName].c_str(), &list))
                {
                    va_end(list);
                    return true;
                }
            }
        }
        else
        {
            for (unsigned int i = 0; i < iter->second->size(); i++)
            {
                if (sc->executeFunction<bool>((*iter->second)[i].function.c_str(), _events[eventName].c_str()))
                {
                    va_end(list);
                    return true;
                }
            }
        }
    }

    va_end(list);
    return false;
}

void ScriptTarget::addCallback(const std::string& eventName, const std::string& function)
{
    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.find(eventName);
    if (iter != _callbacks.end())
    {
        if (!iter->second)
            iter->second = new std::vector<Callback>();

        // Add the function to the list of callbacks.
        std::string functionName = Game::getInstance()->getScriptController()->loadUrl(function.c_str());
        iter->second->push_back(Callback(functionName));
    }
    else
    {
        GP_ERROR("Attempting to add a script callback for unsupported event '%s'.", eventName.c_str());
    }
}

void ScriptTarget::removeCallback(const std::string& eventName, const std::string& function)
{
    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.find(eventName);
    if (iter != _callbacks.end())
    {
        if (!iter->second)
            return;

        std::string file;
        std::string id;
        splitURL(function, &file, &id);

        // Make sure the function isn't empty.
        if (id.size() <= 0)
            return;

        // Remove the function from the list of callbacks.
        for (unsigned int i = 0; i < iter->second->size(); i++)
        {
            if ((*iter->second)[i].function == id)
            {
                iter->second->erase(iter->second->begin() + i);
                return;
            }
        }
    }
    else
    {
        GP_ERROR("Attempting to remove a script callback for unsupported event '%s'.", eventName.c_str());
    }
}

void ScriptTarget::addEvent(const std::string& eventName, const char* argsString)
{
    _events[eventName] = (argsString ? argsString : "");
    _callbacks[eventName] = NULL;
}

ScriptTarget::Callback::Callback(const std::string& function) : function(function)
{
}

}
<commit_msg>Fixed null pointer in ScriptTarget.<commit_after>#include "Base.h"
#include "ScriptController.h"
#include "ScriptTarget.h"

namespace gameplay
{

extern void splitURL(const std::string& url, std::string* file, std::string* id);

ScriptTarget::~ScriptTarget()
{
    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.begin();
    for (; iter != _callbacks.end(); iter++)
    {
        SAFE_DELETE(iter->second);
    }
}

template<> void ScriptTarget::fireEvent<void>(const char* eventName, ...)
{
    va_list list;
    va_start(list, eventName);

    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.find(eventName);
    if (iter != _callbacks.end() && iter->second != NULL)
    {
        ScriptController* sc = Game::getInstance()->getScriptController();

        if (_events[eventName].size() > 0)
        {
            for (unsigned int i = 0; i < iter->second->size(); i++)
            {
                sc->executeFunction<void>((*iter->second)[i].function.c_str(), _events[eventName].c_str(), &list);
            }
        }
        else
        {
            for (unsigned int i = 0; i < iter->second->size(); i++)
            {
                sc->executeFunction<void>((*iter->second)[i].function.c_str(), _events[eventName].c_str());
            }
        }
    }

    va_end(list);
}

template<> bool ScriptTarget::fireEvent<bool>(const char* eventName, ...)
{
    va_list list;
    va_start(list, eventName);

    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.find(eventName);
    if (iter != _callbacks.end() && iter->second)
    {
        ScriptController* sc = Game::getInstance()->getScriptController();

        if (_events[eventName].size() > 0)
        {
            for (unsigned int i = 0; i < iter->second->size(); i++)
            {
                if (sc->executeFunction<bool>((*iter->second)[i].function.c_str(), _events[eventName].c_str(), &list))
                {
                    va_end(list);
                    return true;
                }
            }
        }
        else
        {
            for (unsigned int i = 0; i < iter->second->size(); i++)
            {
                if (sc->executeFunction<bool>((*iter->second)[i].function.c_str(), _events[eventName].c_str()))
                {
                    va_end(list);
                    return true;
                }
            }
        }
    }

    va_end(list);
    return false;
}

void ScriptTarget::addCallback(const std::string& eventName, const std::string& function)
{
    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.find(eventName);
    if (iter != _callbacks.end())
    {
        if (!iter->second)
            iter->second = new std::vector<Callback>();

        // Add the function to the list of callbacks.
        std::string functionName = Game::getInstance()->getScriptController()->loadUrl(function.c_str());
        iter->second->push_back(Callback(functionName));
    }
    else
    {
        GP_ERROR("Attempting to add a script callback for unsupported event '%s'.", eventName.c_str());
    }
}

void ScriptTarget::removeCallback(const std::string& eventName, const std::string& function)
{
    std::map<std::string, std::vector<Callback>* >::iterator iter = _callbacks.find(eventName);
    if (iter != _callbacks.end())
    {
        if (!iter->second)
            return;

        std::string file;
        std::string id;
        splitURL(function, &file, &id);

        // Make sure the function isn't empty.
        if (id.size() <= 0)
            return;

        // Remove the function from the list of callbacks.
        for (unsigned int i = 0; i < iter->second->size(); i++)
        {
            if ((*iter->second)[i].function == id)
            {
                iter->second->erase(iter->second->begin() + i);
                return;
            }
        }
    }
    else
    {
        GP_ERROR("Attempting to remove a script callback for unsupported event '%s'.", eventName.c_str());
    }
}

void ScriptTarget::addEvent(const std::string& eventName, const char* argsString)
{
    _events[eventName] = (argsString ? argsString : "");
    _callbacks[eventName] = NULL;
}

ScriptTarget::Callback::Callback(const std::string& function) : function(function)
{
}

}
<|endoftext|>


<commit_before>/**
 *  Exception_handler.cpp
 *
 *  Set the exception handler
 *
 *  @author Toon Schoenmakers <toon.schoenmakers@copernica.com>
 */

/**
 *  Dependencies
 */
#include "includes.h"

/**
 *  Open the PHP namespace
 */
namespace Php {

/**
 *  Set a std::function as a php exception handler
 */
Value set_exception_handler(const std::function<Value(Parameters &params)> &handler)
{
    // create a functor which wraps our callback
    Function functor(handler);

    // initialize our output value
    Value output;

    // turn our user_exception_handler into a Value so we can return the original one later on
    if (EG(user_exception_handler)) output = EG(user_exception_handler);

    // detach so we have the zval
    auto value = functor.detach(true);

    // allocate the user_exception_handler
    ALLOC_ZVAL(EG(user_exception_handler));

    // copy our zval into the user_exception_handler
    MAKE_COPY_ZVAL(&value, EG(user_exception_handler));

    // return the original handler
    return output;
}

/**
 *  Set a std::function as a php error handler
 */
Value set_error_handler(const std::function<Value(Parameters &params)> &handler, Error error)
{
    // create the functor which wraps our callback
    Function functor(handler);

    // initialize our output value
    Value output;

    // turn our user_error_handler into a Value if we have one, just so we can return it later on
    if (EG(user_error_handler)) output = EG(user_error_handler);

    // detach so we have the zval
    auto value = functor.detach(true);

    // alocate the user_error_handler
    ALLOC_ZVAL(EG(user_error_handler));

    // copy our zval into the user_error_handler
    MAKE_COPY_ZVAL(&value, EG(user_error_handler));
    EG(user_error_handler_error_reporting) = (int) error;

    // return the original handler
    return output;
}

/**
 *  Modify the error reporting level, will return the old error reporting level.
 */
Value error_reporting(Error error)
{
    // store the old error reporting value
    Value output(EG(error_reporting));

    // create a small temporary buffer
    char str[21];

    // write the level into this buffer
    int size = sprintf(str, "%d", (int) error);

    // if we failed for some reason we bail out
    if (size < 0) return false;

    // alter the ini on the fly
    zend_alter_ini_entry("error_reporting", sizeof("error_reporting"), str, size, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);

    // return the output
    return output;
}

/**
 *  End of namespace
 */
}
<commit_msg>Fix compiler errors when compiling for a multi-threading environment, fixes issue #226<commit_after>/**
 *  Exception_handler.cpp
 *
 *  Set the exception handler
 *
 *  @author Toon Schoenmakers <toon.schoenmakers@copernica.com>
 */

/**
 *  Dependencies
 */
#include "includes.h"

/**
 *  Open the PHP namespace
 */
namespace Php {

/**
 *  Set a std::function as a php exception handler
 */
Value set_exception_handler(const std::function<Value(Parameters &params)> &handler)
{
    // we need the tsrm_ls variable
    TSRMLS_FETCH();

    // create a functor which wraps our callback
    Function functor(handler);

    // initialize our output value
    Value output;

    // turn our user_exception_handler into a Value so we can return the original one later on
    if (EG(user_exception_handler)) output = EG(user_exception_handler);

    // detach so we have the zval
    auto value = functor.detach(true);

    // allocate the user_exception_handler
    ALLOC_ZVAL(EG(user_exception_handler));

    // copy our zval into the user_exception_handler
    MAKE_COPY_ZVAL(&value, EG(user_exception_handler));

    // return the original handler
    return output;
}

/**
 *  Set a std::function as a php error handler
 */
Value set_error_handler(const std::function<Value(Parameters &params)> &handler, Error error)
{
    // we need the tsrm_ls variable
    TSRMLS_FETCH();

    // create the functor which wraps our callback
    Function functor(handler);

    // initialize our output value
    Value output;

    // turn our user_error_handler into a Value if we have one, just so we can return it later on
    if (EG(user_error_handler)) output = EG(user_error_handler);

    // detach so we have the zval
    auto value = functor.detach(true);

    // alocate the user_error_handler
    ALLOC_ZVAL(EG(user_error_handler));

    // copy our zval into the user_error_handler
    MAKE_COPY_ZVAL(&value, EG(user_error_handler));
    EG(user_error_handler_error_reporting) = (int) error;

    // return the original handler
    return output;
}

/**
 *  Modify the error reporting level, will return the old error reporting level.
 */
Value error_reporting(Error error)
{
    // we need the tsrm_ls variable
    TSRMLS_FETCH();

    // store the old error reporting value
    Value output(EG(error_reporting));

    // create a small temporary buffer
    char str[21];

    // write the level into this buffer
    int size = sprintf(str, "%d", (int) error);

    // if we failed for some reason we bail out
    if (size < 0) return false;

    // alter the ini on the fly
    zend_alter_ini_entry("error_reporting", sizeof("error_reporting"), str, size, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);

    // return the output
    return output;
}

/**
 *  End of namespace
 */
}
<|endoftext|>


<commit_before>/*

Copyright (c) 2003, Arvid Norberg
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 author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

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

*/

#include <algorithm>
#include "libtorrent/entry.hpp"
#include <boost/bind.hpp>
#include <boost/next_prior.hpp>

#if defined(_MSC_VER)
namespace std
{
	using ::isprint;
}
#define for if (false) {} else for
#endif

namespace
{
	template <class T>
	void call_destructor(T* o)
	{
		assert(o);
		o->~T();
	}

	struct compare_string
	{
		compare_string(char const* s): m_str(s)  {}

		bool operator()(
			std::pair<std::string
			, libtorrent::entry> const& e) const
		{
			return e.first == m_str;
		}
		char const* m_str;
	};
}

namespace libtorrent
{
	namespace detail
	{
		char const*	integer_to_str(char* buf, int size, entry::integer_type val)
		{
			int sign = 0;
			if (val < 0)
			{
				sign = 1;
				val = -val;
			}
			buf[--size] = '\0';
			if (val == 0) buf[--size] = '0';
			for (; size > sign && val != 0;)
			{
				buf[--size] = '0' + char(val % 10);
				val /= 10;
			}
			if (sign) buf[--size] = '-';
			return buf + size;
		}
	}

	entry& entry::operator[](char const* key)
	{
		dictionary_type::iterator i = std::find_if(
			dict().begin()
			, dict().end()
			, compare_string(key));
		if (i != dict().end()) return i->second;
		dictionary_type::iterator ret = dict().insert(
			dict().end()
			, std::make_pair(std::string(key), entry()));
		return ret->second;
	}

	entry& entry::operator[](std::string const& key)
	{
		return (*this)[key.c_str()];
	}

	entry* entry::find_key(char const* key)
	{
		dictionary_type::iterator i = std::find_if(
			dict().begin()
			, dict().end()
			, compare_string(key));
		if (i == dict().end()) return 0;
		return &i->second;

	}

	entry const* entry::find_key(char const* key) const
	{
		dictionary_type::const_iterator i = std::find_if(
			dict().begin()
			, dict().end()
			, compare_string(key));
		if (i == dict().end()) return 0;
		return &i->second;

	}

	const entry& entry::operator[](char const* key) const
	{
		dictionary_type::const_iterator i = std::find_if(
			dict().begin()
			, dict().end()
			, compare_string(key));
		if (i == dict().end()) throw type_error("key not found");
		return i->second;
	}

	const entry& entry::operator[](std::string const& key) const
	{
		return (*this)[key.c_str()];
	}

	entry::entry(const dictionary_type& v)
	{
		new(data) dictionary_type(v);
		m_type = dictionary_t;
	}

	entry::entry(const string_type& v)
	{
		new(data) string_type(v);
		m_type = string_t;
	}

	entry::entry(const list_type& v)
	{
		new(data) list_type(v);
		m_type = list_t;
	}

	entry::entry(const integer_type& v)
	{
		new(data) integer_type(v);
		m_type = int_t;
	}

	void entry::operator=(const dictionary_type& v)
	{
		destruct();
		new(data) dictionary_type(v);
		m_type = dictionary_t;
	}

	void entry::operator=(const string_type& v)
	{
		destruct();
		new(data) string_type(v);
		m_type = string_t;
	}

	void entry::operator=(const list_type& v)
	{
		destruct();
		new(data) list_type(v);
		m_type = list_t;
	}

	void entry::operator=(const integer_type& v)
	{
		destruct();
		new(data) integer_type(v);
		m_type = int_t;
	}

	bool entry::operator==(entry const& e) const
	{
		if (m_type != e.m_type) return false;

		switch(m_type)
		{
		case int_t:
			return integer() == e.integer();
		case string_t:
			return string() == e.string();
		case list_t:
			return list() == e.list();
		case dictionary_t:
			return dict() == e.dict();
		default:
			assert(m_type == undefined_t);
			return true;
		}
	}

	void entry::construct(data_type t)
	{
		m_type = t;
		switch(m_type)
		{
		case int_t:
			new(data) integer_type;
			break;
		case string_t:
			new(data) string_type;
			break;
		case list_t:
			new(data) list_type;
			break;
		case dictionary_t:
			new (data) dictionary_type;
			break;
		default:
			assert(m_type == undefined_t);
			m_type = undefined_t;
		}
	}

	void entry::copy(const entry& e)
	{
		m_type = e.m_type;
		switch(m_type)
		{
		case int_t:
			new(data) integer_type(e.integer());
			break;
		case string_t:
			new(data) string_type(e.string());
			break;
		case list_t:
			new(data) list_type(e.list());
			break;
		case dictionary_t:
			new (data) dictionary_type(e.dict());
			break;
		default:
			m_type = undefined_t;
		}
	}

	void entry::destruct()
	{
		switch(m_type)
		{
		case int_t:
			call_destructor(reinterpret_cast<integer_type*>(data));
			break;
		case string_t:
			call_destructor(reinterpret_cast<string_type*>(data));
			break;
		case list_t:
			call_destructor(reinterpret_cast<list_type*>(data));
			break;
		case dictionary_t:
			call_destructor(reinterpret_cast<dictionary_type*>(data));
			break;
		default:
			assert(m_type == undefined_t);
			break;
		}
	}

	void entry::print(std::ostream& os, int indent) const
	{
		assert(indent >= 0);
		for (int i = 0; i < indent; ++i) os << " ";
		switch (m_type)
		{
		case int_t:
			os << integer() << "\n";
			break;
		case string_t:
			{
				bool binary_string = false;
				for (std::string::const_iterator i = string().begin(); i != string().end(); ++i)
				{
					if (!std::isprint(static_cast<unsigned char>(*i)))
					{
						binary_string = true;
						break;
					}
				}
				if (binary_string)
				{
					os.unsetf(std::ios_base::dec);
					os.setf(std::ios_base::hex);
					for (std::string::const_iterator i = string().begin(); i != string().end(); ++i)
						os << static_cast<unsigned int>((unsigned char)*i);
					os.unsetf(std::ios_base::hex);
					os.setf(std::ios_base::dec);
					os << "\n";
				}
				else
				{
					os << string() << "\n";
				}
			} break;
		case list_t:
			{
				os << "list\n";
				for (list_type::const_iterator i = list().begin(); i != list().end(); ++i)
				{
					i->print(os, indent+1);
				}
			} break;
		case dictionary_t:
			{
				os << "dictionary\n";
				for (dictionary_type::const_iterator i = dict().begin(); i != dict().end(); ++i)
				{
					for (int j = 0; j < indent+1; ++j) os << " ";
					os << "[" << i->first << "]";
					if (i->second.type() != entry::string_t && i->second.type() != entry::int_t) os << "\n";
					else os << " ";
					i->second.print(os, indent+2);
				}
			} break;
		default:
			os << "<uninitialized>\n";
		}
	}
}
<commit_msg>optimizations to entry (using std::maps find instead of linear search)<commit_after>/*

Copyright (c) 2003, Arvid Norberg
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 author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

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

*/

#include <algorithm>
#include "libtorrent/entry.hpp"
#include <boost/bind.hpp>
#include <boost/next_prior.hpp>

#if defined(_MSC_VER)
namespace std
{
	using ::isprint;
}
#define for if (false) {} else for
#endif

namespace
{
	template <class T>
	void call_destructor(T* o)
	{
		assert(o);
		o->~T();
	}

	struct compare_string
	{
		compare_string(char const* s): m_str(s)  {}

		bool operator()(
			std::pair<std::string
			, libtorrent::entry> const& e) const
		{
			return e.first == m_str;
		}
		char const* m_str;
	};
}

namespace libtorrent
{
	namespace detail
	{
		char const*	integer_to_str(char* buf, int size, entry::integer_type val)
		{
			int sign = 0;
			if (val < 0)
			{
				sign = 1;
				val = -val;
			}
			buf[--size] = '\0';
			if (val == 0) buf[--size] = '0';
			for (; size > sign && val != 0;)
			{
				buf[--size] = '0' + char(val % 10);
				val /= 10;
			}
			if (sign) buf[--size] = '-';
			return buf + size;
		}
	}

	entry& entry::operator[](char const* key)
	{
		dictionary_type::iterator i = dict().find(key);
		if (i != dict().end()) return i->second;
		dictionary_type::iterator ret = dict().insert(
			dict().begin()
			, std::make_pair(std::string(key), entry()));
		return ret->second;
	}

	entry& entry::operator[](std::string const& key)
	{
		return (*this)[key.c_str()];
	}

	entry* entry::find_key(char const* key)
	{
		dictionary_type::iterator i = std::find_if(
			dict().begin()
			, dict().end()
			, compare_string(key));
		if (i == dict().end()) return 0;
		return &i->second;

	}

	entry const* entry::find_key(char const* key) const
	{
		dictionary_type::const_iterator i = dict().find(key);
		if (i == dict().end()) return 0;
		return &i->second;
	}

	const entry& entry::operator[](char const* key) const
	{
		dictionary_type::const_iterator i = dict().find(key);
		if (i == dict().end()) throw type_error(
			(std::string("key not found: ") + key).c_str());
		return i->second;
	}

	const entry& entry::operator[](std::string const& key) const
	{
		return (*this)[key.c_str()];
	}

	entry::entry(const dictionary_type& v)
	{
		new(data) dictionary_type(v);
		m_type = dictionary_t;
	}

	entry::entry(const string_type& v)
	{
		new(data) string_type(v);
		m_type = string_t;
	}

	entry::entry(const list_type& v)
	{
		new(data) list_type(v);
		m_type = list_t;
	}

	entry::entry(const integer_type& v)
	{
		new(data) integer_type(v);
		m_type = int_t;
	}

	void entry::operator=(const dictionary_type& v)
	{
		destruct();
		new(data) dictionary_type(v);
		m_type = dictionary_t;
	}

	void entry::operator=(const string_type& v)
	{
		destruct();
		new(data) string_type(v);
		m_type = string_t;
	}

	void entry::operator=(const list_type& v)
	{
		destruct();
		new(data) list_type(v);
		m_type = list_t;
	}

	void entry::operator=(const integer_type& v)
	{
		destruct();
		new(data) integer_type(v);
		m_type = int_t;
	}

	bool entry::operator==(entry const& e) const
	{
		if (m_type != e.m_type) return false;

		switch(m_type)
		{
		case int_t:
			return integer() == e.integer();
		case string_t:
			return string() == e.string();
		case list_t:
			return list() == e.list();
		case dictionary_t:
			return dict() == e.dict();
		default:
			assert(m_type == undefined_t);
			return true;
		}
	}

	void entry::construct(data_type t)
	{
		m_type = t;
		switch(m_type)
		{
		case int_t:
			new(data) integer_type;
			break;
		case string_t:
			new(data) string_type;
			break;
		case list_t:
			new(data) list_type;
			break;
		case dictionary_t:
			new (data) dictionary_type;
			break;
		default:
			assert(m_type == undefined_t);
			m_type = undefined_t;
		}
	}

	void entry::copy(const entry& e)
	{
		m_type = e.m_type;
		switch(m_type)
		{
		case int_t:
			new(data) integer_type(e.integer());
			break;
		case string_t:
			new(data) string_type(e.string());
			break;
		case list_t:
			new(data) list_type(e.list());
			break;
		case dictionary_t:
			new (data) dictionary_type(e.dict());
			break;
		default:
			m_type = undefined_t;
		}
	}

	void entry::destruct()
	{
		switch(m_type)
		{
		case int_t:
			call_destructor(reinterpret_cast<integer_type*>(data));
			break;
		case string_t:
			call_destructor(reinterpret_cast<string_type*>(data));
			break;
		case list_t:
			call_destructor(reinterpret_cast<list_type*>(data));
			break;
		case dictionary_t:
			call_destructor(reinterpret_cast<dictionary_type*>(data));
			break;
		default:
			assert(m_type == undefined_t);
			break;
		}
	}

	void entry::print(std::ostream& os, int indent) const
	{
		assert(indent >= 0);
		for (int i = 0; i < indent; ++i) os << " ";
		switch (m_type)
		{
		case int_t:
			os << integer() << "\n";
			break;
		case string_t:
			{
				bool binary_string = false;
				for (std::string::const_iterator i = string().begin(); i != string().end(); ++i)
				{
					if (!std::isprint(static_cast<unsigned char>(*i)))
					{
						binary_string = true;
						break;
					}
				}
				if (binary_string)
				{
					os.unsetf(std::ios_base::dec);
					os.setf(std::ios_base::hex);
					for (std::string::const_iterator i = string().begin(); i != string().end(); ++i)
						os << static_cast<unsigned int>((unsigned char)*i);
					os.unsetf(std::ios_base::hex);
					os.setf(std::ios_base::dec);
					os << "\n";
				}
				else
				{
					os << string() << "\n";
				}
			} break;
		case list_t:
			{
				os << "list\n";
				for (list_type::const_iterator i = list().begin(); i != list().end(); ++i)
				{
					i->print(os, indent+1);
				}
			} break;
		case dictionary_t:
			{
				os << "dictionary\n";
				for (dictionary_type::const_iterator i = dict().begin(); i != dict().end(); ++i)
				{
					for (int j = 0; j < indent+1; ++j) os << " ";
					os << "[" << i->first << "]";
					if (i->second.type() != entry::string_t && i->second.type() != entry::int_t) os << "\n";
					else os << " ";
					i->second.print(os, indent+2);
				}
			} break;
		default:
			os << "<uninitialized>\n";
		}
	}
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: alienwarn.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: rt $ $Date: 2007-04-26 10:10:14 $
 *
 *  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_sfx2.hxx"

#include "alienwarn.hxx"
#include "sfxresid.hxx"
#include "sfxuno.hxx"

#include "alienwarn.hrc"
#include "dialog.hrc"

#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_SAVEOPT_HXX
#include <svtools/saveopt.hxx>
#endif

// class SfxAlienWarningDialog -------------------------------------------

SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :

    SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),

    m_aQueryImage   ( this, SfxResId( FI_QUERY ) ),
    m_aInfoText     ( this, SfxResId( FT_INFOTEXT ) ),
    m_aYesBtn       ( this, SfxResId( PB_YES ) ),
    m_aNoBtn        ( this, SfxResId( PB_NO ) ),
    m_aMoreInfoBtn  ( this, SfxResId( PB_MOREINFO ) ),
    m_aOptionLine   ( this, SfxResId( FL_OPTION ) ),
    m_aWarningOffBox( this, SfxResId( CB_WARNING_OFF ) )

{
    FreeResource();

    // set questionmark image
    m_aQueryImage.SetImage( QueryBox::GetStandardImage() );

    // replace formatname
    String sInfoText = m_aInfoText.GetText();
    sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
    m_aInfoText.SetText( sInfoText );

    // load value of "warning off" checkbox from save options
    m_aWarningOffBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_False );

    // set focus to "No" button
    m_aNoBtn.GrabFocus();

    // pb: #i43989# we have no online help for this dialog at the moment
    // -> hide the "more info" button
    m_aMoreInfoBtn.Hide();

    // calculate and set the size of the dialog and its controls
    InitSize();
}

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

SfxAlienWarningDialog::~SfxAlienWarningDialog()
{
    // save value of "warning off" checkbox, if necessary
    SvtSaveOptions aSaveOpt;
    sal_Bool bChecked = !m_aWarningOffBox.IsChecked();
    if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
        aSaveOpt.SetWarnAlienFormat( bChecked );
}

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

void SfxAlienWarningDialog::InitSize()
{
    // if the button text is too wide, then broaden the button
    long nTxtW = m_aMoreInfoBtn.GetTextWidth( m_aMoreInfoBtn.GetText() );
    long nCtrlW = m_aMoreInfoBtn.GetSizePixel().Width();
    if ( nTxtW >= nCtrlW )
    {
        long nDelta = nTxtW - nCtrlW;
        nDelta += 6; // a little more space looks better
        Point aNextPoint = m_aNoBtn.GetPosPixel();
        aNextPoint.X() += m_aNoBtn.GetSizePixel().Width();
        Point aNewPoint = m_aMoreInfoBtn.GetPosPixel();
        aNewPoint.X() -= nDelta;
        if ( aNextPoint.X() >= aNewPoint.X() )
        {
            long nSpace = aNextPoint.X() - aNewPoint.X();
            nSpace += 2;
            nDelta -= nSpace;
            aNewPoint.X() += nSpace;
        }
        Size aNewSize = m_aMoreInfoBtn.GetSizePixel();
        aNewSize.Width() += nDelta;
        m_aMoreInfoBtn.SetPosSizePixel( aNewPoint, aNewSize );
    }

    // text of checkbox to wide -> add new line
    nTxtW = m_aWarningOffBox.GetTextWidth( m_aWarningOffBox.GetText() );
    nCtrlW = m_aWarningOffBox.GetSizePixel().Width();
    if ( nTxtW >= nCtrlW )
    {
        long nTextHeight = m_aWarningOffBox.GetTextHeight();
        Size aNewSize = m_aWarningOffBox.GetSizePixel();
        aNewSize.Height() += nTextHeight;
        m_aWarningOffBox.SetSizePixel( aNewSize );
        aNewSize = GetSizePixel();
        aNewSize.Height() += nTextHeight;
        SetSizePixel( aNewSize );
    }

    // align the size of the information text control (FixedText) to its content
    Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
    long nTxtH = aMinSize.Height();
    long nCtrlH = m_aInfoText.GetSizePixel().Height();
    long nDelta = ( nCtrlH - nTxtH );
    Size aNewSize = m_aInfoText.GetSizePixel();
    aNewSize.Height() -= nDelta;
    m_aInfoText.SetSizePixel( aNewSize );

    // new position for the succeeding windows
    Window* pWins[] =
    {
        &m_aYesBtn, &m_aNoBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOffBox
    };
    Window** pCurrent = pWins;
    for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
    {
        Point aNewPos = (*pCurrent)->GetPosPixel();
        aNewPos.Y() -= nDelta;
        (*pCurrent)->SetPosPixel( aNewPos );
    }

    // new size of the dialog
    aNewSize = GetSizePixel();
    aNewSize.Height() -= nDelta;
    SetSizePixel( aNewSize );
}

<commit_msg>INTEGRATION: CWS vgbugs07 (1.8.32); FILE MERGED 2007/06/04 13:34:46 vg 1.8.32.1: #i76605# Remove -I .../inc/module hack introduced by hedaburemove01<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: alienwarn.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: hr $ $Date: 2007-06-27 23:09:13 $
 *
 *  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_sfx2.hxx"

#include "alienwarn.hxx"
#include "sfxresid.hxx"
#include <sfx2/sfxuno.hxx>

#include "alienwarn.hrc"
#include "dialog.hrc"

#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_SAVEOPT_HXX
#include <svtools/saveopt.hxx>
#endif

// class SfxAlienWarningDialog -------------------------------------------

SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :

    SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),

    m_aQueryImage   ( this, SfxResId( FI_QUERY ) ),
    m_aInfoText     ( this, SfxResId( FT_INFOTEXT ) ),
    m_aYesBtn       ( this, SfxResId( PB_YES ) ),
    m_aNoBtn        ( this, SfxResId( PB_NO ) ),
    m_aMoreInfoBtn  ( this, SfxResId( PB_MOREINFO ) ),
    m_aOptionLine   ( this, SfxResId( FL_OPTION ) ),
    m_aWarningOffBox( this, SfxResId( CB_WARNING_OFF ) )

{
    FreeResource();

    // set questionmark image
    m_aQueryImage.SetImage( QueryBox::GetStandardImage() );

    // replace formatname
    String sInfoText = m_aInfoText.GetText();
    sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
    m_aInfoText.SetText( sInfoText );

    // load value of "warning off" checkbox from save options
    m_aWarningOffBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_False );

    // set focus to "No" button
    m_aNoBtn.GrabFocus();

    // pb: #i43989# we have no online help for this dialog at the moment
    // -> hide the "more info" button
    m_aMoreInfoBtn.Hide();

    // calculate and set the size of the dialog and its controls
    InitSize();
}

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

SfxAlienWarningDialog::~SfxAlienWarningDialog()
{
    // save value of "warning off" checkbox, if necessary
    SvtSaveOptions aSaveOpt;
    sal_Bool bChecked = !m_aWarningOffBox.IsChecked();
    if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
        aSaveOpt.SetWarnAlienFormat( bChecked );
}

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

void SfxAlienWarningDialog::InitSize()
{
    // if the button text is too wide, then broaden the button
    long nTxtW = m_aMoreInfoBtn.GetTextWidth( m_aMoreInfoBtn.GetText() );
    long nCtrlW = m_aMoreInfoBtn.GetSizePixel().Width();
    if ( nTxtW >= nCtrlW )
    {
        long nDelta = nTxtW - nCtrlW;
        nDelta += 6; // a little more space looks better
        Point aNextPoint = m_aNoBtn.GetPosPixel();
        aNextPoint.X() += m_aNoBtn.GetSizePixel().Width();
        Point aNewPoint = m_aMoreInfoBtn.GetPosPixel();
        aNewPoint.X() -= nDelta;
        if ( aNextPoint.X() >= aNewPoint.X() )
        {
            long nSpace = aNextPoint.X() - aNewPoint.X();
            nSpace += 2;
            nDelta -= nSpace;
            aNewPoint.X() += nSpace;
        }
        Size aNewSize = m_aMoreInfoBtn.GetSizePixel();
        aNewSize.Width() += nDelta;
        m_aMoreInfoBtn.SetPosSizePixel( aNewPoint, aNewSize );
    }

    // text of checkbox to wide -> add new line
    nTxtW = m_aWarningOffBox.GetTextWidth( m_aWarningOffBox.GetText() );
    nCtrlW = m_aWarningOffBox.GetSizePixel().Width();
    if ( nTxtW >= nCtrlW )
    {
        long nTextHeight = m_aWarningOffBox.GetTextHeight();
        Size aNewSize = m_aWarningOffBox.GetSizePixel();
        aNewSize.Height() += nTextHeight;
        m_aWarningOffBox.SetSizePixel( aNewSize );
        aNewSize = GetSizePixel();
        aNewSize.Height() += nTextHeight;
        SetSizePixel( aNewSize );
    }

    // align the size of the information text control (FixedText) to its content
    Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
    long nTxtH = aMinSize.Height();
    long nCtrlH = m_aInfoText.GetSizePixel().Height();
    long nDelta = ( nCtrlH - nTxtH );
    Size aNewSize = m_aInfoText.GetSizePixel();
    aNewSize.Height() -= nDelta;
    m_aInfoText.SetSizePixel( aNewSize );

    // new position for the succeeding windows
    Window* pWins[] =
    {
        &m_aYesBtn, &m_aNoBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOffBox
    };
    Window** pCurrent = pWins;
    for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
    {
        Point aNewPos = (*pCurrent)->GetPosPixel();
        aNewPos.Y() -= nDelta;
        (*pCurrent)->SetPosPixel( aNewPos );
    }

    // new size of the dialog
    aNewSize = GetSizePixel();
    aNewSize.Height() -= nDelta;
    SetSizePixel( aNewSize );
}

<|endoftext|>


<commit_before>// Formatting library for C++
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.

#include "fmt/format-inl.h"

FMT_BEGIN_NAMESPACE
template struct FMT_API internal::basic_data<void>;

// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
int (*instantiate_format_float)(double, int, internal::float_spec,
                                internal::buffer<char>&) =
    internal::format_float;

#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
template FMT_API internal::locale_ref::locale_ref(const std::locale& loc);
template FMT_API std::locale internal::locale_ref::get<std::locale>() const;
#endif

// Explicit instantiations for char.

template FMT_API std::string internal::grouping_impl<char>(locale_ref);
template FMT_API char internal::thousands_sep_impl(locale_ref);
template FMT_API char internal::decimal_point_impl(locale_ref);

template FMT_API void internal::buffer<char>::append(const char*, const char*);

template FMT_API void internal::arg_map<format_context>::init(
    const basic_format_args<format_context>& args);

template FMT_API std::string internal::vformat<char>(
    string_view, basic_format_args<format_context>);

template FMT_API format_context::iterator internal::vformat_to(
    internal::buffer<char>&, string_view, basic_format_args<format_context>);

template FMT_API int internal::format_float(double, int, internal::float_spec,
                                            internal::buffer<char>&);
template FMT_API int internal::format_float(long double, int,
                                            internal::float_spec,
                                            internal::buffer<char>&);

// Explicit instantiations for wchar_t.

template FMT_API std::string internal::grouping_impl<wchar_t>(locale_ref);
template FMT_API wchar_t internal::thousands_sep_impl(locale_ref);
template FMT_API wchar_t internal::decimal_point_impl(locale_ref);

template FMT_API void internal::buffer<wchar_t>::append(const wchar_t*,
                                                        const wchar_t*);

template FMT_API void internal::arg_map<wformat_context>::init(
    const basic_format_args<wformat_context>&);

template FMT_API std::wstring internal::vformat<wchar_t>(
    wstring_view, basic_format_args<wformat_context>);
FMT_END_NAMESPACE
<commit_msg>Instantiate snprintf_float<commit_after>// Formatting library for C++
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.

#include "fmt/format-inl.h"

FMT_BEGIN_NAMESPACE
template struct FMT_API internal::basic_data<void>;

// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
int (*instantiate_format_float)(double, int, internal::float_spec,
                                internal::buffer<char>&) =
    internal::format_float;

#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
template FMT_API internal::locale_ref::locale_ref(const std::locale& loc);
template FMT_API std::locale internal::locale_ref::get<std::locale>() const;
#endif

// Explicit instantiations for char.

template FMT_API std::string internal::grouping_impl<char>(locale_ref);
template FMT_API char internal::thousands_sep_impl(locale_ref);
template FMT_API char internal::decimal_point_impl(locale_ref);

template FMT_API void internal::buffer<char>::append(const char*, const char*);

template FMT_API void internal::arg_map<format_context>::init(
    const basic_format_args<format_context>& args);

template FMT_API std::string internal::vformat<char>(
    string_view, basic_format_args<format_context>);

template FMT_API format_context::iterator internal::vformat_to(
    internal::buffer<char>&, string_view, basic_format_args<format_context>);

template FMT_API int internal::snprintf_float(double, int, internal::float_spec,
                                              internal::buffer<char>&);
template FMT_API int internal::snprintf_float(long double, int,
                                              internal::float_spec,
                                              internal::buffer<char>&);
template FMT_API int internal::format_float(double, int, internal::float_spec,
                                            internal::buffer<char>&);
template FMT_API int internal::format_float(long double, int,
                                            internal::float_spec,
                                            internal::buffer<char>&);

// Explicit instantiations for wchar_t.

template FMT_API std::string internal::grouping_impl<wchar_t>(locale_ref);
template FMT_API wchar_t internal::thousands_sep_impl(locale_ref);
template FMT_API wchar_t internal::decimal_point_impl(locale_ref);

template FMT_API void internal::buffer<wchar_t>::append(const wchar_t*,
                                                        const wchar_t*);

template FMT_API void internal::arg_map<wformat_context>::init(
    const basic_format_args<wformat_context>&);

template FMT_API std::wstring internal::vformat<wchar_t>(
    wstring_view, basic_format_args<wformat_context>);
FMT_END_NAMESPACE
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2012 Thomas Kemmer <tkemmer@computer.org>
 *
 * http://code.google.com/p/stlencoders/
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef STLENCODERS_LOOKUP_HPP
#define STLENCODERS_LOOKUP_HPP

namespace stlencoders {
    template<template<char> class LUT, class T>
    inline const T& lookup(char c, const T& def)
    {
        static const T table[256] = {
            LUT<'\000'>::value, LUT<'\001'>::value, LUT<'\002'>::value, LUT<'\003'>::value,
            LUT<'\004'>::value, LUT<'\005'>::value, LUT<'\006'>::value, LUT<'\007'>::value,
            LUT<'\010'>::value, LUT<'\011'>::value, LUT<'\012'>::value, LUT<'\013'>::value,
            LUT<'\014'>::value, LUT<'\015'>::value, LUT<'\016'>::value, LUT<'\017'>::value,
            LUT<'\020'>::value, LUT<'\021'>::value, LUT<'\022'>::value, LUT<'\023'>::value,
            LUT<'\024'>::value, LUT<'\025'>::value, LUT<'\026'>::value, LUT<'\027'>::value,
            LUT<'\030'>::value, LUT<'\031'>::value, LUT<'\032'>::value, LUT<'\033'>::value,
            LUT<'\034'>::value, LUT<'\035'>::value, LUT<'\036'>::value, LUT<'\037'>::value,
            LUT<'\040'>::value, LUT<'\041'>::value, LUT<'\042'>::value, LUT<'\043'>::value,
            LUT<'\044'>::value, LUT<'\045'>::value, LUT<'\046'>::value, LUT<'\047'>::value,
            LUT<'\050'>::value, LUT<'\051'>::value, LUT<'\052'>::value, LUT<'\053'>::value,
            LUT<'\054'>::value, LUT<'\055'>::value, LUT<'\056'>::value, LUT<'\057'>::value,
            LUT<'\060'>::value, LUT<'\061'>::value, LUT<'\062'>::value, LUT<'\063'>::value,
            LUT<'\064'>::value, LUT<'\065'>::value, LUT<'\066'>::value, LUT<'\067'>::value,
            LUT<'\070'>::value, LUT<'\071'>::value, LUT<'\072'>::value, LUT<'\073'>::value,
            LUT<'\074'>::value, LUT<'\075'>::value, LUT<'\076'>::value, LUT<'\077'>::value,
            LUT<'\100'>::value, LUT<'\101'>::value, LUT<'\102'>::value, LUT<'\103'>::value,
            LUT<'\104'>::value, LUT<'\105'>::value, LUT<'\106'>::value, LUT<'\107'>::value,
            LUT<'\110'>::value, LUT<'\111'>::value, LUT<'\112'>::value, LUT<'\113'>::value,
            LUT<'\114'>::value, LUT<'\115'>::value, LUT<'\116'>::value, LUT<'\117'>::value,
            LUT<'\120'>::value, LUT<'\121'>::value, LUT<'\122'>::value, LUT<'\123'>::value,
            LUT<'\124'>::value, LUT<'\125'>::value, LUT<'\126'>::value, LUT<'\127'>::value,
            LUT<'\130'>::value, LUT<'\131'>::value, LUT<'\132'>::value, LUT<'\133'>::value,
            LUT<'\134'>::value, LUT<'\135'>::value, LUT<'\136'>::value, LUT<'\137'>::value,
            LUT<'\140'>::value, LUT<'\141'>::value, LUT<'\142'>::value, LUT<'\143'>::value,
            LUT<'\144'>::value, LUT<'\145'>::value, LUT<'\146'>::value, LUT<'\147'>::value,
            LUT<'\150'>::value, LUT<'\151'>::value, LUT<'\152'>::value, LUT<'\153'>::value,
            LUT<'\154'>::value, LUT<'\155'>::value, LUT<'\156'>::value, LUT<'\157'>::value,
            LUT<'\160'>::value, LUT<'\161'>::value, LUT<'\162'>::value, LUT<'\163'>::value,
            LUT<'\164'>::value, LUT<'\165'>::value, LUT<'\166'>::value, LUT<'\167'>::value,
            LUT<'\170'>::value, LUT<'\171'>::value, LUT<'\172'>::value, LUT<'\173'>::value,
            LUT<'\174'>::value, LUT<'\175'>::value, LUT<'\176'>::value, LUT<'\177'>::value,
            LUT<'\200'>::value, LUT<'\201'>::value, LUT<'\202'>::value, LUT<'\203'>::value,
            LUT<'\204'>::value, LUT<'\205'>::value, LUT<'\206'>::value, LUT<'\207'>::value,
            LUT<'\210'>::value, LUT<'\211'>::value, LUT<'\212'>::value, LUT<'\213'>::value,
            LUT<'\214'>::value, LUT<'\215'>::value, LUT<'\216'>::value, LUT<'\217'>::value,
            LUT<'\220'>::value, LUT<'\221'>::value, LUT<'\222'>::value, LUT<'\223'>::value,
            LUT<'\224'>::value, LUT<'\225'>::value, LUT<'\226'>::value, LUT<'\227'>::value,
            LUT<'\230'>::value, LUT<'\231'>::value, LUT<'\232'>::value, LUT<'\233'>::value,
            LUT<'\234'>::value, LUT<'\235'>::value, LUT<'\236'>::value, LUT<'\237'>::value,
            LUT<'\240'>::value, LUT<'\241'>::value, LUT<'\242'>::value, LUT<'\243'>::value,
            LUT<'\244'>::value, LUT<'\245'>::value, LUT<'\246'>::value, LUT<'\247'>::value,
            LUT<'\250'>::value, LUT<'\251'>::value, LUT<'\252'>::value, LUT<'\253'>::value,
            LUT<'\254'>::value, LUT<'\255'>::value, LUT<'\256'>::value, LUT<'\257'>::value,
            LUT<'\260'>::value, LUT<'\261'>::value, LUT<'\262'>::value, LUT<'\263'>::value,
            LUT<'\264'>::value, LUT<'\265'>::value, LUT<'\266'>::value, LUT<'\267'>::value,
            LUT<'\270'>::value, LUT<'\271'>::value, LUT<'\272'>::value, LUT<'\273'>::value,
            LUT<'\274'>::value, LUT<'\275'>::value, LUT<'\276'>::value, LUT<'\277'>::value,
            LUT<'\300'>::value, LUT<'\301'>::value, LUT<'\302'>::value, LUT<'\303'>::value,
            LUT<'\304'>::value, LUT<'\305'>::value, LUT<'\306'>::value, LUT<'\307'>::value,
            LUT<'\310'>::value, LUT<'\311'>::value, LUT<'\312'>::value, LUT<'\313'>::value,
            LUT<'\314'>::value, LUT<'\315'>::value, LUT<'\316'>::value, LUT<'\317'>::value,
            LUT<'\320'>::value, LUT<'\321'>::value, LUT<'\322'>::value, LUT<'\323'>::value,
            LUT<'\324'>::value, LUT<'\325'>::value, LUT<'\326'>::value, LUT<'\327'>::value,
            LUT<'\330'>::value, LUT<'\331'>::value, LUT<'\332'>::value, LUT<'\333'>::value,
            LUT<'\334'>::value, LUT<'\335'>::value, LUT<'\336'>::value, LUT<'\337'>::value,
            LUT<'\340'>::value, LUT<'\341'>::value, LUT<'\342'>::value, LUT<'\343'>::value,
            LUT<'\344'>::value, LUT<'\345'>::value, LUT<'\346'>::value, LUT<'\347'>::value,
            LUT<'\350'>::value, LUT<'\351'>::value, LUT<'\352'>::value, LUT<'\353'>::value,
            LUT<'\354'>::value, LUT<'\355'>::value, LUT<'\356'>::value, LUT<'\357'>::value,
            LUT<'\360'>::value, LUT<'\361'>::value, LUT<'\362'>::value, LUT<'\363'>::value,
            LUT<'\364'>::value, LUT<'\365'>::value, LUT<'\366'>::value, LUT<'\367'>::value,
            LUT<'\370'>::value, LUT<'\371'>::value, LUT<'\372'>::value, LUT<'\373'>::value,
            LUT<'\374'>::value, LUT<'\375'>::value, LUT<'\376'>::value, LUT<'\377'>::value
        };

        if (static_cast<unsigned char>(c) < 256)
            return table[static_cast<unsigned char>(c)];
        else
            return def;
    }
}

#endif
<commit_msg>fix warning<commit_after>/*
 * Copyright (c) 2012 Thomas Kemmer <tkemmer@computer.org>
 *
 * http://code.google.com/p/stlencoders/
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef STLENCODERS_LOOKUP_HPP
#define STLENCODERS_LOOKUP_HPP

namespace stlencoders {
    template<template<char> class LUT, class T>
    inline const T& lookup(char c, const T& def)
    {
        static const T table[256] = {
            LUT<'\000'>::value, LUT<'\001'>::value, LUT<'\002'>::value, LUT<'\003'>::value,
            LUT<'\004'>::value, LUT<'\005'>::value, LUT<'\006'>::value, LUT<'\007'>::value,
            LUT<'\010'>::value, LUT<'\011'>::value, LUT<'\012'>::value, LUT<'\013'>::value,
            LUT<'\014'>::value, LUT<'\015'>::value, LUT<'\016'>::value, LUT<'\017'>::value,
            LUT<'\020'>::value, LUT<'\021'>::value, LUT<'\022'>::value, LUT<'\023'>::value,
            LUT<'\024'>::value, LUT<'\025'>::value, LUT<'\026'>::value, LUT<'\027'>::value,
            LUT<'\030'>::value, LUT<'\031'>::value, LUT<'\032'>::value, LUT<'\033'>::value,
            LUT<'\034'>::value, LUT<'\035'>::value, LUT<'\036'>::value, LUT<'\037'>::value,
            LUT<'\040'>::value, LUT<'\041'>::value, LUT<'\042'>::value, LUT<'\043'>::value,
            LUT<'\044'>::value, LUT<'\045'>::value, LUT<'\046'>::value, LUT<'\047'>::value,
            LUT<'\050'>::value, LUT<'\051'>::value, LUT<'\052'>::value, LUT<'\053'>::value,
            LUT<'\054'>::value, LUT<'\055'>::value, LUT<'\056'>::value, LUT<'\057'>::value,
            LUT<'\060'>::value, LUT<'\061'>::value, LUT<'\062'>::value, LUT<'\063'>::value,
            LUT<'\064'>::value, LUT<'\065'>::value, LUT<'\066'>::value, LUT<'\067'>::value,
            LUT<'\070'>::value, LUT<'\071'>::value, LUT<'\072'>::value, LUT<'\073'>::value,
            LUT<'\074'>::value, LUT<'\075'>::value, LUT<'\076'>::value, LUT<'\077'>::value,
            LUT<'\100'>::value, LUT<'\101'>::value, LUT<'\102'>::value, LUT<'\103'>::value,
            LUT<'\104'>::value, LUT<'\105'>::value, LUT<'\106'>::value, LUT<'\107'>::value,
            LUT<'\110'>::value, LUT<'\111'>::value, LUT<'\112'>::value, LUT<'\113'>::value,
            LUT<'\114'>::value, LUT<'\115'>::value, LUT<'\116'>::value, LUT<'\117'>::value,
            LUT<'\120'>::value, LUT<'\121'>::value, LUT<'\122'>::value, LUT<'\123'>::value,
            LUT<'\124'>::value, LUT<'\125'>::value, LUT<'\126'>::value, LUT<'\127'>::value,
            LUT<'\130'>::value, LUT<'\131'>::value, LUT<'\132'>::value, LUT<'\133'>::value,
            LUT<'\134'>::value, LUT<'\135'>::value, LUT<'\136'>::value, LUT<'\137'>::value,
            LUT<'\140'>::value, LUT<'\141'>::value, LUT<'\142'>::value, LUT<'\143'>::value,
            LUT<'\144'>::value, LUT<'\145'>::value, LUT<'\146'>::value, LUT<'\147'>::value,
            LUT<'\150'>::value, LUT<'\151'>::value, LUT<'\152'>::value, LUT<'\153'>::value,
            LUT<'\154'>::value, LUT<'\155'>::value, LUT<'\156'>::value, LUT<'\157'>::value,
            LUT<'\160'>::value, LUT<'\161'>::value, LUT<'\162'>::value, LUT<'\163'>::value,
            LUT<'\164'>::value, LUT<'\165'>::value, LUT<'\166'>::value, LUT<'\167'>::value,
            LUT<'\170'>::value, LUT<'\171'>::value, LUT<'\172'>::value, LUT<'\173'>::value,
            LUT<'\174'>::value, LUT<'\175'>::value, LUT<'\176'>::value, LUT<'\177'>::value,
            LUT<'\200'>::value, LUT<'\201'>::value, LUT<'\202'>::value, LUT<'\203'>::value,
            LUT<'\204'>::value, LUT<'\205'>::value, LUT<'\206'>::value, LUT<'\207'>::value,
            LUT<'\210'>::value, LUT<'\211'>::value, LUT<'\212'>::value, LUT<'\213'>::value,
            LUT<'\214'>::value, LUT<'\215'>::value, LUT<'\216'>::value, LUT<'\217'>::value,
            LUT<'\220'>::value, LUT<'\221'>::value, LUT<'\222'>::value, LUT<'\223'>::value,
            LUT<'\224'>::value, LUT<'\225'>::value, LUT<'\226'>::value, LUT<'\227'>::value,
            LUT<'\230'>::value, LUT<'\231'>::value, LUT<'\232'>::value, LUT<'\233'>::value,
            LUT<'\234'>::value, LUT<'\235'>::value, LUT<'\236'>::value, LUT<'\237'>::value,
            LUT<'\240'>::value, LUT<'\241'>::value, LUT<'\242'>::value, LUT<'\243'>::value,
            LUT<'\244'>::value, LUT<'\245'>::value, LUT<'\246'>::value, LUT<'\247'>::value,
            LUT<'\250'>::value, LUT<'\251'>::value, LUT<'\252'>::value, LUT<'\253'>::value,
            LUT<'\254'>::value, LUT<'\255'>::value, LUT<'\256'>::value, LUT<'\257'>::value,
            LUT<'\260'>::value, LUT<'\261'>::value, LUT<'\262'>::value, LUT<'\263'>::value,
            LUT<'\264'>::value, LUT<'\265'>::value, LUT<'\266'>::value, LUT<'\267'>::value,
            LUT<'\270'>::value, LUT<'\271'>::value, LUT<'\272'>::value, LUT<'\273'>::value,
            LUT<'\274'>::value, LUT<'\275'>::value, LUT<'\276'>::value, LUT<'\277'>::value,
            LUT<'\300'>::value, LUT<'\301'>::value, LUT<'\302'>::value, LUT<'\303'>::value,
            LUT<'\304'>::value, LUT<'\305'>::value, LUT<'\306'>::value, LUT<'\307'>::value,
            LUT<'\310'>::value, LUT<'\311'>::value, LUT<'\312'>::value, LUT<'\313'>::value,
            LUT<'\314'>::value, LUT<'\315'>::value, LUT<'\316'>::value, LUT<'\317'>::value,
            LUT<'\320'>::value, LUT<'\321'>::value, LUT<'\322'>::value, LUT<'\323'>::value,
            LUT<'\324'>::value, LUT<'\325'>::value, LUT<'\326'>::value, LUT<'\327'>::value,
            LUT<'\330'>::value, LUT<'\331'>::value, LUT<'\332'>::value, LUT<'\333'>::value,
            LUT<'\334'>::value, LUT<'\335'>::value, LUT<'\336'>::value, LUT<'\337'>::value,
            LUT<'\340'>::value, LUT<'\341'>::value, LUT<'\342'>::value, LUT<'\343'>::value,
            LUT<'\344'>::value, LUT<'\345'>::value, LUT<'\346'>::value, LUT<'\347'>::value,
            LUT<'\350'>::value, LUT<'\351'>::value, LUT<'\352'>::value, LUT<'\353'>::value,
            LUT<'\354'>::value, LUT<'\355'>::value, LUT<'\356'>::value, LUT<'\357'>::value,
            LUT<'\360'>::value, LUT<'\361'>::value, LUT<'\362'>::value, LUT<'\363'>::value,
            LUT<'\364'>::value, LUT<'\365'>::value, LUT<'\366'>::value, LUT<'\367'>::value,
            LUT<'\370'>::value, LUT<'\371'>::value, LUT<'\372'>::value, LUT<'\373'>::value,
            LUT<'\374'>::value, LUT<'\375'>::value, LUT<'\376'>::value, LUT<'\377'>::value
        };

        if (static_cast<unsigned>(c) < sizeof(table))
            return table[static_cast<unsigned>(c)];
        else
            return def;
    }
}

#endif
<|endoftext|>


<commit_before>#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClearColor(0.2f, 0.3f, 0.4f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}
<commit_msg>basic input<commit_after>#include <GLFW/glfw3.h>
#include <cstdlib>
#include <iostream>

const int WIDTH = 1280;
const int HEIGHT = 720;

float blueOffset = 0;
float greenOffset = 0;

bool keys[512];

void processInput();

int main(int argc, char* argv[])
{
    if (!glfwInit()) {
        return EXIT_FAILURE;
    }

    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
    GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Fuzzy", nullptr, nullptr);
    if (!window) {
        glfwTerminate();
        return EXIT_FAILURE;
    }

    GLFWmonitor* monitor = glfwGetPrimaryMonitor();
    const GLFWvidmode* vidmode = glfwGetVideoMode(monitor);

    glfwSetWindowPos(window, (vidmode->width - WIDTH) / 2, (vidmode->height - HEIGHT) / 2);

    glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods) {
        if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
            glfwSetWindowShouldClose(window, GLFW_TRUE);
        }
        if (action == GLFW_PRESS) {
            keys[key] = true;
        } else if (action == GLFW_RELEASE) {
            keys[key] = false;
        }
    });

    glfwMakeContextCurrent(window);

    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();

        processInput();

        glClearColor(0.5f, greenOffset, blueOffset, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        glfwSwapBuffers(window);
    }

    glfwTerminate();
    return EXIT_SUCCESS;
}

void processInput() {
    float step = 0.0005f;
    if (keys[GLFW_KEY_UP] == GLFW_PRESS) {
        if (blueOffset < 1.0f) {
            blueOffset += step;
        }
    }
    if (keys[GLFW_KEY_DOWN] == GLFW_PRESS) {
        if (blueOffset > 0.f) {
            blueOffset -= step;
        }
    }
    if (keys[GLFW_KEY_RIGHT] == GLFW_PRESS) {
        if (greenOffset < 1.0f) {
            greenOffset += step;
        }
    }
    if (keys[GLFW_KEY_LEFT] == GLFW_PRESS) {
        if (greenOffset > 0.f) {
            greenOffset -= step;
        }
    }
}
<|endoftext|>


<commit_before>#include <stan/math/rev/mat.hpp>
#include <boost/random.hpp>
#include <stan/math/prim/scal/prob/lognormal_rng.hpp>
#include <gtest/gtest.h>
// very small michaelis menten example
#include <test/unit/math/rev/arr/functor/coupled_mm.hpp>
#include <test/unit/util.hpp>
#include <vector>

// test which triggers the too much work exception from odeint
TEST(StanOde_tooMuchWork_test, cvodes_coupled_mm) {
  coupled_mm_ode_fun f_;

  boost::ecuyer1988 rng;

  // initial value and parameters from model definition

  double t0 = 0;

  std::vector<double> ts_long;
  ts_long.push_back(1E10);

  std::vector<double> ts_short;
  ts_short.push_back(1);

  std::vector<double> data;

  std::vector<int> data_int;

  for(std::size_t i = 0; i < 1000; i++) {
    stan::math::start_nested();

    std::vector<stan::math::var> theta_v(4);

    theta_v[0] = stan::math::lognormal_rng(1, 2, rng);
    theta_v[1] = stan::math::lognormal_rng(-1, 2, rng);
    theta_v[2] = stan::math::lognormal_rng(-1, 2, rng);
    theta_v[3] = stan::math::lognormal_rng(-2, 2, rng);

    std::vector<stan::math::var> y0_v(2);
    y0_v[0] = stan::math::lognormal_rng(5, 2, rng);
    y0_v[1] = stan::math::lognormal_rng(-1, 2, rng);

    std::vector<std::vector<stan::math::var> > res = stan::math::integrate_ode_bdf(f_, y0_v, t0, ts_long, theta_v, data,
                                     data_int, 0, 1E-10, 1E-10, 10000);

    stan::math::grad(res[0][0].vi_);

    stan::math::recover_memory_nested();
 }
}
<commit_msg>[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/stable/2017-11-14)<commit_after>#include <stan/math/rev/mat.hpp>
#include <boost/random.hpp>
#include <stan/math/prim/scal/prob/lognormal_rng.hpp>
#include <gtest/gtest.h>
// very small michaelis menten example
#include <test/unit/math/rev/arr/functor/coupled_mm.hpp>
#include <test/unit/util.hpp>
#include <vector>

// test which triggers the too much work exception from odeint
TEST(StanOde_tooMuchWork_test, cvodes_coupled_mm) {
  coupled_mm_ode_fun f_;

  boost::ecuyer1988 rng;

  // initial value and parameters from model definition

  double t0 = 0;

  std::vector<double> ts_long;
  ts_long.push_back(1E10);

  std::vector<double> ts_short;
  ts_short.push_back(1);

  std::vector<double> data;

  std::vector<int> data_int;

  for (std::size_t i = 0; i < 1000; i++) {
    stan::math::start_nested();

    std::vector<stan::math::var> theta_v(4);

    theta_v[0] = stan::math::lognormal_rng(1, 2, rng);
    theta_v[1] = stan::math::lognormal_rng(-1, 2, rng);
    theta_v[2] = stan::math::lognormal_rng(-1, 2, rng);
    theta_v[3] = stan::math::lognormal_rng(-2, 2, rng);

    std::vector<stan::math::var> y0_v(2);
    y0_v[0] = stan::math::lognormal_rng(5, 2, rng);
    y0_v[1] = stan::math::lognormal_rng(-1, 2, rng);

    std::vector<std::vector<stan::math::var> > res
        = stan::math::integrate_ode_bdf(f_, y0_v, t0, ts_long, theta_v, data,
                                        data_int, 0, 1E-10, 1E-10, 10000);

    stan::math::grad(res[0][0].vi_);

    stan::math::recover_memory_nested();
  }
}
<|endoftext|>