blob: 96886f3269cf0479f6691d0cb915c47f8991d1c3 [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 Grochowski16a23a62014-11-13 15:33:38 +010035public:
36 t_function(t_type* returntype, std::string name, t_struct* arglist, bool oneway = false)
37 : returntype_(returntype), name_(name), arglist_(arglist), oneway_(oneway) {
Mark Sleef0712dc2006-10-25 19:03:57 +000038 xceptions_ = new t_struct(NULL);
Konrad Grochowski16a23a62014-11-13 15:33:38 +010039 if (oneway_ && (!returntype_->is_void())) {
Jens Geyer70a57622013-06-14 18:48:15 +020040 pwarning(1, "Oneway methods should return void.\n");
41 }
Mark Slee9cb7c612006-09-01 22:17:45 +000042 }
43
Mark Slee9cb7c612006-09-01 22:17:45 +000044 t_function(t_type* returntype,
45 std::string name,
46 t_struct* arglist,
47 t_struct* xceptions,
Konrad Grochowski16a23a62014-11-13 15:33:38 +010048 bool oneway = false)
49 : returntype_(returntype),
50 name_(name),
51 arglist_(arglist),
52 xceptions_(xceptions),
53 oneway_(oneway) {
David Reiss47329252009-03-24 20:01:02 +000054 if (oneway_ && !xceptions_->get_members().empty()) {
David Reiss6ce401d2009-03-24 20:01:58 +000055 throw std::string("Oneway methods can't throw exceptions.");
David Reiss6d943902008-03-14 00:51:42 +000056 }
Konrad Grochowski16a23a62014-11-13 15:33:38 +010057 if (oneway_ && (!returntype_->is_void())) {
Jens Geyer70a57622013-06-14 18:48:15 +020058 pwarning(1, "Oneway methods should return void.\n");
59 }
David Reiss6d943902008-03-14 00:51:42 +000060 }
Mark Slee31985722006-05-24 21:45:31 +000061
62 ~t_function() {}
63
Konrad Grochowski16a23a62014-11-13 15:33:38 +010064 t_type* get_returntype() const { return returntype_; }
Mark Sleef5377b32006-10-10 01:42:59 +000065
Konrad Grochowski16a23a62014-11-13 15:33:38 +010066 const std::string& get_name() const { return name_; }
Mark Sleef5377b32006-10-10 01:42:59 +000067
Konrad Grochowski16a23a62014-11-13 15:33:38 +010068 t_struct* get_arglist() const { return arglist_; }
Mark Sleef5377b32006-10-10 01:42:59 +000069
Konrad Grochowski16a23a62014-11-13 15:33:38 +010070 t_struct* get_xceptions() const { return xceptions_; }
Mark Sleef5377b32006-10-10 01:42:59 +000071
Konrad Grochowski16a23a62014-11-13 15:33:38 +010072 bool is_oneway() const { return oneway_; }
Mark Sleeb15a68b2006-06-07 06:46:24 +000073
Roger Meier30877382012-09-17 21:18:05 +000074 std::map<std::string, std::string> annotations_;
75
Konrad Grochowski16a23a62014-11-13 15:33:38 +010076private:
Mark Slee31985722006-05-24 21:45:31 +000077 t_type* returntype_;
78 std::string name_;
79 t_struct* arglist_;
Mark Slee9cb7c612006-09-01 22:17:45 +000080 t_struct* xceptions_;
David Reiss47329252009-03-24 20:01:02 +000081 bool oneway_;
Mark Slee31985722006-05-24 21:45:31 +000082};
83
84#endif