Fix bug when passing type with holder by value to Lua.
[luabind.git] / luabind / detail / method_rep.hpp
blob8844d624c6a6ffddb7783c6b8364ee504717c63a
1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef LUABIND_METHOD_REP_HPP_INCLUDED
25 #define LUABIND_METHOD_REP_HPP_INCLUDED
27 #include <luabind/config.hpp>
29 #include <vector>
31 #include <luabind/detail/overload_rep.hpp>
33 namespace luabind { namespace detail
36 class class_rep;
39 contains information about a method. It contains
40 a list of all overloads of the function. If a class
41 derives from another class all methods and overloads
42 are copied into the derived class and the pointer
43 offset is applied to each copied method. The pointer
44 offset is needed because if the method is called
45 on a derived object the method needs a pointer
46 to the base class, and that typecast may need
47 an offseted pointer (if multiple inheritance is used).
49 struct method_rep
51 void add_overload(const overload_rep& o)
53 std::vector<overload_rep>::iterator i = std::find(m_overloads.begin(), m_overloads.end(), o);
54 if (i == m_overloads.end())
56 // if this overload does not exist, we can just add it to the end of the overloads list
57 m_overloads.push_back(o);
59 else
61 // if this specific overload already exists, replace it
62 *i = o;
65 const std::vector<overload_rep>& overloads() const throw() { return m_overloads; }
67 // this is a pointer to the string kept in class_rep::m_methods, and those strings are deleted
68 // at the end of the lua session.
69 const char* name;
71 // the class_rep in which this method_rep is found
72 const class_rep* crep;
74 private:
75 // this have to be write protected, since each time an overload is
76 // added it has to be checked for existence. add_overload() should
77 // be used.
78 std::vector<overload_rep> m_overloads;
83 #endif // LUABIND_METHOD_REP_HPP_INCLUDED