blob: ae8c2f605d8dc04270517a5635d657afe676edeb [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +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 */
Mark Sleee9ce01c2007-05-16 02:29:53 +000019
Mark Slee31985722006-05-24 21:45:31 +000020#ifndef T_FUNCTION_H
21#define T_FUNCTION_H
22
23#include <string>
24#include "t_type.h"
25#include "t_struct.h"
ccheeverf53b5cf2007-02-05 20:33:11 +000026#include "t_doc.h"
Mark Slee31985722006-05-24 21:45:31 +000027
28/**
Mark Sleef5377b32006-10-10 01:42:59 +000029 * 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.
Mark Slee31985722006-05-24 21:45:31 +000032 *
Mark Slee31985722006-05-24 21:45:31 +000033 */
ccheeverf53b5cf2007-02-05 20:33:11 +000034class t_function : public t_doc {
Konrad Grochowski240120c2014-11-18 11:33:31 +010035 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) {
Mark Sleef0712dc2006-10-25 19:03:57 +000044 xceptions_ = new t_struct(NULL);
Konrad Grochowski240120c2014-11-18 11:33:31 +010045 if (oneway_ && (! returntype_->is_void())) {
Jens Geyer70a57622013-06-14 18:48:15 +020046 pwarning(1, "Oneway methods should return void.\n");
47 }
Mark Slee9cb7c612006-09-01 22:17:45 +000048 }
49
Mark Slee9cb7c612006-09-01 22:17:45 +000050 t_function(t_type* returntype,
51 std::string name,
52 t_struct* arglist,
53 t_struct* xceptions,
Konrad Grochowski240120c2014-11-18 11:33:31 +010054 bool oneway=false) :
55 returntype_(returntype),
56 name_(name),
57 arglist_(arglist),
58 xceptions_(xceptions),
59 oneway_(oneway)
60 {
David Reiss47329252009-03-24 20:01:02 +000061 if (oneway_ && !xceptions_->get_members().empty()) {
David Reiss6ce401d2009-03-24 20:01:58 +000062 throw std::string("Oneway methods can't throw exceptions.");
David Reiss6d943902008-03-14 00:51:42 +000063 }
Konrad Grochowski240120c2014-11-18 11:33:31 +010064 if (oneway_ && (! returntype_->is_void())) {
Jens Geyer70a57622013-06-14 18:48:15 +020065 pwarning(1, "Oneway methods should return void.\n");
66 }
David Reiss6d943902008-03-14 00:51:42 +000067 }
Mark Slee31985722006-05-24 21:45:31 +000068
69 ~t_function() {}
70
Konrad Grochowski240120c2014-11-18 11:33:31 +010071 t_type* get_returntype() const {
72 return returntype_;
73 }
Mark Sleef5377b32006-10-10 01:42:59 +000074
Konrad Grochowski240120c2014-11-18 11:33:31 +010075 const std::string& get_name() const {
76 return name_;
77 }
Mark Sleef5377b32006-10-10 01:42:59 +000078
Konrad Grochowski240120c2014-11-18 11:33:31 +010079 t_struct* get_arglist() const {
80 return arglist_;
81 }
Mark Sleef5377b32006-10-10 01:42:59 +000082
Konrad Grochowski240120c2014-11-18 11:33:31 +010083 t_struct* get_xceptions() const {
84 return xceptions_;
85 }
Mark Sleef5377b32006-10-10 01:42:59 +000086
Konrad Grochowski240120c2014-11-18 11:33:31 +010087 bool is_oneway() const {
88 return oneway_;
89 }
Mark Sleeb15a68b2006-06-07 06:46:24 +000090
Roger Meier30877382012-09-17 21:18:05 +000091 std::map<std::string, std::string> annotations_;
92
Konrad Grochowski240120c2014-11-18 11:33:31 +010093 private:
Mark Slee31985722006-05-24 21:45:31 +000094 t_type* returntype_;
95 std::string name_;
96 t_struct* arglist_;
Mark Slee9cb7c612006-09-01 22:17:45 +000097 t_struct* xceptions_;
David Reiss47329252009-03-24 20:01:02 +000098 bool oneway_;
Mark Slee31985722006-05-24 21:45:31 +000099};
100
101#endif