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