blob: a72aa6c3980d85c1914752426b37cfcf4813065b [file] [log] [blame]
Gavin McDonald0b75e1a2010-10-28 02:12:01 +00001/*
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
20#ifndef T_FUNCTION_H
21#define T_FUNCTION_H
22
23#include <string>
24#include "t_type.h"
25#include "t_struct.h"
26#include "t_doc.h"
27
28/**
29 * Representation of a function. Key parts are return type, function name,
30 * optional modifiers, and an argument list, which is implemented as a thrift
31 * struct.
32 *
33 */
34class t_function : public t_doc {
35 public:
36 t_function(t_type* returntype,
37 std::string name,
38 t_struct* arglist,
39 bool oneway=false) :
40 returntype_(returntype),
41 name_(name),
42 arglist_(arglist),
43 oneway_(oneway) {
44 xceptions_ = new t_struct(NULL);
45 }
46
47 t_function(t_type* returntype,
48 std::string name,
49 t_struct* arglist,
50 t_struct* xceptions,
51 bool oneway=false) :
52 returntype_(returntype),
53 name_(name),
54 arglist_(arglist),
55 xceptions_(xceptions),
56 oneway_(oneway)
57 {
58 if (oneway_ && !xceptions_->get_members().empty()) {
59 throw std::string("Oneway methods can't throw exceptions.");
60 }
61 }
62
63 ~t_function() {}
64
65 t_type* get_returntype() const {
66 return returntype_;
67 }
68
69 const std::string& get_name() const {
70 return name_;
71 }
72
73 t_struct* get_arglist() const {
74 return arglist_;
75 }
76
77 t_struct* get_xceptions() const {
78 return xceptions_;
79 }
80
81 bool is_oneway() const {
82 return oneway_;
83 }
84
85 private:
86 t_type* returntype_;
87 std::string name_;
88 t_struct* arglist_;
89 t_struct* xceptions_;
90 bool oneway_;
91};
92
93#endif