<commit_before>#pragma once
#include <type_traits>
#include <std/experimental/tagged.hpp>

namespace named_types {

// String literals, GNU Extension only
#ifdef __GNUG__
template <typename T, T ... chars> class string_literal {
  const char data_[sizeof ... (chars) + 1u];
  const size_t size_;
 public:
  constexpr string_literal() : data_ {chars..., '\0'}, size_(sizeof ... (chars)) {}
  constexpr char const* str() const { return data_; }
  constexpr size_t size() const { return size_; }
  constexpr char operator[] (size_t index) const { return data_[index]; }
};
#endif  // __GNUG__

// Traits for compile time name extraction

template<typename T> class has_user_defined_name {
  template <typename TT> static auto test(int) -> decltype(TT::classname);
  template <typename TT> static auto test(int) -> decltype(TT::name);
  template <typename TT> static auto test(int) -> decltype(TT::classname());
  template <typename TT> static auto test(int) -> decltype(TT::name());
  template <typename TT> static auto test(...) -> void;
 public:
  static constexpr bool value = std::is_same<decltype(test<T>(0)),char const *>::value;
};

template<typename T> class constexpr_type_name {
  template <typename TT> static inline constexpr auto extract(int) -> decltype(TT::classname) { return TT::classname; }
  template <typename TT> static inline constexpr auto extract(int) -> decltype(TT::name) { return TT::name; }
  template <typename TT> static inline constexpr auto extract(int) -> decltype(TT::classname()) { return TT::classname(); }
  template <typename TT> static inline constexpr auto extract(int) -> decltype(TT::name()) { return TT::name(); }
 public:
  static constexpr char const* value = extract<T>();
};

// Name extractors specified to work with string literals
#ifdef __GNUG__
template<typename T, T... chars> class has_user_defined_name<string_literal<T,chars...>> {
 public:
  static constexpr bool value = true;
};

template<typename T, T... chars> class constexpr_type_name <string_literal<T,chars...>> {
  static const string_literal<T,chars...> literal_value;
 public:
  static constexpr char const* value = literal_value.str();
};
template<typename T, T... chars> const string_literal<T,chars...> constexpr_type_name<string_literal<T,chars...>>::literal_value {};
#endif  // __GNUG__

// Private types

template <class Tag, typename Value> class __attribute_const_reference_holder;
template <class Tag, typename Value> class __attribute_reference_holder;
template <class Tag, typename Value> class __attribute_value_holder;

// Tag, shared by every one

template <class Tag> struct named_tag;
template <class Tag, typename Value> class named_attribute_holder;

// Specific types : named_tuple

template <class...Types> struct named_tuple;
template <class T> struct __ntuple_tag_spec {};
template <class Spec, class Arg> struct __ntuple_tag_spec<Arg(Spec)> { using type = typename named_tag<Spec>::type; };
template <class T> struct __ntuple_tag_elem {};
template <class Spec, class Arg> struct __ntuple_tag_elem<Arg(Spec)> { using type = Arg; };

// Tag

template <class Tag> struct named_tag : std::tag::basic_tag {
 private:
  template <typename T> struct unnested_ { using type = named_tag; };
  template <typename T> struct unnested_<named_tag<T>> { using type = named_tag<T>; };
  template <typename T> struct unnested_value_ { using type = T; };
  template <typename T> struct unnested_value_<named_tag<T>> { using type = T; };

 public:
  using type = typename unnested_<Tag>::type;
  using value_type = typename unnested_value_<Tag>::type;
  constexpr named_tag() = default;

  // Attribute holder generation

  template <typename T>
  __attribute_const_reference_holder<type, T>
  operator=(T const& value)
  { return __attribute_const_reference_holder<type,T>(value); }

  template <typename T>
  __attribute_reference_holder<type, T>
  operator=(T& value)
  { return __attribute_reference_holder<type,T>(value); }

  template <typename T>
  __attribute_value_holder<type, T>
  operator=(T&& value)
  { return __attribute_value_holder<type,T>(std::move(value)); }

  // Specific behavior : named_tuple

  template <typename...Types>
  inline constexpr typename named_tuple<Types...>::template type_at<type>::raw_type const&
  operator() (named_tuple<Types...> const& input) const
  { return std::get<type>(input); }

  template <typename...Types>
  inline constexpr typename named_tuple<Types...>::template type_at<type>::raw_type &
  operator() (named_tuple<Types...> & input) const
  { return std::get<type>(input); }

  template <typename...Types>
  inline constexpr typename named_tuple<Types...>::template type_at<type>::raw_type &&
  operator() (named_tuple<Types...>&& input) const
  { return std::move(std::get<type>(std::forward<named_tuple<Types...>>(input))); }
};

// Attribute holders

template <class Tag, typename Value> class __attribute_const_reference_holder {
  Value const& value_;
 public:
  using tag_type = Tag;
  using value_type = Value;
  __attribute_const_reference_holder(Value const& input) : value_(input) {}
  __attribute_const_reference_holder(__attribute_const_reference_holder const&) = delete;
  __attribute_const_reference_holder(__attribute_const_reference_holder&&) = default;
  __attribute_const_reference_holder& operator=(__attribute_const_reference_holder const&) = delete;
  __attribute_const_reference_holder& operator=(__attribute_const_reference_holder&&) = default;
  Value const& get() && { return value_; }
};

template <class Tag, typename Value> class __attribute_reference_holder {
  Value& value_;
 public:
  using tag_type = Tag;
  using value_type = Value;
  __attribute_reference_holder(Value& input) : value_(input) {}
  __attribute_reference_holder(__attribute_reference_holder const&) = delete;
  __attribute_reference_holder(__attribute_reference_holder&&) = default;
  __attribute_reference_holder& operator=(__attribute_reference_holder const&) = delete;
  __attribute_reference_holder& operator=(__attribute_reference_holder&&) = default;
  Value& get() && { return value_; }
};

template <class Tag, typename Value> class __attribute_value_holder {
  Value&& value_;
 public:
  using tag_type = Tag;
  using value_type = Value;
  __attribute_value_holder (Value&& input) : value_(std::move(input)) {}
  __attribute_value_holder(__attribute_value_holder const&) = delete;
  __attribute_value_holder(__attribute_value_holder&&) = default;
  __attribute_value_holder& operator=(__attribute_value_holder const&) = delete;
  __attribute_value_holder& operator=(__attribute_value_holder&&) = default;
  Value&& get() && { return std::move(value_); }
};

}  // namespace named_types
<commit_msg>Making string data more static.<commit_after>#pragma once
#include <type_traits>
#include <std/experimental/tagged.hpp>

namespace named_types {

// String literals, GNU Extension only
#ifdef __GNUG__
template <class T, T ... chars> struct string_literal {
  static const char data[sizeof ... (chars) + 1u];
  static const size_t data_size = sizeof ... (chars);

  constexpr string_literal() = default;
  constexpr char const* str() const { return data; }
  constexpr size_t size() const { return sizeof ... (chars); }
  constexpr char operator[] (size_t index) const { return data[index]; }
};
template <class T, T ... chars> const char string_literal<T,chars...>::data[sizeof ... (chars) + 1u] = {chars..., '\0'};
#endif  // __GNUG__

// Traits for compile time name extraction

template <class T> class has_user_defined_name {
  template <class TT> static auto test(int) -> decltype(TT::classname);
  template <class TT> static auto test(int) -> decltype(TT::name);
  template <class TT> static auto test(int) -> decltype(TT::classname());
  template <class TT> static auto test(int) -> decltype(TT::name());
  template <class TT> static auto test(...) -> void;
 public:
  static constexpr bool value = std::is_same<decltype(test<T>(0)),char const *>::value;
};

template<class T> class constexpr_type_name {
  template <class TT> static inline constexpr auto extract(int) -> decltype(TT::classname) { return TT::classname; }
  template <class TT> static inline constexpr auto extract(int) -> decltype(TT::name) { return TT::name; }
  template <class TT> static inline constexpr auto extract(int) -> decltype(TT::classname()) { return TT::classname(); }
  template <class TT> static inline constexpr auto extract(int) -> decltype(TT::name()) { return TT::name(); }
 public:
  static constexpr char const* value = extract<T>();
};

// Name extractors specified to work with string literals
#ifdef __GNUG__
template<class T, T... chars> class has_user_defined_name<string_literal<T,chars...>> {
 public:
  static constexpr bool value = true;
};

template<class T, T... chars> class constexpr_type_name <string_literal<T,chars...>> {
 public:
  static constexpr char const* value = string_literal<T,chars...>::data;
};
#endif  // __GNUG__

// Private types

template <class Tag, typename Value> class __attribute_const_reference_holder;
template <class Tag, typename Value> class __attribute_reference_holder;
template <class Tag, typename Value> class __attribute_value_holder;

// Tag, shared by every one

template <class Tag> struct named_tag;
template <class Tag, typename Value> class named_attribute_holder;

// Specific types : named_tuple

template <class...Types> struct named_tuple;
template <class T> struct __ntuple_tag_spec {};
template <class Spec, class Arg> struct __ntuple_tag_spec<Arg(Spec)> { using type = typename named_tag<Spec>::type; };
template <class T> struct __ntuple_tag_elem {};
template <class Spec, class Arg> struct __ntuple_tag_elem<Arg(Spec)> { using type = Arg; };

// Tag

template <class Tag> struct named_tag : std::tag::basic_tag {
 private:
  template <typename T> struct unnested_ { using type = named_tag; };
  template <typename T> struct unnested_<named_tag<T>> { using type = named_tag<T>; };
  template <typename T> struct unnested_value_ { using type = T; };
  template <typename T> struct unnested_value_<named_tag<T>> { using type = T; };

 public:
  using type = typename unnested_<Tag>::type;
  using value_type = typename unnested_value_<Tag>::type;
  constexpr named_tag() = default;

  // Attribute holder generation

  template <typename T>
  __attribute_const_reference_holder<type, T>
  operator=(T const& value)
  { return __attribute_const_reference_holder<type,T>(value); }

  template <typename T>
  __attribute_reference_holder<type, T>
  operator=(T& value)
  { return __attribute_reference_holder<type,T>(value); }

  template <typename T>
  __attribute_value_holder<type, T>
  operator=(T&& value)
  { return __attribute_value_holder<type,T>(std::move(value)); }

  // Specific behavior : named_tuple

  template <typename...Types>
  inline constexpr typename named_tuple<Types...>::template type_at<type>::raw_type const&
  operator() (named_tuple<Types...> const& input) const
  { return std::get<type>(input); }

  template <typename...Types>
  inline constexpr typename named_tuple<Types...>::template type_at<type>::raw_type &
  operator() (named_tuple<Types...> & input) const
  { return std::get<type>(input); }

  template <typename...Types>
  inline constexpr typename named_tuple<Types...>::template type_at<type>::raw_type &&
  operator() (named_tuple<Types...>&& input) const
  { return std::move(std::get<type>(std::forward<named_tuple<Types...>>(input))); }
};

// Attribute holders

template <class Tag, typename Value> class __attribute_const_reference_holder {
  Value const& value_;
 public:
  using tag_type = Tag;
  using value_type = Value;
  __attribute_const_reference_holder(Value const& input) : value_(input) {}
  __attribute_const_reference_holder(__attribute_const_reference_holder const&) = delete;
  __attribute_const_reference_holder(__attribute_const_reference_holder&&) = default;
  __attribute_const_reference_holder& operator=(__attribute_const_reference_holder const&) = delete;
  __attribute_const_reference_holder& operator=(__attribute_const_reference_holder&&) = default;
  Value const& get() && { return value_; }
};

template <class Tag, typename Value> class __attribute_reference_holder {
  Value& value_;
 public:
  using tag_type = Tag;
  using value_type = Value;
  __attribute_reference_holder(Value& input) : value_(input) {}
  __attribute_reference_holder(__attribute_reference_holder const&) = delete;
  __attribute_reference_holder(__attribute_reference_holder&&) = default;
  __attribute_reference_holder& operator=(__attribute_reference_holder const&) = delete;
  __attribute_reference_holder& operator=(__attribute_reference_holder&&) = default;
  Value& get() && { return value_; }
};

template <class Tag, typename Value> class __attribute_value_holder {
  Value&& value_;
 public:
  using tag_type = Tag;
  using value_type = Value;
  __attribute_value_holder (Value&& input) : value_(std::move(input)) {}
  __attribute_value_holder(__attribute_value_holder const&) = delete;
  __attribute_value_holder(__attribute_value_holder&&) = default;
  __attribute_value_holder& operator=(__attribute_value_holder const&) = delete;
  __attribute_value_holder& operator=(__attribute_value_holder&&) = default;
  Value&& get() && { return std::move(value_); }
};

}  // namespace named_types
<|endoftext|>


