blob: a72aa6c3980d85c1914752426b37cfcf4813065b [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 {
Mark Slee31985722006-05-24 21:45:31 +000035 public:
Mark Slee52f643d2006-08-09 00:03:43 +000036 t_function(t_type* returntype,
37 std::string name,
38 t_struct* arglist,
David Reiss47329252009-03-24 20:01:02 +000039 bool oneway=false) :
Mark Slee52f643d2006-08-09 00:03:43 +000040 returntype_(returntype),
41 name_(name),
42 arglist_(arglist),
David Reiss47329252009-03-24 20:01:02 +000043 oneway_(oneway) {
Mark Sleef0712dc2006-10-25 19:03:57 +000044 xceptions_ = new t_struct(NULL);
Mark Slee9cb7c612006-09-01 22:17:45 +000045 }
46
Mark Slee9cb7c612006-09-01 22:17:45 +000047 t_function(t_type* returntype,
48 std::string name,
49 t_struct* arglist,
50 t_struct* xceptions,
David Reiss47329252009-03-24 20:01:02 +000051 bool oneway=false) :
Mark Slee9cb7c612006-09-01 22:17:45 +000052 returntype_(returntype),
53 name_(name),
54 arglist_(arglist),
55 xceptions_(xceptions),
David Reiss47329252009-03-24 20:01:02 +000056 oneway_(oneway)
David Reiss6d943902008-03-14 00:51:42 +000057 {
David Reiss47329252009-03-24 20:01:02 +000058 if (oneway_ && !xceptions_->get_members().empty()) {
David Reiss6ce401d2009-03-24 20:01:58 +000059 throw std::string("Oneway methods can't throw exceptions.");
David Reiss6d943902008-03-14 00:51:42 +000060 }
61 }
Mark Slee31985722006-05-24 21:45:31 +000062
63 ~t_function() {}
64
Mark Sleef5377b32006-10-10 01:42:59 +000065 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
David Reiss47329252009-03-24 20:01:02 +000081 bool is_oneway() const {
82 return oneway_;
Mark Sleef5377b32006-10-10 01:42:59 +000083 }
Mark Sleeb15a68b2006-06-07 06:46:24 +000084
Mark Slee31985722006-05-24 21:45:31 +000085 private:
86 t_type* returntype_;
87 std::string name_;
88 t_struct* arglist_;
Mark Slee9cb7c612006-09-01 22:17:45 +000089 t_struct* xceptions_;
David Reiss47329252009-03-24 20:01:02 +000090 bool oneway_;
Mark Slee31985722006-05-24 21:45:31 +000091};
92
93#endif