4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [Bear] in the subject of your mails.
25
* \file script/code/string_to_arg.cpp
26
* \brief Implementation of the specialisations of the
27
* text_interface::string_to_arg class.
28
* \author Julien Jorge
30
#include "engine/script/string_to_arg.hpp"
32
/*----------------------------------------------------------------------------*/
34
* \brief Convert a string naming a base_item to a reference to this base_item,
35
* to pass as an argument for a character method.
36
* \param c The context on which the conversion is done.
37
* \param arg The string representation of the value.
39
const bear::engine::base_item&
40
bear::text_interface::string_to_arg
41
<bear::engine::script_context, const bear::engine::base_item&>::convert
42
( const engine::script_context& c, const std::string& arg )
44
const engine::base_item* item( c.get_actor_item(arg) );
48
claw::logger << claw::log_warning << "No item named '" << arg << "'"
50
throw std::invalid_argument("No item named '" + arg + "'");
54
} // string_to_arg::convert()
56
/*----------------------------------------------------------------------------*/
58
* \brief Convert a string naming a base_item to a reference to this base_item,
59
* to pass as an argument for a character method.
60
* \param c The context on which the conversion is done.
61
* \param arg The string representation of the value.
63
bear::engine::base_item&
64
bear::text_interface::string_to_arg
65
<bear::engine::script_context, bear::engine::base_item&>::convert
66
( const engine::script_context& c, const std::string& arg )
68
engine::base_item* item( c.get_actor_item(arg) );
72
claw::logger << claw::log_warning << "No item named '" << arg << "'"
74
throw std::invalid_argument("No item named '" + arg + "'");
78
} // string_to_arg::convert()
80
/*----------------------------------------------------------------------------*/
82
* \brief Convert a string naming a base_item to a reference to this base_item,
83
* to pass as an argument for a character method.
84
* \param c The context on which the conversion is done.
85
* \param arg The string representation of the value.
87
const bear::engine::script_runner&
88
bear::text_interface::string_to_arg
89
<bear::engine::script_context, const bear::engine::script_runner&>::convert
90
( const engine::script_context& c, const std::string& arg )
92
const text_interface::base_exportable<engine::script_context>*
93
item( c.get_actor(arg) );
97
claw::logger << claw::log_warning << "No item named '"
98
<< arg << "'" << std::endl;
99
throw std::invalid_argument("No item named '" + arg + "'");
103
const bear::engine::script_runner* script =
104
dynamic_cast<const bear::engine::script_runner*>(item);
106
if ( script != NULL )
110
claw::logger << claw::log_warning << "No script runner named '"
111
<< arg << "'" << std::endl;
112
throw std::invalid_argument("No script runner named '" +arg +"'");
115
} // string_to_arg::convert()
117
/*----------------------------------------------------------------------------*/
119
* \brief Convert a string naming a base_item to a reference to this base_item,
120
* to pass as an argument for a character method.
121
* \param c The context on which the conversion is done.
122
* \param arg The string representation of the value.
124
bear::engine::script_runner&
125
bear::text_interface::string_to_arg
126
<bear::engine::script_context, bear::engine::script_runner&>::convert
127
( const engine::script_context& c, const std::string& arg )
129
text_interface::base_exportable<engine::script_context>*
130
item( c.get_actor(arg) );
134
claw::logger << claw::log_warning << "No item named '"
135
<< arg << "'" << std::endl;
136
throw std::invalid_argument("No item named '" + arg + "'");
140
bear::engine::script_runner* script =
141
dynamic_cast<bear::engine::script_runner*>(item);
143
if ( script != NULL )
147
claw::logger << claw::log_warning << "No script runner named '"
148
<< arg << "'" << std::endl;
149
throw std::invalid_argument("No script runner named '" +arg +"'");
152
} // string_to_arg::convert()