<commit_before>/**
 * @file llexternaleditor.cpp
 * @brief A convenient class to run external editor.
 *
 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"
#include "llexternaleditor.h"

#include "lltrans.h"
#include "llui.h"
#include "llprocess.h"
#include "llsdutil.h"
#include <boost/foreach.hpp>

// static
const std::string LLExternalEditor::sFilenameMarker = "%s";

// static
const std::string LLExternalEditor::sSetting = "ExternalEditor";

LLExternalEditor::EErrorCode LLExternalEditor::setCommand(const std::string& env_var, const std::string& override)
{
	std::string cmd = findCommand(env_var, override);
	if (cmd.empty())
	{
		llwarns << "Editor command is empty or not set" << llendl;
// <FS:CR> FIRE-10320 If no editor is set, fallback on the system open handler
		//return EC_NOT_SPECIFIED;
		llwarns << "Falling back on generic open handler" << llendl;
#ifdef WIN32
		cmd = findCommand("", "%comspec% /C START \"%s\"")
#endif
#ifdef DARWIN
		cmd = findCommand("", "/usr/bin/open \"%s\"")
#endif
#ifdef LINUX
		// xdg-open might not actually be installed, but it's out best shot
		cmd = findCommand("", "/usr/bin/xdg-open \"%s\"")
#endif
		if (cmd.empty())
		{
			return EC_NOT_SPECIFIED;
		}
// </FS:CR>
	}

	string_vec_t tokens;
	tokenize(tokens, cmd);

	// Check executable for existence.
	std::string bin_path = tokens[0];
	if (!LLFile::isfile(bin_path))
	{
		llwarns << "Editor binary [" << bin_path << "] not found" << llendl;
		return EC_BINARY_NOT_FOUND;
	}

	// Save command.
	mProcessParams = LLProcess::Params();
	mProcessParams.executable = bin_path;
	for (size_t i = 1; i < tokens.size(); ++i)
	{
		mProcessParams.args.add(tokens[i]);
	}

	// Add the filename marker if missing.
	if (cmd.find(sFilenameMarker) == std::string::npos)
	{
		mProcessParams.args.add(sFilenameMarker);
		llinfos << "Adding the filename marker (" << sFilenameMarker << ")" << llendl;
	}

	llinfos << "Setting command [" << mProcessParams << "]" << llendl;

	return EC_SUCCESS;
}

LLExternalEditor::EErrorCode LLExternalEditor::run(const std::string& file_path)
{
	if (std::string(mProcessParams.executable).empty() || mProcessParams.args.empty())
	{
		llwarns << "Editor command not set" << llendl;
		return EC_NOT_SPECIFIED;
	}

	// Copy params block so we can replace sFilenameMarker
	LLProcess::Params params;
	params.executable = mProcessParams.executable;

	// Substitute the filename marker in the command with the actual passed file name.
	BOOST_FOREACH(const std::string& arg, mProcessParams.args)
	{
		std::string fixed(arg);
		LLStringUtil::replaceString(fixed, sFilenameMarker, file_path);
		params.args.add(fixed);
	}

	// Run the editor. Prevent killing the process in destructor.
	params.autokill = false;
	return LLProcess::create(params) ? EC_SUCCESS : EC_FAILED_TO_RUN;
}

// static
std::string LLExternalEditor::getErrorMessage(EErrorCode code)
{
	switch (code)
	{
	case EC_SUCCESS: 			return LLTrans::getString("ok");
	case EC_NOT_SPECIFIED: 		return LLTrans::getString("ExternalEditorNotSet");
	case EC_PARSE_ERROR:		return LLTrans::getString("ExternalEditorCommandParseError");
	case EC_BINARY_NOT_FOUND:	return LLTrans::getString("ExternalEditorNotFound");
	case EC_FAILED_TO_RUN:		return LLTrans::getString("ExternalEditorFailedToRun");
	}

	return LLTrans::getString("Unknown");
}

// TODO:
// - Unit-test this with tests like LLStringUtil::getTokens() (the
//   command-line overload that supports quoted tokens)
// - Unless there are significant semantic differences, eliminate this method
//   and use LLStringUtil::getTokens() instead.

// static
size_t LLExternalEditor::tokenize(string_vec_t& tokens, const std::string& str)
{
	tokens.clear();

	// Split the argument string into separate strings for each argument
	typedef boost::tokenizer< boost::char_separator<char> > tokenizer;
	boost::char_separator<char> sep("", "\" ", boost::drop_empty_tokens);

	tokenizer tokens_list(str, sep);
	tokenizer::iterator token_iter;
	BOOL inside_quotes = FALSE;
	BOOL last_was_space = FALSE;
	for (token_iter = tokens_list.begin(); token_iter != tokens_list.end(); ++token_iter)
	{
		if (!strncmp("\"",(*token_iter).c_str(),2))
		{
			inside_quotes = !inside_quotes;
		}
		else if (!strncmp(" ",(*token_iter).c_str(),2))
		{
			if(inside_quotes)
			{
				tokens.back().append(std::string(" "));
				last_was_space = TRUE;
			}
		}
		else
		{
			std::string to_push = *token_iter;
			if (last_was_space)
			{
				tokens.back().append(to_push);
				last_was_space = FALSE;
			}
			else
			{
				tokens.push_back(to_push);
			}
		}
	}

	return tokens.size();
}

// static
std::string LLExternalEditor::findCommand(
	const std::string& env_var,
	const std::string& override)
{
	std::string cmd;

	// Get executable path.
	if (!override.empty())	// try the supplied override first
	{
		cmd = override;
		llinfos << "Using override" << llendl;
	}
	else if (!LLUI::sSettingGroups["config"]->getString(sSetting).empty())
	{
		cmd = LLUI::sSettingGroups["config"]->getString(sSetting);
		llinfos << "Using setting" << llendl;
	}
	else					// otherwise use the path specified by the environment variable
	{
		char* env_var_val = getenv(env_var.c_str());
		if (env_var_val)
		{
			cmd = env_var_val;
			llinfos << "Using env var " << env_var << llendl;
		}
	}

	llinfos << "Found command [" << cmd << "]" << llendl;
	return cmd;
}
<commit_msg>More fixing. I forgot semicolons. -_-<commit_after>/**
 * @file llexternaleditor.cpp
 * @brief A convenient class to run external editor.
 *
 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"
#include "llexternaleditor.h"

#include "lltrans.h"
#include "llui.h"
#include "llprocess.h"
#include "llsdutil.h"
#include <boost/foreach.hpp>

// static
const std::string LLExternalEditor::sFilenameMarker = "%s";

// static
const std::string LLExternalEditor::sSetting = "ExternalEditor";

LLExternalEditor::EErrorCode LLExternalEditor::setCommand(const std::string& env_var, const std::string& override)
{
	std::string cmd = findCommand(env_var, override);
	if (cmd.empty())
	{
		llwarns << "Editor command is empty or not set" << llendl;
// <FS:CR> FIRE-10320 If no editor is set, fallback on the system open handler
		//return EC_NOT_SPECIFIED;
		llwarns << "Falling back on generic open handler" << llendl;
#ifdef WIN32
		cmd = "%comspec% /C START \"%s\"";
#endif
#ifdef DARWIN
		cmd = "/usr/bin/open \"%s\"";
#endif
#ifdef LINUX
		// xdg-open might not actually be installed, but it's out best shot
		cmd = findCommand("", "/usr/bin/xdg-open \"%s\"");
#endif
		if (cmd.empty())
		{
			return EC_NOT_SPECIFIED;
		}
// </FS:CR>
	}

	string_vec_t tokens;
	tokenize(tokens, cmd);

	// Check executable for existence.
	std::string bin_path = tokens[0];
	if (!LLFile::isfile(bin_path))
	{
		llwarns << "Editor binary [" << bin_path << "] not found" << llendl;
		return EC_BINARY_NOT_FOUND;
	}

	// Save command.
	mProcessParams = LLProcess::Params();
	mProcessParams.executable = bin_path;
	for (size_t i = 1; i < tokens.size(); ++i)
	{
		mProcessParams.args.add(tokens[i]);
	}

	// Add the filename marker if missing.
	if (cmd.find(sFilenameMarker) == std::string::npos)
	{
		mProcessParams.args.add(sFilenameMarker);
		llinfos << "Adding the filename marker (" << sFilenameMarker << ")" << llendl;
	}

	llinfos << "Setting command [" << mProcessParams << "]" << llendl;

	return EC_SUCCESS;
}

LLExternalEditor::EErrorCode LLExternalEditor::run(const std::string& file_path)
{
	if (std::string(mProcessParams.executable).empty() || mProcessParams.args.empty())
	{
		llwarns << "Editor command not set" << llendl;
		return EC_NOT_SPECIFIED;
	}

	// Copy params block so we can replace sFilenameMarker
	LLProcess::Params params;
	params.executable = mProcessParams.executable;

	// Substitute the filename marker in the command with the actual passed file name.
	BOOST_FOREACH(const std::string& arg, mProcessParams.args)
	{
		std::string fixed(arg);
		LLStringUtil::replaceString(fixed, sFilenameMarker, file_path);
		params.args.add(fixed);
	}

	// Run the editor. Prevent killing the process in destructor.
	params.autokill = false;
	return LLProcess::create(params) ? EC_SUCCESS : EC_FAILED_TO_RUN;
}

// static
std::string LLExternalEditor::getErrorMessage(EErrorCode code)
{
	switch (code)
	{
	case EC_SUCCESS: 			return LLTrans::getString("ok");
	case EC_NOT_SPECIFIED: 		return LLTrans::getString("ExternalEditorNotSet");
	case EC_PARSE_ERROR:		return LLTrans::getString("ExternalEditorCommandParseError");
	case EC_BINARY_NOT_FOUND:	return LLTrans::getString("ExternalEditorNotFound");
	case EC_FAILED_TO_RUN:		return LLTrans::getString("ExternalEditorFailedToRun");
	}

	return LLTrans::getString("Unknown");
}

// TODO:
// - Unit-test this with tests like LLStringUtil::getTokens() (the
//   command-line overload that supports quoted tokens)
// - Unless there are significant semantic differences, eliminate this method
//   and use LLStringUtil::getTokens() instead.

// static
size_t LLExternalEditor::tokenize(string_vec_t& tokens, const std::string& str)
{
	tokens.clear();

	// Split the argument string into separate strings for each argument
	typedef boost::tokenizer< boost::char_separator<char> > tokenizer;
	boost::char_separator<char> sep("", "\" ", boost::drop_empty_tokens);

	tokenizer tokens_list(str, sep);
	tokenizer::iterator token_iter;
	BOOL inside_quotes = FALSE;
	BOOL last_was_space = FALSE;
	for (token_iter = tokens_list.begin(); token_iter != tokens_list.end(); ++token_iter)
	{
		if (!strncmp("\"",(*token_iter).c_str(),2))
		{
			inside_quotes = !inside_quotes;
		}
		else if (!strncmp(" ",(*token_iter).c_str(),2))
		{
			if(inside_quotes)
			{
				tokens.back().append(std::string(" "));
				last_was_space = TRUE;
			}
		}
		else
		{
			std::string to_push = *token_iter;
			if (last_was_space)
			{
				tokens.back().append(to_push);
				last_was_space = FALSE;
			}
			else
			{
				tokens.push_back(to_push);
			}
		}
	}

	return tokens.size();
}

// static
std::string LLExternalEditor::findCommand(
	const std::string& env_var,
	const std::string& override)
{
	std::string cmd;

	// Get executable path.
	if (!override.empty())	// try the supplied override first
	{
		cmd = override;
		llinfos << "Using override" << llendl;
	}
	else if (!LLUI::sSettingGroups["config"]->getString(sSetting).empty())
	{
		cmd = LLUI::sSettingGroups["config"]->getString(sSetting);
		llinfos << "Using setting" << llendl;
	}
	else					// otherwise use the path specified by the environment variable
	{
		char* env_var_val = getenv(env_var.c_str());
		if (env_var_val)
		{
			cmd = env_var_val;
			llinfos << "Using env var " << env_var << llendl;
		}
	}

	llinfos << "Found command [" << cmd << "]" << llendl;
	return cmd;
}
<|endoftext|>


<commit_before>#include "ManageGamesMenu.h"
#include <sstream>

#include "NewGameMenu.h"
#include "ChooseYourLevelMenu.h"

/** @namespace Symp */
namespace Symp {

extern int g_WindowHeight;
extern int g_WindowWidth;

/**
* @brief ManageGamesMenu constructor
* Responsible for the initialization of the private attributes of the #ManageGamesMenuMenu class. This function
* is not responsible for drawing the graphical elements that compose the menu, the #init() function is.
* @see Player
* @see MenuManager
* @see State
* @see init()
* @see ~ManageGamesMenu()
*/
ManageGamesMenu::ManageGamesMenu()
	:State(){

}

/**
* @brief ManageGamesMenu elements initialization
* The elements that compose the menu are created in this function.
* @see Player
* @see MenuManager
* @see State
* @see end()
*/
void ManageGamesMenu::init(){

	m_background = new Image("../assets/menu/manage-games-background.png");
	m_background->setWidth(g_WindowWidth);
	m_background->setHeight(g_WindowHeight);
	m_background->setAspectRatio(AspectRatio::IGNORE_ASPECT_RATIO);
	MenuManager::getInstance()->addGuiComponent(m_background, 0);
	m_background->update();

	// The go back button up-left of the window
	m_pBackButton = new Image("../assets/menu/back-to-menu-outgame.png", g_WindowWidth*0.05, g_WindowHeight*0.05, 0.5);
	m_pBackButton->setColor(Color::YELLOWDINO);
	m_pBackButton->enable();
	m_pBackButton->setAspectRatio(AspectRatio::EXPAND_ASPECT_RATIO);
	MenuManager::getInstance()->addGuiComponent(m_pBackButton, 1);

	//Image that display the "Current Game" Label
	m_pCurrentGameLabel = new Image("../assets/menu/current_game.png", g_WindowWidth*0.25, g_WindowHeight*0.26, 0.7);
	MenuManager::getInstance()->addGuiComponent(m_pCurrentGameLabel, 2);

	// Last Player panel
	createPlayerPanel(MenuManager::getInstance()->getLastPlayer(), g_WindowWidth*0.25,  g_WindowHeight*0.3, g_WindowWidth*0.6, g_WindowHeight*0.1, Color::YELLOWDINO, Color::BLUEDINO);

	// If there is more than one player
	if(MenuManager::getInstance()->getPlayers().size() > 1 ) {
		//Image that display the "Load another game" Label
		m_pLoadAnotherGameLabel = new Image("../assets/menu/load_another_game.png", g_WindowWidth*0.25, g_WindowHeight*0.46, 0.7);
		MenuManager::getInstance()->addGuiComponent(m_pLoadAnotherGameLabel, 2);

		//Other players panel
		int posY = g_WindowHeight*0.5;
		for (unsigned int i = 0; i < MenuManager::getInstance()->getPlayers().size(); ++i){
			if(MenuManager::getInstance()->getPlayers()[i] != MenuManager::getInstance()->getLastPlayer()) {
				createPlayerPanel(MenuManager::getInstance()->getPlayers()[i], g_WindowWidth*0.25, posY + i*g_WindowHeight*0.12, g_WindowWidth*0.6, g_WindowHeight*0.1, Color::YELLOWDINO, Color::BLUEDINO);
			}
		}

	}

	//Create a new Player Button
	m_pCreateNewGameButton = new Image("../assets/menu/create-new-game.png", g_WindowWidth*0.6, g_WindowHeight*0.8);
	m_pCreateNewGameButton->setHeight(g_WindowHeight*0.1);
	m_pCreateNewGameButton->setColor(Color::YELLOWDINO);
	m_pCreateNewGameButton->enable();
	m_pCreateNewGameButton->setAspectRatio(AspectRatio::KEEP_ASPECT_RATIO);
	MenuManager::getInstance()->addGuiComponent(m_pCreateNewGameButton, 0);

}

/**
* @brief Create a panel with the #Player data
* The elements that compose the #Player panel are created in this function. This panel
* is composed by a #Layout that group elements but that do not manage their position and shape, and a #Button
* that can receive events. The panel can be customized with two colors : one for the border of the #Layout component, one for the background of the #Button component.
* @param pPlayer the reference to the #Player this panel is made for
* @param iPosX the x coordinate of the upper-left corner of the panel in pixels
* @param iPosY the y coordinate of the upper-left corner of the panel in pixels
* @param iWidth the width of the panel in pixels
* @param iHeight the height of the panel in pixels
* @param borderColor the color of the border of the panel
* @param backgoundColor the color of the background of the panel
* @return pLayout the reference to the #Layout that contain the #Player graphcal data
* @see Player
* @see MenuManager
* @see State
* @see init()
*/
Layout* ManageGamesMenu::createPlayerPanel(Player* pPlayer, int iPosX, int iPosY, int iWidth, int iHeight,
	Color borderColor, Color backgroundColor){
	//Creation of the main Layout
	//Layout* pLayout = new Layout(iPosX, iPosY, iWidth, iHeight, borderColor, LayoutFillAttribute::BORDER);

	int iCrossWidth = g_WindowWidth*0.1;

	Layout* persoLayout = new Layout(iPosX, iPosY, iWidth - (iCrossWidth + 10), iHeight, borderColor, LayoutFillAttribute::BORDER);
	int iVMargin = persoLayout->getVerticalMargin();
	int iHMargin = persoLayout->getHorizontalMargin();

	//Creation of the Button
	Button* button = new Button(backgroundColor, iPosX, iPosY, iWidth - (iCrossWidth + 10), iHeight);
	MenuManager::getInstance()->addGuiComponent(button, 0);

	//Retrieve the avatar index
	std::ostringstream oss;
	oss << pPlayer->getAvatarIndex();
	std::string avatarIndex = oss.str();

	// Display the avatar
	Image* image = new Image(std::string("../assets/menu/avatar" + avatarIndex + ".png").c_str(), iPosX + iHMargin, iPosY + iVMargin);
	image->setWidth(iWidth - 2*iHMargin);
	image->setHeight(iHeight - 2*iVMargin);
	persoLayout->addComponent(image, 0, 0, false);
	image->update();

	// Display the Player progression bar
	int level = pPlayer->getCurrentLevel();
	int sliderHeight = g_WindowHeight*0.03;
	int sliderPosX = image->getIND_Entity2d()->getSurface()->getWidth()*image->getIND_Entity2d()->getScaleX() + image->getPosX() + 2 * iHMargin;
	int sliderPosY = iPosY + iHeight - (sliderHeight + iVMargin);
	int sliderWidth = iWidth - iCrossWidth - 6*iHMargin - image->getIND_Entity2d()->getSurface()->getWidth()*image->getIND_Entity2d()->getScaleY();
	Slider* slider = new Slider((float)level/gTotalLevelNumber, sliderPosX, sliderPosY, sliderWidth, sliderHeight);
	persoLayout->addComponent(slider, 1, 0, false);
	MenuManager::getInstance()->addGuiComponent(slider->getImage(), 2);
	slider->update();
	MenuManager::getInstance()->addGuiLayout(persoLayout, 1);

	// Retrieve the last level unlocked
	Text* lastLevel = new Text("Last level unlocked : " + getLevelName(pPlayer->getCurrentLevel()), Color(20, 20, 20), sliderPosX + sliderWidth - 10, iPosY + sliderHeight, true);
	lastLevel->getIND_Entity2d()->setAlign(IND_RIGHT);
	MenuManager::getInstance()->addGuiComponent(lastLevel, 1);

	//Retrieve the player's name
	Text* name = new Text(pPlayer->getName(), Color::BLUEDINO, sliderPosX, iPosY);
	name->getIND_Entity2d()->setAlign(IND_LEFT);
	MenuManager::getInstance()->addGuiComponent(name, 1);

	//Cross Image
	Image* cross = new Image("../assets/menu/cross.png", iPosX + iWidth - (iCrossWidth + 2*iHMargin), iPosY + 2*iVMargin);
	cross->setColor(Color::RED);
	cross->enable();
	MenuManager::getInstance()->addGuiComponent(cross, 0);

	//Associate the button with the player
	m_buttonMap.insert(std::pair<Button*, Player*>(button, pPlayer));
	m_crossMap.insert(std::pair<Image*, Player*>(cross, pPlayer));

	//Return the main Layout
	return persoLayout;
}

/**
* @brief Handle mouse clic events
* @param mouseX the x coordinate of the mouse position
* @param mouseY the y coordinate of the mouse position
* @see MenuManager
* @see State
* @see InputManager
* @see init()
*/
void ManageGamesMenu::handleMouseClic(int mouseX, int mouseY){
	if (m_pCreateNewGameButton->isTargetedByMouse(mouseX, mouseY)){
		//Creates a new Player
		NewGameMenu* newGameMenu = new NewGameMenu();
		MenuManager::getInstance()->setState(newGameMenu);
	}
	else if (m_pBackButton->isTargetedByMouse(mouseX, mouseY)){
		//Go back
		MenuManager::getInstance()->goBack();
	}
	else{
		// Click on a Player, then display its data in the ChooseYourLevelMenu
		for (std::map<Button*,Player*>::iterator it=m_buttonMap.begin(); it!=m_buttonMap.end(); ++it){
			if (it->first->isTargetedByMouse(mouseX, mouseY)){
				ChooseYourLevelMenu* chooseYourLevelMenu = new ChooseYourLevelMenu(it->second);
				MenuManager::getInstance()->setState(chooseYourLevelMenu);
			}
		}
		for (std::map<Image*,Player*>::iterator it=m_crossMap.begin(); it!=m_crossMap.end(); ++it){
			if (it->first->isTargetedByMouse(mouseX, mouseY)){
				MenuManager::getInstance()->erasePlayerData(it->second);
			}
		}
	}
}

std::string ManageGamesMenu::getLevelName(int level){
	std::string chapter = " CHAPTER ";
	std::string index = " LEVEL ";
	for (int i =1; i<4; ++i){
		if(level- i*3 > 0 ){
			level = level-i*3;
		}else if(level- i*3 < 0){
			std::ostringstream oss;
			oss << level;
			index += oss.str();

			std::ostringstream ossBis;
			ossBis << i;
			chapter += ossBis.str();
			break;
		}
	}
	return chapter + "-" + index;
}

/**
* @brief Handle key down event
* @see MenuManager
* @see State
* @see InputManager
* @see init()
*/
void ManageGamesMenu::keyDownPressed(){
	std::cout << "Key down pressed" <<std::endl;
}

/**
* @brief Handle key up event
* @see MenuManager
* @see State
* @see InputManager
* @see init()
*/
void ManageGamesMenu::keyUpPressed(){
	std::cout << "Key up pressed" <<std::endl;
}

}<commit_msg>Center "Create a New Game" in "ManageGameMenu". fix #172<commit_after>#include "ManageGamesMenu.h"
#include <sstream>

