~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to bear-engine/core/src/engine/script/code/string_to_arg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Bear Engine
 
3
 
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
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.
 
10
 
 
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
 
14
  more details.
 
15
 
 
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
 
19
 
 
20
  contact: plee-the-bear@gamned.org
 
21
 
 
22
  Please add the tag [Bear] in the subject of your mails.
 
23
*/
 
24
/**
 
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
 
29
 */
 
30
#include "engine/script/string_to_arg.hpp"
 
31
 
 
32
/*----------------------------------------------------------------------------*/
 
33
/**
 
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.
 
38
 */
 
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 )
 
43
{
 
44
  const engine::base_item* item( c.get_actor_item(arg) );
 
45
 
 
46
  if ( item == NULL )
 
47
    {
 
48
      claw::logger << claw::log_warning << "No item named '" << arg << "'"
 
49
                   << std::endl;
 
50
      throw std::invalid_argument("No item named '" + arg + "'");
 
51
    }
 
52
  else
 
53
    return *item;
 
54
} // string_to_arg::convert()
 
55
 
 
56
/*----------------------------------------------------------------------------*/
 
57
/**
 
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.
 
62
 */
 
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 )
 
67
{
 
68
  engine::base_item* item( c.get_actor_item(arg) );
 
69
 
 
70
  if ( item == NULL )
 
71
    {
 
72
      claw::logger << claw::log_warning << "No item named '" << arg << "'"
 
73
                   << std::endl;
 
74
      throw std::invalid_argument("No item named '" + arg + "'");
 
75
    }
 
76
  else
 
77
    return *item;
 
78
} // string_to_arg::convert()
 
79
 
 
80
/*----------------------------------------------------------------------------*/
 
81
/**
 
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.
 
86
 */
 
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 )
 
91
{
 
92
  const text_interface::base_exportable<engine::script_context>*
 
93
    item( c.get_actor(arg) );
 
94
 
 
95
  if ( item == NULL )
 
96
    {
 
97
      claw::logger << claw::log_warning << "No item named '"
 
98
                   << arg << "'" << std::endl;
 
99
      throw std::invalid_argument("No item named '" + arg + "'");
 
100
    }
 
101
  else
 
102
    {
 
103
      const bear::engine::script_runner* script =
 
104
        dynamic_cast<const bear::engine::script_runner*>(item);
 
105
 
 
106
      if ( script != NULL )
 
107
        return *script;
 
108
      else
 
109
        {
 
110
          claw::logger << claw::log_warning << "No script runner named '"
 
111
                       << arg << "'" << std::endl;
 
112
          throw std::invalid_argument("No script runner named '" +arg +"'");
 
113
        }
 
114
    }
 
115
} // string_to_arg::convert()
 
116
 
 
117
/*----------------------------------------------------------------------------*/
 
118
/**
 
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.
 
123
 */
 
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 )
 
128
{
 
129
  text_interface::base_exportable<engine::script_context>*
 
130
    item( c.get_actor(arg) );
 
131
 
 
132
  if ( item == NULL )
 
133
    {
 
134
      claw::logger << claw::log_warning << "No item named '"
 
135
                   << arg << "'" << std::endl;
 
136
      throw std::invalid_argument("No item named '" + arg + "'");
 
137
    }
 
138
  else
 
139
    {
 
140
      bear::engine::script_runner* script =
 
141
        dynamic_cast<bear::engine::script_runner*>(item);
 
142
 
 
143
      if ( script != NULL )
 
144
        return *script;
 
145
      else
 
146
        {
 
147
          claw::logger << claw::log_warning << "No script runner named '"
 
148
                       << arg << "'" << std::endl;
 
149
          throw std::invalid_argument("No script runner named '" +arg +"'");
 
150
        }
 
151
    }
 
152
} // string_to_arg::convert()