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 { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 35 | public: |
| 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 Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 38 | xceptions_ = new t_struct(NULL); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 39 | if (oneway_ && (!returntype_->is_void())) { |
Jens Geyer | 70a5762 | 2013-06-14 18:48:15 +0200 | [diff] [blame] | 40 | pwarning(1, "Oneway methods should return void.\n"); |
| 41 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 44 | t_function(t_type* returntype, |
| 45 | std::string name, |
| 46 | t_struct* arglist, |
| 47 | t_struct* xceptions, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 48 | bool oneway = false) |
| 49 | : returntype_(returntype), |
| 50 | name_(name), |
| 51 | arglist_(arglist), |
| 52 | xceptions_(xceptions), |
| 53 | oneway_(oneway) { |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 54 | if (oneway_ && !xceptions_->get_members().empty()) { |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 55 | throw std::string("Oneway methods can't throw exceptions."); |
David Reiss | 6d94390 | 2008-03-14 00:51:42 +0000 | [diff] [blame] | 56 | } |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 57 | if (oneway_ && (!returntype_->is_void())) { |
Jens Geyer | 70a5762 | 2013-06-14 18:48:15 +0200 | [diff] [blame] | 58 | pwarning(1, "Oneway methods should return void.\n"); |
| 59 | } |
David Reiss | 6d94390 | 2008-03-14 00:51:42 +0000 | [diff] [blame] | 60 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 61 | |
| 62 | ~t_function() {} |
| 63 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 64 | t_type* get_returntype() const { return returntype_; } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 65 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 66 | const std::string& get_name() const { return name_; } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 67 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 68 | t_struct* get_arglist() const { return arglist_; } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 69 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 70 | t_struct* get_xceptions() const { return xceptions_; } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 71 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 72 | bool is_oneway() const { return oneway_; } |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 73 | |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 74 | std::map<std::string, std::string> annotations_; |
| 75 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 76 | private: |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 77 | t_type* returntype_; |
| 78 | std::string name_; |
| 79 | t_struct* arglist_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 80 | t_struct* xceptions_; |
David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 81 | bool oneway_; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | #endif |