#include "NewGameMenu.h"
#include "ChooseYourLevelMenu.h"

/** @namespace Symp */
namespace Symp {

extern int g_WindowHeight;
extern int g_WindowWidth;

/**
* @brief ManageGamesMenu constructor
* Responsible for the initialization of the private attributes of the #ManageGamesMenuMenu class. This function
* is not responsible for drawing the graphical elements that compose the menu, the #init() function is.
* @see Player
* @see MenuManager
* @see State
* @see init()
* @see ~ManageGamesMenu()
*/
ManageGamesMenu::ManageGamesMenu()
	:State(){

}

/**
* @brief ManageGamesMenu elements initialization
* The elements that compose the menu are created in this function.
* @see Player
* @see MenuManager
* @see State
* @see end()
*/
void ManageGamesMenu::init(){

	m_background = new Image("../assets/menu/manage-games-background.png");
	m_background->setWidth(g_WindowWidth);
	m_background->setHeight(g_WindowHeight);
	m_background->setAspectRatio(AspectRatio::IGNORE_ASPECT_RATIO);
	MenuManager::getInstance()->addGuiComponent(m_background, 0);
	m_background->update();

	// The go back button up-left of the window
	m_pBackButton = new Image("../assets/menu/back-to-menu-outgame.png", g_WindowWidth*0.05, g_WindowHeight*0.05, 0.5);
	m_pBackButton->setColor(Color::YELLOWDINO);
	m_pBackButton->enable();
	m_pBackButton->setAspectRatio(AspectRatio::EXPAND_ASPECT_RATIO);
	MenuManager::getInstance()->addGuiComponent(m_pBackButton, 1);

	//Image that display the "Current Game" Label
	m_pCurrentGameLabel = new Image("../assets/menu/current_game.png", g_WindowWidth*0.25, g_WindowHeight*0.26, 0.7);
	MenuManager::getInstance()->addGuiComponent(m_pCurrentGameLabel, 2);

	// Last Player panel
	createPlayerPanel(MenuManager::getInstance()->getLastPlayer(), g_WindowWidth*0.25,  g_WindowHeight*0.3, g_WindowWidth*0.6, g_WindowHeight*0.1, Color::YELLOWDINO, Color::BLUEDINO);

	// If there is more than one player
	if(MenuManager::getInstance()->getPlayers().size() > 1 ) {
		//Image that display the "Load another game" Label
		m_pLoadAnotherGameLabel = new Image("../assets/menu/load_another_game.png", g_WindowWidth*0.25, g_WindowHeight*0.46, 0.7);
		MenuManager::getInstance()->addGuiComponent(m_pLoadAnotherGameLabel, 2);

		//Other players panel
		int posY = g_WindowHeight*0.5;
		for (unsigned int i = 0; i < MenuManager::getInstance()->getPlayers().size(); ++i){
			if(MenuManager::getInstance()->getPlayers()[i] != MenuManager::getInstance()->getLastPlayer()) {
				createPlayerPanel(MenuManager::getInstance()->getPlayers()[i], g_WindowWidth*0.25, posY + i*g_WindowHeight*0.12, g_WindowWidth*0.6, g_WindowHeight*0.1, Color::YELLOWDINO, Color::BLUEDINO);
			}
		}

	}

	//Create a new Player Button
	m_pCreateNewGameButton = new Image("../assets/menu/create-new-game.png", g_WindowWidth*0.42, g_WindowHeight*0.8);
	m_pCreateNewGameButton->setHeight(g_WindowHeight*0.1);
	m_pCreateNewGameButton->setColor(Color::YELLOWDINO);
	m_pCreateNewGameButton->enable();
	m_pCreateNewGameButton->setAspectRatio(AspectRatio::KEEP_ASPECT_RATIO);
	MenuManager::getInstance()->addGuiComponent(m_pCreateNewGameButton, 0);

}

/**
* @brief Create a panel with the #Player data
* The elements that compose the #Player panel are created in this function. This panel
* is composed by a #Layout that group elements but that do not manage their position and shape, and a #Button
* that can receive events. The panel can be customized with two colors : one for the border of the #Layout component, one for the background of the #Button component.
* @param pPlayer the reference to the #Player this panel is made for
* @param iPosX the x coordinate of the upper-left corner of the panel in pixels
* @param iPosY the y coordinate of the upper-left corner of the panel in pixels
* @param iWidth the width of the panel in pixels
* @param iHeight the height of the panel in pixels
* @param borderColor the color of the border of the panel
* @param backgoundColor the color of the background of the panel
* @return pLayout the reference to the #Layout that contain the #Player graphcal data
* @see Player
* @see MenuManager
* @see State
* @see init()
*/
Layout* ManageGamesMenu::createPlayerPanel(Player* pPlayer, int iPosX, int iPosY, int iWidth, int iHeight,
	Color borderColor, Color backgroundColor){
	//Creation of the main Layout
	//Layout* pLayout = new Layout(iPosX, iPosY, iWidth, iHeight, borderColor, LayoutFillAttribute::BORDER);

	int iCrossWidth = g_WindowWidth*0.1;

	Layout* persoLayout = new Layout(iPosX, iPosY, iWidth - (iCrossWidth + 10), iHeight, borderColor, LayoutFillAttribute::BORDER);
	int iVMargin = persoLayout->getVerticalMargin();
	int iHMargin = persoLayout->getHorizontalMargin();

	//Creation of the Button
	Button* button = new Button(backgroundColor, iPosX, iPosY, iWidth - (iCrossWidth + 10), iHeight);
	MenuManager::getInstance()->addGuiComponent(button, 0);

	//Retrieve the avatar index
	std::ostringstream oss;
	oss << pPlayer->getAvatarIndex();
	std::string avatarIndex = oss.str();

	// Display the avatar
	Image* image = new Image(std::string("../assets/menu/avatar" + avatarIndex + ".png").c_str(), iPosX + iHMargin, iPosY + iVMargin);
	image->setWidth(iWidth - 2*iHMargin);
	image->setHeight(iHeight - 2*iVMargin);
	persoLayout->addComponent(image, 0, 0, false);
	image->update();

	// Display the Player progression bar
	int level = pPlayer->getCurrentLevel();
	int sliderHeight = g_WindowHeight*0.03;
	int sliderPosX = image->getIND_Entity2d()->getSurface()->getWidth()*image->getIND_Entity2d()->getScaleX() + image->getPosX() + 2 * iHMargin;
	int sliderPosY = iPosY + iHeight - (sliderHeight + iVMargin);
	int sliderWidth = iWidth - iCrossWidth - 6*iHMargin - image->getIND_Entity2d()->getSurface()->getWidth()*image->getIND_Entity2d()->getScaleY();
	Slider* slider = new Slider((float)level/gTotalLevelNumber, sliderPosX, sliderPosY, sliderWidth, sliderHeight);
	persoLayout->addComponent(slider, 1, 0, false);
	MenuManager::getInstance()->addGuiComponent(slider->getImage(), 2);
	slider->update();
	MenuManager::getInstance()->addGuiLayout(persoLayout, 1);

	// Retrieve the last level unlocked
	Text* lastLevel = new Text("Last level unlocked : " + getLevelName(pPlayer->getCurrentLevel()), Color(20, 20, 20), sliderPosX + sliderWidth - 10, iPosY + sliderHeight, true);
	lastLevel->getIND_Entity2d()->setAlign(IND_RIGHT);
	MenuManager::getInstance()->addGuiComponent(lastLevel, 1);

	//Retrieve the player's name
	Text* name = new Text(pPlayer->getName(), Color::BLUEDINO, sliderPosX, iPosY);
	name->getIND_Entity2d()->setAlign(IND_LEFT);
	MenuManager::getInstance()->addGuiComponent(name, 1);

	//Cross Image
	Image* cross = new Image("../assets/menu/cross.png", iPosX + iWidth - (iCrossWidth + 2*iHMargin), iPosY + 2*iVMargin);
	cross->setColor(Color::RED);
	cross->enable();
	MenuManager::getInstance()->addGuiComponent(cross, 0);

	//Associate the button with the player
	m_buttonMap.insert(std::pair<Button*, Player*>(button, pPlayer));
	m_crossMap.insert(std::pair<Image*, Player*>(cross, pPlayer));

	//Return the main Layout
	return persoLayout;
}

/**
* @brief Handle mouse clic events
* @param mouseX the x coordinate of the mouse position
* @param mouseY the y coordinate of the mouse position
* @see MenuManager
* @see State
* @see InputManager
* @see init()
*/
void ManageGamesMenu::handleMouseClic(int mouseX, int mouseY){
	if (m_pCreateNewGameButton->isTargetedByMouse(mouseX, mouseY)){
		//Creates a new Player
		NewGameMenu* newGameMenu = new NewGameMenu();
		MenuManager::getInstance()->setState(newGameMenu);
	}
	else if (m_pBackButton->isTargetedByMouse(mouseX, mouseY)){
		//Go back
		MenuManager::getInstance()->goBack();
	}
	else{
		// Click on a Player, then display its data in the ChooseYourLevelMenu
		for (std::map<Button*,Player*>::iterator it=m_buttonMap.begin(); it!=m_buttonMap.end(); ++it){
			if (it->first->isTargetedByMouse(mouseX, mouseY)){
				ChooseYourLevelMenu* chooseYourLevelMenu = new ChooseYourLevelMenu(it->second);
				MenuManager::getInstance()->setState(chooseYourLevelMenu);
			}
		}
		for (std::map<Image*,Player*>::iterator it=m_crossMap.begin(); it!=m_crossMap.end(); ++it){
			if (it->first->isTargetedByMouse(mouseX, mouseY)){
				MenuManager::getInstance()->erasePlayerData(it->second);
			}
		}
	}
}

std::string ManageGamesMenu::getLevelName(int level){
	std::string chapter = " CHAPTER ";
	std::string index = " LEVEL ";
	for (int i =1; i<4; ++i){
		if(level- i*3 > 0 ){
			level = level-i*3;
		}else if(level- i*3 < 0){
			std::ostringstream oss;
			oss << level;
			index += oss.str();

			std::ostringstream ossBis;
			ossBis << i;
			chapter += ossBis.str();
			break;
		}
	}
	return chapter + "-" + index;
}

/**
* @brief Handle key down event
* @see MenuManager
* @see State
* @see InputManager
* @see init()
*/
void ManageGamesMenu::keyDownPressed(){
	std::cout << "Key down pressed" <<std::endl;
}

/**
* @brief Handle key up event
* @see MenuManager
* @see State
* @see InputManager
* @see init()
*/
void ManageGamesMenu::keyUpPressed(){
	std::cout << "Key up pressed" <<std::endl;
}

}<|endoftext|>


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

