]> git.buserror.net Git - polintos/scott/priv.git/blob - idlcomp/cdl.h
Add copyright to idlcomp files that were previously just "Written by:".
[polintos/scott/priv.git] / idlcomp / cdl.h
1 // Types which are only used when compiling CDL files
2 //
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
4 // 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal with
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 // of the Software, and to permit persons to whom the Software is furnished to do
10 // so, subject to the following condition:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
21 // SOFTWARE.
22
23
24 #ifndef CDL_H
25 #define CDL_H
26
27 #include <idlc.h>
28
29 class Class;
30 typedef Ref<Class> ClassRef;
31
32 extern list<ClassRef> classes;
33
34 class Class : public NameSpace {
35         list<InterfaceRef> ifaces;
36
37 public:
38         struct ParamInfo : public RefCountable<ParamInfo> {
39                 bool copy;
40         };
41
42         typedef Ref<ParamInfo> ParamInfoRef;
43
44 private:
45         // C++ associative arrays are much more of a 
46         // pain to use than they should be.
47
48         typedef map<ParamRef, ParamInfoRef> params_map_type;
49         typedef params_map_type::value_type params_valtype;
50         typedef params_map_type::const_iterator params_iter;
51
52 public:
53         struct MethodInfo : public RefCountable<MethodInfo> {
54                 StrListRef implname;
55                 bool copy_params; // True if at least one parameter
56                                   // has the copy attribute.
57
58         private:
59                 params_map_type params;
60         
61         public:
62                 ParamInfo *get_param(Param *p)
63                 {
64                         params_iter ret = params.find(p);
65                         
66                         if (ret != params.end())
67                                 return (*ret).second;
68                         
69                         return NULL;
70                 }
71                 
72                 ParamInfo *add_param(Param *p)
73                 {
74                         ParamInfo *pi = get_param(p);
75                 
76                         if (!pi) {
77                                 pi = new ParamInfo;
78                                 pi->copy = false;
79                                 
80                                 pair<params_iter, bool> ret = 
81                                         params.insert(params_valtype(p, pi));
82         
83                                 assert(ret.second);
84                         }
85                 
86                         return pi;
87                 }
88         };
89
90         typedef Ref<MethodInfo> MethodInfoRef;
91
92 private:
93         typedef map<MethodRef, MethodInfoRef> method_map_type;
94         typedef method_map_type::value_type methods_valtype;
95         typedef method_map_type::const_iterator methods_iter;
96
97         method_map_type methods;
98
99 public:
100         InterfaceRef concrete_iface;
101
102         Class(const String *name) :
103         Symbol(name), concrete_iface(new Interface(new String("<anon>")))
104         {
105                 classes.push_back(this);
106         }
107         
108         void add_iface(Interface *iface)
109         {
110                 ifaces.push_back(iface);
111                 concrete_iface->add_super(iface);
112         }
113         
114         MethodInfo *get_method(Method *m)
115         {
116                 methods_iter ret = methods.find(m);
117                 
118                 if (ret != methods.end())
119                         return (*ret).second;
120                 
121                 return NULL;
122         }
123         
124         MethodInfo *add_method(Method *m)
125         {
126                 MethodInfo *mi = get_method(m);
127
128                 if (!mi) {
129                         mi = new MethodInfo;
130                         mi->copy_params = false;
131                         
132                         pair<methods_iter, bool> ret = 
133                                 methods.insert(methods_valtype(m, mi));
134
135                         assert(ret.second);
136                 }
137                 
138                 return mi;
139         }
140
141         typedef list<InterfaceRef>::const_iterator ifaces_iterator;
142
143         ifaces_iterator ifaces_begin()
144         {
145                 return ifaces.begin();
146         }
147
148         ifaces_iterator ifaces_end()
149         {
150                 return ifaces.end();
151         }
152         
153         // FIXME: check for duplicate method implementation names.
154         void finalize()
155         {
156                 concrete_iface->finalize_class_iface();
157         }
158 };
159
160 #endif