Line data Source code
1 : /*
2 : * Licensed to the Apache Software Foundation (ASF) under one
3 : * or more contributor license agreements. See the NOTICE file
4 : * distributed with this work for additional information
5 : * regarding copyright ownership. The ASF licenses this file
6 : * to you under the Apache License, Version 2.0 (the
7 : * "License"); you may not use this file except in compliance
8 : * with the License. You may obtain a copy of the License at
9 : *
10 : * http://www.apache.org/licenses/LICENSE-2.0
11 : *
12 : * Unless required by applicable law or agreed to in writing,
13 : * software distributed under the License is distributed on an
14 : * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 : * KIND, either express or implied. See the License for the
16 : * specific language governing permissions and limitations
17 : * under the License.
18 : *
19 : * Modifications Copyright (c) Juniper Networks, Inc.
20 : * Copyright Contributors to the OpenSDN project
21 : */
22 :
23 : #ifndef T_FUNCTION_H
24 : #define T_FUNCTION_H
25 :
26 : #include <string>
27 : #include "t_type.h"
28 : #include "t_struct.h"
29 : #include "t_doc.h"
30 :
31 : /**
32 : * Representation of a function. Key parts are return type, function name,
33 : * optional modifiers, and an argument list, which is implemented as a thrift
34 : * struct.
35 : *
36 : */
37 : class t_function : public t_doc {
38 : public:
39 0 : t_function(t_type* returntype,
40 : std::string name,
41 : t_struct* arglist,
42 : bool oneway=false
43 : #ifdef SANDESH
44 : ,
45 : bool is_virtual=false,
46 : bool is_static=false
47 : #endif
48 0 : ) :
49 0 : returntype_(returntype),
50 0 : name_(name),
51 0 : arglist_(arglist),
52 0 : oneway_(oneway),
53 : #ifdef SANDESH
54 0 : virtual_(is_virtual),
55 0 : static_(is_static)
56 : #endif
57 : {
58 0 : xceptions_ = new t_struct(NULL);
59 0 : }
60 :
61 0 : t_function(t_type* returntype,
62 : std::string name,
63 : t_struct* arglist,
64 : t_struct* xceptions,
65 : bool oneway=false
66 : #ifdef SANDESH
67 : ,
68 : bool is_virtual=false,
69 : bool is_static=false
70 : #endif
71 0 : ) :
72 0 : returntype_(returntype),
73 0 : name_(name),
74 0 : arglist_(arglist),
75 0 : xceptions_(xceptions),
76 0 : oneway_(oneway)
77 : #ifdef SANDESH
78 : ,
79 0 : virtual_(is_virtual),
80 0 : static_(is_static)
81 : #endif
82 : {
83 0 : if (oneway_ && !xceptions_->get_members().empty()) {
84 0 : throw std::string("Oneway methods can't throw exceptions.");
85 : }
86 0 : }
87 :
88 0 : ~t_function() {}
89 :
90 0 : t_type* get_returntype() const {
91 0 : return returntype_;
92 : }
93 :
94 0 : const std::string& get_name() const {
95 0 : return name_;
96 : }
97 :
98 0 : t_struct* get_arglist() const {
99 0 : return arglist_;
100 : }
101 :
102 0 : t_struct* get_xceptions() const {
103 0 : return xceptions_;
104 : }
105 :
106 0 : bool is_oneway() const {
107 0 : return oneway_;
108 : }
109 : #ifdef SANDESH
110 0 : bool is_virtual() const {
111 0 : return virtual_;
112 : }
113 :
114 0 : bool is_static() const {
115 0 : return static_;
116 : }
117 : #endif
118 :
119 : private:
120 : t_type* returntype_;
121 : std::string name_;
122 : t_struct* arglist_;
123 : t_struct* xceptions_;
124 : bool oneway_;
125 : #ifdef SANDESH
126 : bool virtual_;
127 : bool static_;
128 : #endif
129 : };
130 :
131 : #endif
|