#include "modules/canbus/vehicle/lincoln/protocol/brakeinfo_74.h"

#include "gtest/gtest.h"

namespace apollo {
namespace canbus {
namespace lincoln {

class Brakeinfo74Test : public ::testing::Test {
 public:
  virtual void SetUp() {}
};

TEST_F(Brakeinfo74Test, simple) {
  Brakeinfo74 brakeinfo;
  uint8_t data[8] = {0x64U};
  int32_t length = 8;
  ChassisDetail cd;
  brakeinfo.Parse(data, length, &cd);

  EXPECT_FALSE(cd.esp().is_abs_active());
  EXPECT_FALSE(cd.esp().is_abs_enabled());
  EXPECT_FALSE(cd.esp().is_stab_active());
  EXPECT_FALSE(cd.esp().is_stab_enabled());
  EXPECT_FALSE(cd.esp().is_trac_active());
  EXPECT_FALSE(cd.esp().is_trac_enabled());

  EXPECT_EQ(cd.epb().parking_brake_status(), Epb::PBRAKE_OFF);
  EXPECT_DOUBLE_EQ(cd.brake().brake_torque_req(), 400.0);
  EXPECT_EQ(cd.brake().hsa_status(), Brake::HSA_INACTIVE);
  EXPECT_DOUBLE_EQ(cd.brake().brake_torque_act(), 0.0);
  EXPECT_EQ(cd.brake().hsa_status(), Brake::HSA_OFF);
  EXPECT_DOUBLE_EQ(cd.brake().wheel_torque_act(), 0.0);
  EXPECT_FALSE(cd.vehicle_spd().is_vehicle_standstill());
  EXPECT_DOUBLE_EQ(cd.vehicle_spd().acc_est(), 0.0);
}

}  // namespace lincoln
}  // namespace apollo
}  // namespace canbus
<commit_msg>Use full length test data in brakeinfo_74_test<commit_after>/******************************************************************************
 * Copyright 2017 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

#include "modules/canbus/vehicle/lincoln/protocol/brakeinfo_74.h"

#include "gtest/gtest.h"

namespace apollo {
namespace canbus {
namespace lincoln {

class Brakeinfo74Test : public ::testing::Test {
 public:
  virtual void SetUp() {}
};

TEST_F(Brakeinfo74Test, simple) {
  Brakeinfo74 brakeinfo;
  uint8_t data[8] = {0x64U, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14};
  int32_t length = 8;
  ChassisDetail cd;
  brakeinfo.Parse(data, length, &cd);

  EXPECT_TRUE(cd.esp().is_abs_active());
  EXPECT_FALSE(cd.esp().is_abs_enabled());
  EXPECT_TRUE(cd.esp().is_stab_active());
  EXPECT_FALSE(cd.esp().is_stab_enabled());
  EXPECT_FALSE(cd.esp().is_trac_active());
  EXPECT_FALSE(cd.esp().is_trac_enabled());

  EXPECT_EQ(cd.epb().parking_brake_status(), Epb::PBRAKE_OFF);
  EXPECT_DOUBLE_EQ(cd.brake().brake_torque_req(), 2448.0);
  EXPECT_EQ(cd.brake().hsa_status(), Brake::HSA_INACTIVE);
  EXPECT_DOUBLE_EQ(cd.brake().brake_torque_act(), 4108.0);
  EXPECT_EQ(cd.brake().hsa_status(), Brake::HSA_OFF);
  EXPECT_DOUBLE_EQ(cd.brake().wheel_torque_act(), 18500.0);
  EXPECT_FALSE(cd.vehicle_spd().is_vehicle_standstill());
  EXPECT_DOUBLE_EQ(cd.vehicle_spd().acc_est(), 0.665);
}

}  // namespace lincoln
}  // namespace apollo
}  // namespace canbus
<|endoftext|>


<commit_before>/*
 * fMBT, free Model Based Testing tool
 * Copyright (c) 2011, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope 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 program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#include "end_condition.hh"

#include <stdlib.h>

#include <stdio.h> // DEBUG

#ifndef DROI
#include <glib.h>
#endif

End_condition::End_condition(Verdict::Verdict v, Counter c, std::string* p)
  : verdict(v), counter(c), param(p),
    param_float(-1.0), param_long(-1), param_time(-1)
{
    switch (counter) {

    case STEPS:
      param_long = atol(param->c_str());
      status = true;
      break;

    case COVERAGE:
      param_float = atof(param->c_str());
      status = true;
      break;

    case STATETAG:
      // param already contains the state tag string, but it cannot be
      // converted into index (param_long) because the model is not
      // initialized
      status = true;
      break;

    case DURATION:
    {
      param_time = -1;
#ifndef DROI
      char* out = NULL;
      int stat;
      std::string ss = "date --date='" + *param + "' +%s.%N";

      if (g_spawn_command_line_sync(ss.c_str(), &out, NULL, &stat, NULL)) {
        if (!stat) {
          // Store seconds to param_time and microseconds to param_long
          param_time = atoi(out);
          param_long = (strtod(out, NULL) - param_time) * 1000000;
          status = true;
        } else {
          errormsg = "Parsing 'duration' parameter '" + *param + "' failed.";
          errormsg += " Date returned an error when executing '" + ss + "'";
          status = false;
        }
      } else {
        errormsg = "Parsing 'duration' parameter '" + *param + "' failed, could not execute '";
        errormsg += ss + "'";
        status = false;
      }
#else
      char* endp;
      long r = strtol(param->c_str(), &endp, 10);
      if (*endp == 0) {
        param_time = r;
        status = true;
      } else {
        // Error on str?
        errormsg = "Parsing duration '" + *param + "' failed.";
        status = false;
      }
#endif
    }

    case NOPROGRESS:
      param_long = atol(param->c_str());
      status = true;
      break;

    } /* switch (counter) ... */
}

