| Mark Slee | e9ce01c | 2007-05-16 02:29:53 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook | 
 | 2 | // Distributed under the Thrift Software License | 
 | 3 | // | 
 | 4 | // See accompanying file LICENSE or visit the Thrift site at: | 
 | 5 | // http://developers.facebook.com/thrift/ | 
 | 6 |  | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 7 | #ifndef T_FUNCTION_H | 
 | 8 | #define T_FUNCTION_H | 
 | 9 |  | 
 | 10 | #include <string> | 
 | 11 | #include "t_type.h" | 
 | 12 | #include "t_struct.h" | 
| ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 13 | #include "t_doc.h" | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 14 |  | 
 | 15 | /** | 
| Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 16 |  * Representation of a function. Key parts are return type, function name, | 
 | 17 |  * optional modifiers, and an argument list, which is implemented as a thrift | 
 | 18 |  * struct. | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 19 |  * | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 20 |  */ | 
| ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 21 | class t_function : public t_doc { | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 22 |  public: | 
| Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 23 |   t_function(t_type* returntype, | 
 | 24 |              std::string name, | 
 | 25 |              t_struct* arglist, | 
| David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 26 |              bool oneway=false) : | 
| Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 27 |     returntype_(returntype), | 
 | 28 |     name_(name), | 
 | 29 |     arglist_(arglist), | 
| David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 30 |     oneway_(oneway) { | 
| Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 31 |     xceptions_ = new t_struct(NULL); | 
| Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 32 |   } | 
 | 33 |  | 
| Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 34 |   t_function(t_type* returntype, | 
 | 35 |              std::string name, | 
 | 36 |              t_struct* arglist, | 
 | 37 |              t_struct* xceptions, | 
| David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 38 |              bool oneway=false) : | 
| Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 39 |     returntype_(returntype), | 
 | 40 |     name_(name), | 
 | 41 |     arglist_(arglist), | 
 | 42 |     xceptions_(xceptions), | 
| David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 43 |     oneway_(oneway) | 
| David Reiss | 6d94390 | 2008-03-14 00:51:42 +0000 | [diff] [blame] | 44 |   { | 
| David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 45 |     if (oneway_ && !xceptions_->get_members().empty()) { | 
| David Reiss | 6d94390 | 2008-03-14 00:51:42 +0000 | [diff] [blame] | 46 |       throw std::string("Async methods can't throw exceptions."); | 
 | 47 |     } | 
 | 48 |   } | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 49 |  | 
 | 50 |   ~t_function() {} | 
 | 51 |  | 
| Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 52 |   t_type* get_returntype() const { | 
 | 53 |     return returntype_; | 
 | 54 |   } | 
 | 55 |  | 
 | 56 |   const std::string& get_name() const { | 
 | 57 |     return name_; | 
 | 58 |   } | 
 | 59 |  | 
 | 60 |   t_struct* get_arglist() const { | 
 | 61 |     return arglist_; | 
 | 62 |   } | 
 | 63 |  | 
 | 64 |   t_struct* get_xceptions() const { | 
 | 65 |     return xceptions_; | 
 | 66 |   } | 
 | 67 |  | 
| David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 68 |   bool is_oneway() const { | 
 | 69 |     return oneway_; | 
| Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 70 |   } | 
| Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 71 |  | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 72 |  private: | 
 | 73 |   t_type* returntype_; | 
 | 74 |   std::string name_; | 
 | 75 |   t_struct* arglist_; | 
| Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 76 |   t_struct* xceptions_; | 
| David Reiss | 4732925 | 2009-03-24 20:01:02 +0000 | [diff] [blame] | 77 |   bool oneway_; | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 78 | }; | 
 | 79 |  | 
 | 80 | #endif |