1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2008, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18
19 #include <common/ac/assert.h>
20
21 #include <libaegis/introspector/error.h>
22 #include <libaegis/introspector/structure.h>
23 #include <libaegis/sub.h>
24
25
~introspector_structure()26 introspector_structure::~introspector_structure()
27 {
28 }
29
30
introspector_structure(const nstring & a_name)31 introspector_structure::introspector_structure(const nstring &a_name) :
32 name(a_name)
33 {
34 members.set_reaper();
35 }
36
37
38 introspector_structure::pointer
create(const nstring & a_name)39 introspector_structure::create(const nstring &a_name)
40 {
41 return pointer(new introspector_structure(a_name));
42 }
43
44
45 nstring
get_name() const46 introspector_structure::get_name()
47 const
48 {
49 return name;
50 }
51
52
53 introspector::pointer
field(const nstring & field_name)54 introspector_structure::field(const nstring &field_name)
55 {
56 nstring fname = field_name;
57 adapter::pointer p = members.get(fname);
58 if (!p)
59 {
60 nstring suggest = members.query_fuzzy(fname);
61 if (suggest.empty())
62 {
63 sub_context_ty sc;
64 sc.var_set_string("Name", field_name);
65 error(&sc, i18n("the name \"$name\" is undefined"));
66 return introspector_error::create();
67 }
68
69 sub_context_ty sc;
70 sc.var_set_string("Name", name);
71 sc.var_set_string("Guess", suggest);
72 error(&sc, i18n("no \"$name\", guessing \"$guess\""));
73
74 fname = suggest;
75 p = members.get(fname);
76 assert(p);
77 }
78
79 if (p->is_set() && !p->redefinition_ok())
80 {
81 sub_context_ty sc;
82 sc.var_set_string("Name", field_name);
83 error(&sc, i18n("field \"$name\" redefined"));
84 }
85
86 return p->introspector_factory();
87 }
88
89
90 // vim: set ts=8 sw=4 et :
91