End_condition::~End_condition()
{
  delete param;
}
<commit_msg>fix duration end condition accuracy bug<commit_after>/*
 * fMBT, free Model Based Testing tool
 * Copyright (c) 2011, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope 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 program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#include "end_condition.hh"

#include <stdlib.h>

#include <stdio.h> // DEBUG

#ifndef DROI
#include <glib.h>
#endif

End_condition::End_condition(Verdict::Verdict v, Counter c, std::string* p)
  : verdict(v), counter(c), param(p),
    param_float(-1.0), param_long(-1), param_time(-1)
{
    switch (counter) {

    case STEPS:
      param_long = atol(param->c_str());
      status = true;
      break;

    case COVERAGE:
      param_float = atof(param->c_str());
      status = true;
      break;

    case STATETAG:
      // param already contains the state tag string, but it cannot be
      // converted into index (param_long) because the model is not
      // initialized
      status = true;
      break;

    case DURATION:
    {
      param_time = -1;
#ifndef DROI
      char* out = NULL;
      int stat;
      std::string ss = "date --date='" + *param + "' +%s.%N";

      if (g_spawn_command_line_sync(ss.c_str(), &out, NULL, &stat, NULL)) {
        if (!stat) {
          // Store seconds to param_time and microseconds to param_long
          param_time = atoi(out);
          param_long = (strtod(out, NULL) - param_time) * 1000000;
          status = true;
        } else {
          errormsg = "Parsing 'duration' parameter '" + *param + "' failed.";
          errormsg += " Date returned an error when executing '" + ss + "'";
          status = false;
        }
      } else {
        errormsg = "Parsing 'duration' parameter '" + *param + "' failed, could not execute '";
        errormsg += ss + "'";
        status = false;
      }
#else
      char* endp;
      long r = strtol(param->c_str(), &endp, 10);
      if (*endp == 0) {
        param_time = r;
        status = true;
      } else {
        // Error on str?
        errormsg = "Parsing duration '" + *param + "' failed.";
        status = false;
      }
#endif
      break;
    }

    case NOPROGRESS:
      param_long = atol(param->c_str());
      status = true;
      break;

    } /* switch (counter) ... */
}

