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 */ 19 20 #ifndef T_FUNCTION_H 21 #define T_FUNCTION_H 22 23 #include "thrift/parse/t_doc.h" 24 #include "thrift/parse/t_struct.h" 25 #include "thrift/parse/t_type.h" 26 #include <string> 27 28 /** 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. 32 * 33 */ 34 class t_function : public t_doc { 35 public: 36 t_function(t_type* returntype, std::string name, t_struct* arglist, bool oneway = false) returntype_(returntype)37 : returntype_(returntype), 38 name_(name), 39 arglist_(arglist), 40 xceptions_(new t_struct(nullptr)), 41 own_xceptions_(true), 42 oneway_(oneway) { 43 xceptions_->set_method_xcepts(true); 44 if (oneway_ && (!returntype_->is_void())) { 45 pwarning(1, "Oneway methods should return void.\n"); 46 } 47 } 48 49 t_function(t_type* returntype, 50 std::string name, 51 t_struct* arglist, 52 t_struct* xceptions, 53 bool oneway = false) returntype_(returntype)54 : returntype_(returntype), 55 name_(name), 56 arglist_(arglist), 57 xceptions_(xceptions), 58 own_xceptions_(false), 59 oneway_(oneway) { 60 xceptions_->set_method_xcepts(true); 61 if (oneway_ && !xceptions_->get_members().empty()) { 62 throw std::string("Oneway methods can't throw exceptions."); 63 } 64 if (oneway_ && (!returntype_->is_void())) { 65 pwarning(1, "Oneway methods should return void.\n"); 66 } 67 } 68 ~t_function()69 ~t_function() override { 70 if (own_xceptions_) 71 delete xceptions_; 72 } 73 get_returntype()74 t_type* get_returntype() const { return returntype_; } 75 get_name()76 const std::string& get_name() const { return name_; } 77 get_arglist()78 t_struct* get_arglist() const { return arglist_; } 79 get_xceptions()80 t_struct* get_xceptions() const { return xceptions_; } 81 is_oneway()82 bool is_oneway() const { return oneway_; } 83 84 std::map<std::string, std::vector<std::string>> annotations_; 85 86 private: 87 t_type* returntype_; 88 std::string name_; 89 t_struct* arglist_; 90 t_struct* xceptions_; 91 bool own_xceptions_; 92 bool oneway_; 93 }; 94 95 #endif 96