David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 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 | */ |
Mark Slee | e9ce01c | 2007-05-16 02:29:53 +0000 | [diff] [blame] | 19 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 20 | #ifndef T_FUNCTION_H |
| 21 | #define T_FUNCTION_H |
| 22 | |
| 23 | #include <string> |
| 24 | #include "t_type.h" |
| 25 | #include "t_struct.h" |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 26 | #include "t_doc.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 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. |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 32 | * |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 33 | */ |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 34 | class t_function : public t_doc { |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 35 | public: |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 36 | t_function(t_type* returntype, |
| 37 | std::string name, |
| 38 | t_struct* arglist, |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 39 | bool oneway=false) : |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 40 | returntype_(returntype), |
| 41 | name_(name), |
| 42 | arglist_(arglist), |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 43 | oneway_(oneway) { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 44 | xceptions_ = new t_struct(NULL); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 47 | t_function(t_type* returntype, |
| 48 | std::string name, |
| 49 | t_struct* arglist, |
| 50 | t_struct* xceptions, |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 51 | bool oneway=false) : |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 52 | returntype_(returntype), |
| 53 | name_(name), |
| 54 | arglist_(arglist), |
| 55 | xceptions_(xceptions), |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 56 | oneway_(oneway) |
David Reiss | 6d94390 | 2008-03-14 00:51:42 +0000 | [diff] [blame] | 57 | { |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 58 | if (oneway_ && !xceptions_->get_members().empty()) { |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 59 | throw std::string("Oneway methods can't throw exceptions."); |
David Reiss | 6d94390 | 2008-03-14 00:51:42 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 62 | |
| 63 | ~t_function() {} |
| 64 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 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 | |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 81 | bool is_oneway() const { |
| 82 | return oneway_; |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 83 | } |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 84 | |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame^] | 85 | std::map<std::string, std::string> annotations_; |
| 86 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 87 | private: |
| 88 | t_type* returntype_; |
| 89 | std::string name_; |
| 90 | t_struct* arglist_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 91 | t_struct* xceptions_; |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 92 | bool oneway_; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | #endif |