End_condition::~End_condition()
{
  delete param;
}
<|endoftext|>


<commit_before>/*
	This file is part of cpp-ethereum.

	cpp-ethereum is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	cpp-ethereum 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 General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with cpp-ethereum.  If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Parser.cpp
 * @author Gav Wood <i@gavwood.com>
 * @date 2014
 */

#include "Parser.h"

#define BOOST_RESULT_OF_USE_DECLTYPE
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/support_utree.hpp>

using namespace std;
using namespace dev;
using namespace dev::eth;
namespace qi = boost::spirit::qi;
namespace px = boost::phoenix;
namespace sp = boost::spirit;

void dev::eth::killBigints(sp::utree const& _this)
{
	switch (_this.which())
	{
	case sp::utree_type::list_type: for (auto const& i: _this) killBigints(i); break;
	case sp::utree_type::any_type: delete _this.get<bigint*>(); break;
	default:;
	}
}

void dev::eth::debugOutAST(ostream& _out, sp::utree const& _this)
{
	switch (_this.which())
	{
	case sp::utree_type::list_type:
		switch (_this.tag())
		{
		case 0: _out << "( "; for (auto const& i: _this) { debugOutAST(_out, i); _out << " "; } _out << ")"; break;
		case 1: _out << "@ "; debugOutAST(_out, _this.front()); break;
		case 2: _out << "@@ "; debugOutAST(_out, _this.front()); break;
		case 3: _out << "[ "; debugOutAST(_out, _this.front()); _out << " ] "; debugOutAST(_out, _this.back()); break;
		case 4: _out << "[[ "; debugOutAST(_out, _this.front()); _out << " ]] "; debugOutAST(_out, _this.back()); break;
		case 5: _out << "{ "; for (auto const& i: _this) { debugOutAST(_out, i); _out << " "; } _out << "}"; break;
		case 6: _out << "$ "; debugOutAST(_out, _this.front()); break;
		default:;
		}

		break;
	case sp::utree_type::int_type: _out << _this.get<int>(); break;
	case sp::utree_type::string_type: _out << "\"" << _this.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::string_type>>() << "\""; break;
	case sp::utree_type::symbol_type: _out << _this.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::symbol_type>>(); break;
	case sp::utree_type::any_type: _out << *_this.get<bigint*>(); break;
	default: _out << "nil";
	}
}

namespace dev { namespace eth {
namespace parseTreeLLL_ {

template<unsigned N>
struct tagNode
{
	void operator()(sp::utree& n, qi::rule<string::const_iterator, qi::ascii::space_type, sp::utree()>::context_type& c) const
	{
		(boost::fusion::at_c<0>(c.attributes) = n).tag(N);
	}
};

}}}

void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out)
{
	using qi::standard::space;
	using qi::standard::space_type;
	using dev::eth::parseTreeLLL_::tagNode;
	typedef sp::basic_string<std::string, sp::utree_type::symbol_type> symbol_type;
	typedef string::const_iterator it;

	static const u256 ether = u256(1000000000) * 1000000000;
	static const u256 finney = u256(1000000000) * 1000000;
	static const u256 szabo = u256(1000000000) * 1000;

	qi::rule<it, space_type, sp::utree()> element;
	qi::rule<it, string()> str = '"' > qi::lexeme[+(~qi::char_(std::string("\"") + '\0'))] > '"';
	qi::rule<it, string()> strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))];
	qi::rule<it, symbol_type()> symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
	qi::rule<it, string()> intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]];
	qi::rule<it, bigint()> integer = intstr;
	qi::rule<it, bigint()> multiplier = qi::lit("wei")[qi::_val = 1] | qi::lit("szabo")[qi::_val = szabo] | qi::lit("finney")[qi::_val = finney] | qi::lit("ether")[qi::_val = ether];
	qi::rule<it, space_type, bigint()> quantity = integer[qi::_val = qi::_1] >> -multiplier[qi::_val *= qi::_1];
	qi::rule<it, space_type, sp::utree()> atom = quantity[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
	qi::rule<it, space_type, sp::utree::list_type()> seq = '{' > *element > '}';
	qi::rule<it, space_type, sp::utree::list_type()> mload = '@' > element;
	qi::rule<it, space_type, sp::utree::list_type()> sload = qi::lit("@@") > element;
	qi::rule<it, space_type, sp::utree::list_type()> mstore = '[' > element > ']' > -qi::lit(":") > element;
	qi::rule<it, space_type, sp::utree::list_type()> sstore = qi::lit("[[") > element > qi::lit("]]") > -qi::lit(":") > element;
	qi::rule<it, space_type, sp::utree::list_type()> calldataload = qi::lit("$") > element;
	qi::rule<it, space_type, sp::utree::list_type()> list = '(' > *element > ')';

	qi::rule<it, space_type, sp::utree()> extra = sload[tagNode<2>()] | mload[tagNode<1>()] | sstore[tagNode<4>()] | mstore[tagNode<3>()] | seq[tagNode<5>()] | calldataload[tagNode<6>()];
	element = atom | list | extra;

	string s;
	s.reserve(_s.size());
	bool incomment = false;
	bool instring = false;
	bool insstring = false;
	for (auto i: _s)
	{
		if (i == ';' && !instring && !insstring)
			incomment = true;
		else if (i == '\n')
			incomment = instring = insstring = false;
		else if (i == '"' && !insstring)
			instring = !instring;
		else if (i == '\'')
			insstring = true;
		else if (i == ' ')
			insstring = false;
		if (!incomment)
			s.push_back(i);
	}
	auto ret = s.cbegin();
	qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out);
	for (auto i = ret; i != s.cend(); ++i)
		if (!isspace(*i))
			BOOST_THROW_EXCEPTION(std::exception());
}

