Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 112 lines (91 sloc) 2.562 kB
6774809 @NotFound initial support for extern function
authored
1 // winxedxx_namespace.cxx
2
3 // (C) 2012 Julián Albo "NotFound"
4
5 #include "winxedxx_namespace.h"
56b775a @NotFound implement namespace operator and improve NameSpace and Sub
authored
6 #include "winxedxx_integer.h"
6774809 @NotFound initial support for extern function
authored
7
8 namespace WinxedXX
9 {
10
11 typedef std::map<std::string, WxxObjectPtr> symbols_t;
08b49ff @NotFound more improvements in runtime namespaces and a few cleaning
authored
12 typedef std::map<std::string, WxxNamespace *> childs_t;
6774809 @NotFound initial support for extern function
authored
13
14 WxxNamespace::WxxNamespace() :
56b775a @NotFound implement namespace operator and improve NameSpace and Sub
authored
15 WxxDefault("NameSpace"),
16 name("winxedxx"),
6774809 @NotFound initial support for extern function
authored
17 parentns(0)
18 {
19 }
20
56b775a @NotFound implement namespace operator and improve NameSpace and Sub
authored
21 WxxNamespace::WxxNamespace(const std::string &nsname, WxxNamespace *parent) :
22 WxxDefault("NameSpace"),
23 name(nsname),
6774809 @NotFound initial support for extern function
authored
24 parentns(parent)
25 {
26 }
27
28 WxxObjectPtr WxxNamespace::get(const std::string &name)
29 {
30 symbols_t::const_iterator it = symbols.find(name);
31 if (it == symbols.end())
32 return winxedxxnull;
33 return WxxObjectPtr(it->second);
34 }
35
7727324 @NotFound search symbols in runtime scope
authored
36 WxxObjectPtr WxxNamespace::find_symbol(const std::string &name)
37 {
38 symbols_t::const_iterator it = symbols.find(name);
39 if (it == symbols.end()) {
40 if (parentns)
41 return parentns->find_symbol(name);
42 else
43 return winxedxxnull;
44 }
45 return WxxObjectPtr(it->second);
46 }
47
08b49ff @NotFound more improvements in runtime namespaces and a few cleaning
authored
48 WxxNamespace &WxxNamespace::childNamespace(const std::string &name)
49 {
50 childs_t::const_iterator it = childs.find(name);
51 if (it == childs.end()) {
52 WxxNamespace *child = new WxxNamespace(name, this);
53 childs[name] = child;
54 return *child;
55 }
56 return *it->second;
57 }
58
6774809 @NotFound initial support for extern function
authored
59 void WxxNamespace::set(const std::string &name, const WxxObjectPtr &value)
60 {
61 symbols[name] = value;
62 }
63
56b775a @NotFound implement namespace operator and improve NameSpace and Sub
authored
64 std::string WxxNamespace::get_string()
65 {
66 return name;
67 }
68
69 WxxObjectPtr WxxNamespace::get_pmc_keyed(const std::string &s)
70 {
71 return get(s);
72 }
73
843cfbd @NotFound improve a bit set_pmc_keyed string and implement it in Namespace
authored
74 void WxxNamespace::set_pmc_keyed(const std::string &s, const WxxObjectPtr &value)
75 {
76 set(s, value);
77 }
78
56b775a @NotFound implement namespace operator and improve NameSpace and Sub
authored
79 WxxObjectPtr WxxNamespace::call_method(const std::string &methname, WxxObjectArray &args)
80 {
81 if (methname == "get_parent")
82 return parentns ? parentns : winxedxxnull;
83 else if (methname == "find_var")
84 return get(args.get_string_keyed(0));
85 else if (methname == "add_var") {
86 set(args.get_string_keyed(0), args.get_pmc_keyed(1));
87 return winxedxxnull;
88 }
89 else
90 return WxxDefault::call_method(methname, args);
91 }
92
6774809 @NotFound initial support for extern function
authored
93 //**************************************************************
94
95 class WxxRootNamespace : WxxNamespace
96 {
97 friend WxxNamespace &getRootNamespace();
98 };
99
100 static WxxRootNamespace *rootnamespace = 0;
101
102 WxxNamespace &getRootNamespace()
103 {
104 if (! rootnamespace)
105 rootnamespace = new WxxRootNamespace();
106 return *rootnamespace;
107 }
108
109 } // namespace WinxedXX
110
111 // End of winxedxx_namespace.cxx
Something went wrong with that request. Please try again.