Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 95 lines (76 sloc) 2.142 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
08b49ff @NotFound more improvements in runtime namespaces and a few cleaning
authored
36 WxxNamespace &WxxNamespace::childNamespace(const std::string &name)
37 {
38 childs_t::const_iterator it = childs.find(name);
39 if (it == childs.end()) {
40 WxxNamespace *child = new WxxNamespace(name, this);
41 childs[name] = child;
42 return *child;
43 }
44 return *it->second;
45 }
46
6774809 @NotFound initial support for extern function
authored
47 void WxxNamespace::set(const std::string &name, const WxxObjectPtr &value)
48 {
49 symbols[name] = value;
50 }
51
56b775a @NotFound implement namespace operator and improve NameSpace and Sub
authored
52 std::string WxxNamespace::get_string()
53 {
54 return name;
55 }
56
57 WxxObjectPtr WxxNamespace::get_pmc_keyed(const std::string &s)
58 {
59 return get(s);
60 }
61
62 WxxObjectPtr WxxNamespace::call_method(const std::string &methname, WxxObjectArray &args)
63 {
64 if (methname == "get_parent")
65 return parentns ? parentns : winxedxxnull;
66 else if (methname == "find_var")
67 return get(args.get_string_keyed(0));
68 else if (methname == "add_var") {
69 set(args.get_string_keyed(0), args.get_pmc_keyed(1));
70 return winxedxxnull;
71 }
72 else
73 return WxxDefault::call_method(methname, args);
74 }
75
6774809 @NotFound initial support for extern function
authored
76 //**************************************************************
77
78 class WxxRootNamespace : WxxNamespace
79 {
80 friend WxxNamespace &getRootNamespace();
81 };
82
83 static WxxRootNamespace *rootnamespace = 0;
84
85 WxxNamespace &getRootNamespace()
86 {
87 if (! rootnamespace)
88 rootnamespace = new WxxRootNamespace();
89 return *rootnamespace;
90 }
91
92 } // namespace WinxedXX
93
94 // End of winxedxx_namespace.cxx
Something went wrong with that request. Please try again.