<commit_msg>change typedef to using according to preferred coding style<commit_after>/*
	This file is part of cpp-ethereum.

	cpp-ethereum is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	cpp-ethereum 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 General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with cpp-ethereum.  If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Parser.cpp
 * @author Gav Wood <i@gavwood.com>
 * @date 2014
 */

#include "Parser.h"

#define BOOST_RESULT_OF_USE_DECLTYPE
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/support_utree.hpp>

using namespace std;
using namespace dev;
using namespace dev::eth;
namespace qi = boost::spirit::qi;
namespace px = boost::phoenix;
namespace sp = boost::spirit;

void dev::eth::killBigints(sp::utree const& _this)
{
	switch (_this.which())
	{
	case sp::utree_type::list_type: for (auto const& i: _this) killBigints(i); break;
	case sp::utree_type::any_type: delete _this.get<bigint*>(); break;
	default:;
	}
}

void dev::eth::debugOutAST(ostream& _out, sp::utree const& _this)
{
	switch (_this.which())
	{
	case sp::utree_type::list_type:
		switch (_this.tag())
		{
		case 0: _out << "( "; for (auto const& i: _this) { debugOutAST(_out, i); _out << " "; } _out << ")"; break;
		case 1: _out << "@ "; debugOutAST(_out, _this.front()); break;
		case 2: _out << "@@ "; debugOutAST(_out, _this.front()); break;
		case 3: _out << "[ "; debugOutAST(_out, _this.front()); _out << " ] "; debugOutAST(_out, _this.back()); break;
		case 4: _out << "[[ "; debugOutAST(_out, _this.front()); _out << " ]] "; debugOutAST(_out, _this.back()); break;
		case 5: _out << "{ "; for (auto const& i: _this) { debugOutAST(_out, i); _out << " "; } _out << "}"; break;
		case 6: _out << "$ "; debugOutAST(_out, _this.front()); break;
		default:;
		}

		break;
	case sp::utree_type::int_type: _out << _this.get<int>(); break;
	case sp::utree_type::string_type: _out << "\"" << _this.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::string_type>>() << "\""; break;
	case sp::utree_type::symbol_type: _out << _this.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::symbol_type>>(); break;
	case sp::utree_type::any_type: _out << *_this.get<bigint*>(); break;
	default: _out << "nil";
	}
}

namespace dev { namespace eth {
namespace parseTreeLLL_ {

template<unsigned N>
struct tagNode
{
	void operator()(sp::utree& n, qi::rule<string::const_iterator, qi::ascii::space_type, sp::utree()>::context_type& c) const
	{
		(boost::fusion::at_c<0>(c.attributes) = n).tag(N);
	}
};

}}}

void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out)
{
	using qi::standard::space;
	using qi::standard::space_type;
	using dev::eth::parseTreeLLL_::tagNode;
	using symbol_type = sp::basic_string<std::string, sp::utree_type::symbol_type>;
	using it = string::const_iterator;

	static const u256 ether = u256(1000000000) * 1000000000;
	static const u256 finney = u256(1000000000) * 1000000;
	static const u256 szabo = u256(1000000000) * 1000;

	qi::rule<it, space_type, sp::utree()> element;
	qi::rule<it, string()> str = '"' > qi::lexeme[+(~qi::char_(std::string("\"") + '\0'))] > '"';
	qi::rule<it, string()> strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))];
	qi::rule<it, symbol_type()> symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
	qi::rule<it, string()> intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]];
	qi::rule<it, bigint()> integer = intstr;
	qi::rule<it, bigint()> multiplier = qi::lit("wei")[qi::_val = 1] | qi::lit("szabo")[qi::_val = szabo] | qi::lit("finney")[qi::_val = finney] | qi::lit("ether")[qi::_val = ether];
	qi::rule<it, space_type, bigint()> quantity = integer[qi::_val = qi::_1] >> -multiplier[qi::_val *= qi::_1];
	qi::rule<it, space_type, sp::utree()> atom = quantity[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
	qi::rule<it, space_type, sp::utree::list_type()> seq = '{' > *element > '}';
	qi::rule<it, space_type, sp::utree::list_type()> mload = '@' > element;
	qi::rule<it, space_type, sp::utree::list_type()> sload = qi::lit("@@") > element;
	qi::rule<it, space_type, sp::utree::list_type()> mstore = '[' > element > ']' > -qi::lit(":") > element;
	qi::rule<it, space_type, sp::utree::list_type()> sstore = qi::lit("[[") > element > qi::lit("]]") > -qi::lit(":") > element;
	qi::rule<it, space_type, sp::utree::list_type()> calldataload = qi::lit("$") > element;
	qi::rule<it, space_type, sp::utree::list_type()> list = '(' > *element > ')';

	qi::rule<it, space_type, sp::utree()> extra = sload[tagNode<2>()] | mload[tagNode<1>()] | sstore[tagNode<4>()] | mstore[tagNode<3>()] | seq[tagNode<5>()] | calldataload[tagNode<6>()];
	element = atom | list | extra;

	string s;
	s.reserve(_s.size());
	bool incomment = false;
	bool instring = false;
	bool insstring = false;
	for (auto i: _s)
	{
		if (i == ';' && !instring && !insstring)
			incomment = true;
		else if (i == '\n')
			incomment = instring = insstring = false;
		else if (i == '"' && !insstring)
			instring = !instring;
		else if (i == '\'')
			insstring = true;
		else if (i == ' ')
			insstring = false;
		if (!incomment)
			s.push_back(i);
	}
	auto ret = s.cbegin();
	qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out);
	for (auto i = ret; i != s.cend(); ++i)
		if (!isspace(*i))
			BOOST_THROW_EXCEPTION(std::exception());
}

<|endoftext|>


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

#ifndef INCLUDED_UCBHELPER_HANDLEINTERACTIONREQUEST_HXX
#define INCLUDED_UCBHELPER_HANDLEINTERACTIONREQUEST_HXX

#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_
#include "com/sun/star/uno/Exception.hpp"
#endif
#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include "com/sun/star/uno/Reference.hxx"
#endif
#ifndef _RTL_REF_HXX_
#include "rtl/ref.hxx"
#endif
#ifndef _SAL_TYPES_H_
#include "sal/types.h"
#endif

#ifndef INCLUDED_UTILITY
#include <utility>
#define INCLUDED_UTILITY
#endif

namespace com { namespace sun { namespace star { namespace ucb {
    class XCommandEnvironment;
} } } }
namespace ucbhelper {
    class InteractionSupplyAuthentication;
    class SimpleAuthenticationRequest;
    class SimpleInteractionRequest;
    class SimpleCertificateValidationRequest;
}

/** Pass a <type scope="ucbhelper">SimpleInteractionRequest</type> to an
    <type scope="com::sun::star::task">XInteractionHandler</type>, and handle
    (by throwing the request as an exception) those cases where an interaction
    handler is either not available or does not handle the request.

    @param rRequest
    a <type scope="ucbhelper">SimpleInteractionRequest</type>.  Must not be
    <NULL/>.

    @param rEnvironment
    At the moment, only the
    <type scope="com::sun::star::task">XInteractionHandler</type> part is
    used.  May be <NULL/>.

    @param bThrowOnAbort
    determines what is done if the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation:  If
    <TRUE/>, an appropriate
    <type scope="com::sun::star::ucb">CommandFailedException</type> is thrown.
    If <FALSE/>, <const scope="ucbhelper">CONTINUATION_ABORT</const> is passed
    to the caller of this function.

    @returns
    the constant (defined in ucbhelper/simpelinteractionrequest.hxx) that
    corresponds to the continuation selected by the interaction handler.
    The constant <const scope="ucbhelper">CONTINUATION_UNKNOWN</const> will
    never be returned.

    @throws

the exception specified by the request, if an interaction handler is
    either not available or does not handle the request;

a <type scope="com::sun::star::ucb">CommandFailedException</type> if
    the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation and
    bThrowOnAbort is <TRUE/>;

a <type scope="com::sun::star::uno">RuntimeException</type> if such an
    exception is thrown by code called from within this function.

 */
namespace ucbhelper {

sal_Int32
handleInteractionRequest(
    rtl::Reference< ucbhelper::SimpleInteractionRequest > const & rRequest,
    com::sun::star::uno::Reference<
            com::sun::star::ucb::XCommandEnvironment > const &
        rEnvironment,
    bool bThrowOnAbort = true)
    SAL_THROW((com::sun::star::uno::Exception));

}

/** Pass a <type scope="ucbhelper">SimpleAuthenticationRequest</type> to an
    <type scope="com::sun::star::task">XInteractionHandler</type>, and handle
    (by throwing the request as an exception) those cases where an interaction
    handler is either not available or does not handle the request.

    @param rRequest
    a <type scope="ucbhelper">SimpleAuthenticationRequest</type>.  Must not be
    <NULL/>.

    @param rEnvironment
    At the moment, only the
    <type scope="com::sun::star::task">XInteractionHandler</type> part is
    used.  May be <NULL/>.

    @param bThrowOnAbort
    determines what is done if the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation:  If
    <TRUE/>, an appropriate
    <type scope="com::sun::star::ucb">CommandFailedException</type> is thrown.
    If <FALSE/>, <const scope="ucbhelper">CONTINUATION_ABORT</const> is passed
    to the caller of this function.

    @returns
    either a pair consisting of one of the constants
    <const scope="ucbhelper">CONTINUATION_ABORT</const> or
    <const scope="ucbhelper">CONTINUATION_RETRY</const> (defined in
    ucbhelper/simpelinteractionrequest.hxx) and an empty reference, or a pair
    consisting of the constant
    <const scope="ucbhelper">CONTINUATION_UNKNOWN</const> and a reference to
    an <type scope="ucbhelper">InteractionSupplyAuthentication</type> that
    contains the supplied data.

    @throws

the exception specified by the request, if an interaction handler is
    either not available or does not handle the request;

a <type scope="com::sun::star::ucb">CommandFailedException</type> if
    the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation and
    bThrowOnAbort is <TRUE/>;

a <type scope="com::sun::star::uno">RuntimeException</type> if such an
    exception is thrown by code called from within this function.

 */
namespace ucbhelper {

std::pair< sal_Int32,
           rtl::Reference< ucbhelper::InteractionSupplyAuthentication > >
handleInteractionRequest(
    rtl::Reference< ucbhelper::SimpleAuthenticationRequest > const & rRequest,
    com::sun::star::uno::Reference<
            com::sun::star::ucb::XCommandEnvironment > const &
        rEnvironment,
    bool bThrowOnAbort = true)
    SAL_THROW((com::sun::star::uno::Exception));

}

/** Pass a <type scope="ucbhelper">SimpleCertificateValidationRequest</type> to an
    <type scope="com::sun::star::task">XInteractionHandler</type>, and handle
    (by throwing the request as an exception) those cases where an interaction
    handler is either not available or does not handle the request.

    @param rRequest
    a <type scope="ucbhelper">SimpleCertificateValidationRequest</type>.  Must not be
    <NULL/>.

    @param rEnvironment
    At the moment, only the
    <type scope="com::sun::star::task">XInteractionHandler</type> part is
    used.  May be <NULL/>.

    @param bThrowOnAbort
    determines what is done if the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation:  If
    <TRUE/>, an appropriate
    <type scope="com::sun::star::ucb">CommandFailedException</type> is thrown.
    If <FALSE/>, <const scope="ucbhelper">CONTINUATION_ABORT</const> is passed
    to the caller of this function.

   @returns
    the constant (defined in ucbhelper/simpelinteractionrequest.hxx) that
    corresponds to the continuation selected by the interaction handler.
    The constant <const scope="ucbhelper">CONTINUATION_UNKNOWN</const> will
    never be returned.

    @throws

the exception specified by the request, if an interaction handler is
    either not available or does not handle the request;

a <type scope="com::sun::star::ucb">CommandFailedException</type> if
    the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation and
    bThrowOnAbort is <TRUE/>;

a <type scope="com::sun::star::uno">RuntimeException</type> if such an
    exception is thrown by code called from within this function.

 */
namespace ucbhelper {

sal_Int32
handleInteractionRequest(
    rtl::Reference< ucbhelper::SimpleCertificateValidationRequest > const & rRequest,
    com::sun::star::uno::Reference<
            com::sun::star::ucb::XCommandEnvironment > const &
        rEnvironment,
    bool bThrowOnAbort = true)
    SAL_THROW((com::sun::star::uno::Exception));

}
#endif // INCLUDED_UCBHELPER_HANDLEINTERACTIONREQUEST_HXX
<commit_msg>INTEGRATION: CWS changefileheader (1.3.22); FILE MERGED 2008/04/01 16:02:44 thb 1.3.22.3: #i85898# Stripping all external header guards 2008/04/01 12:58:43 thb 1.3.22.2: #i85898# Stripping all external header guards 2008/03/31 15:31:28 rt 1.3.22.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: handleinteractionrequest.hxx,v $
 * $Revision: 1.4 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef INCLUDED_UCBHELPER_HANDLEINTERACTIONREQUEST_HXX
#define INCLUDED_UCBHELPER_HANDLEINTERACTIONREQUEST_HXX

#include "com/sun/star/uno/Exception.hpp"
#include "com/sun/star/uno/Reference.hxx"
#include "rtl/ref.hxx"
#include "sal/types.h"

#ifndef INCLUDED_UTILITY
#include <utility>
#define INCLUDED_UTILITY
#endif

namespace com { namespace sun { namespace star { namespace ucb {
    class XCommandEnvironment;
} } } }
namespace ucbhelper {
    class InteractionSupplyAuthentication;
    class SimpleAuthenticationRequest;
    class SimpleInteractionRequest;
    class SimpleCertificateValidationRequest;
}

/** Pass a <type scope="ucbhelper">SimpleInteractionRequest</type> to an
    <type scope="com::sun::star::task">XInteractionHandler</type>, and handle
    (by throwing the request as an exception) those cases where an interaction
    handler is either not available or does not handle the request.

    @param rRequest
    a <type scope="ucbhelper">SimpleInteractionRequest</type>.  Must not be
    <NULL/>.

    @param rEnvironment
    At the moment, only the
    <type scope="com::sun::star::task">XInteractionHandler</type> part is
    used.  May be <NULL/>.

    @param bThrowOnAbort
    determines what is done if the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation:  If
    <TRUE/>, an appropriate
    <type scope="com::sun::star::ucb">CommandFailedException</type> is thrown.
    If <FALSE/>, <const scope="ucbhelper">CONTINUATION_ABORT</const> is passed
    to the caller of this function.

    @returns
    the constant (defined in ucbhelper/simpelinteractionrequest.hxx) that
    corresponds to the continuation selected by the interaction handler.
    The constant <const scope="ucbhelper">CONTINUATION_UNKNOWN</const> will
    never be returned.

    @throws

the exception specified by the request, if an interaction handler is
    either not available or does not handle the request;

a <type scope="com::sun::star::ucb">CommandFailedException</type> if
    the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation and
    bThrowOnAbort is <TRUE/>;

a <type scope="com::sun::star::uno">RuntimeException</type> if such an
    exception is thrown by code called from within this function.

 */
namespace ucbhelper {

sal_Int32
handleInteractionRequest(
    rtl::Reference< ucbhelper::SimpleInteractionRequest > const & rRequest,
    com::sun::star::uno::Reference<
            com::sun::star::ucb::XCommandEnvironment > const &
        rEnvironment,
    bool bThrowOnAbort = true)
    SAL_THROW((com::sun::star::uno::Exception));

}

/** Pass a <type scope="ucbhelper">SimpleAuthenticationRequest</type> to an
    <type scope="com::sun::star::task">XInteractionHandler</type>, and handle
    (by throwing the request as an exception) those cases where an interaction
    handler is either not available or does not handle the request.

    @param rRequest
    a <type scope="ucbhelper">SimpleAuthenticationRequest</type>.  Must not be
    <NULL/>.

    @param rEnvironment
    At the moment, only the
    <type scope="com::sun::star::task">XInteractionHandler</type> part is
    used.  May be <NULL/>.

    @param bThrowOnAbort
    determines what is done if the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation:  If
    <TRUE/>, an appropriate
    <type scope="com::sun::star::ucb">CommandFailedException</type> is thrown.
    If <FALSE/>, <const scope="ucbhelper">CONTINUATION_ABORT</const> is passed
    to the caller of this function.

    @returns
    either a pair consisting of one of the constants
    <const scope="ucbhelper">CONTINUATION_ABORT</const> or
    <const scope="ucbhelper">CONTINUATION_RETRY</const> (defined in
    ucbhelper/simpelinteractionrequest.hxx) and an empty reference, or a pair
    consisting of the constant
    <const scope="ucbhelper">CONTINUATION_UNKNOWN</const> and a reference to
    an <type scope="ucbhelper">InteractionSupplyAuthentication</type> that
    contains the supplied data.

    @throws

the exception specified by the request, if an interaction handler is
    either not available or does not handle the request;

a <type scope="com::sun::star::ucb">CommandFailedException</type> if
    the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation and
    bThrowOnAbort is <TRUE/>;

a <type scope="com::sun::star::uno">RuntimeException</type> if such an
    exception is thrown by code called from within this function.

 */
namespace ucbhelper {

std::pair< sal_Int32,
           rtl::Reference< ucbhelper::InteractionSupplyAuthentication > >
handleInteractionRequest(
    rtl::Reference< ucbhelper::SimpleAuthenticationRequest > const & rRequest,
    com::sun::star::uno::Reference<
            com::sun::star::ucb::XCommandEnvironment > const &
        rEnvironment,
    bool bThrowOnAbort = true)
    SAL_THROW((com::sun::star::uno::Exception));

}

/** Pass a <type scope="ucbhelper">SimpleCertificateValidationRequest</type> to an
    <type scope="com::sun::star::task">XInteractionHandler</type>, and handle
    (by throwing the request as an exception) those cases where an interaction
    handler is either not available or does not handle the request.

    @param rRequest
    a <type scope="ucbhelper">SimpleCertificateValidationRequest</type>.  Must not be
    <NULL/>.

    @param rEnvironment
    At the moment, only the
    <type scope="com::sun::star::task">XInteractionHandler</type> part is
    used.  May be <NULL/>.

    @param bThrowOnAbort
    determines what is done if the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation:  If
    <TRUE/>, an appropriate
    <type scope="com::sun::star::ucb">CommandFailedException</type> is thrown.
    If <FALSE/>, <const scope="ucbhelper">CONTINUATION_ABORT</const> is passed
    to the caller of this function.

   @returns
    the constant (defined in ucbhelper/simpelinteractionrequest.hxx) that
    corresponds to the continuation selected by the interaction handler.
    The constant <const scope="ucbhelper">CONTINUATION_UNKNOWN</const> will
    never be returned.

    @throws

the exception specified by the request, if an interaction handler is
    either not available or does not handle the request;

a <type scope="com::sun::star::ucb">CommandFailedException</type> if
    the interaction handler selects a
    <const scope="ucbhelper">CONTINUATION_ABORT</const> continuation and
    bThrowOnAbort is <TRUE/>;

a <type scope="com::sun::star::uno">RuntimeException</type> if such an
    exception is thrown by code called from within this function.

 */
namespace ucbhelper {

sal_Int32
handleInteractionRequest(
    rtl::Reference< ucbhelper::SimpleCertificateValidationRequest > const & rRequest,
    com::sun::star::uno::Reference<
            com::sun::star::ucb::XCommandEnvironment > const &
        rEnvironment,
    bool bThrowOnAbort = true)
    SAL_THROW((com::sun::star::uno::Exception));

}
#endif // INCLUDED_UCBHELPER_HANDLEINTERACTIONREQUEST_HXX
<|endoftext|>