blob: 74dac6350593a90e02fb0887e3683e98fc2855b5 [file] [log] [blame]
Mark Sleee9ce01c2007-05-16 02:29:53 +00001// 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 Slee31985722006-05-24 21:45:31 +00007#ifndef T_FUNCTION_H
8#define T_FUNCTION_H
9
10#include <string>
11#include "t_type.h"
12#include "t_struct.h"
ccheeverf53b5cf2007-02-05 20:33:11 +000013#include "t_doc.h"
Mark Slee31985722006-05-24 21:45:31 +000014
15/**
Mark Sleef5377b32006-10-10 01:42:59 +000016 * 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 Slee31985722006-05-24 21:45:31 +000019 *
20 * @author Mark Slee <mcslee@facebook.com>
21 */
ccheeverf53b5cf2007-02-05 20:33:11 +000022class t_function : public t_doc {
Mark Slee31985722006-05-24 21:45:31 +000023 public:
Mark Slee52f643d2006-08-09 00:03:43 +000024 t_function(t_type* returntype,
25 std::string name,
26 t_struct* arglist,
27 bool async=false) :
28 returntype_(returntype),
29 name_(name),
30 arglist_(arglist),
Mark Slee9cb7c612006-09-01 22:17:45 +000031 async_(async) {
Mark Sleef0712dc2006-10-25 19:03:57 +000032 xceptions_ = new t_struct(NULL);
Mark Slee9cb7c612006-09-01 22:17:45 +000033 }
34
Mark Slee9cb7c612006-09-01 22:17:45 +000035 t_function(t_type* returntype,
36 std::string name,
37 t_struct* arglist,
38 t_struct* xceptions,
39 bool async=false) :
40 returntype_(returntype),
41 name_(name),
42 arglist_(arglist),
43 xceptions_(xceptions),
David Reiss6d943902008-03-14 00:51:42 +000044 async_(async)
45 {
46 if (async_ && !xceptions_->get_members().empty()) {
47 throw std::string("Async methods can't throw exceptions.");
48 }
49 }
Mark Slee31985722006-05-24 21:45:31 +000050
51 ~t_function() {}
52
Mark Sleef5377b32006-10-10 01:42:59 +000053 t_type* get_returntype() const {
54 return returntype_;
55 }
56
57 const std::string& get_name() const {
58 return name_;
59 }
60
61 t_struct* get_arglist() const {
62 return arglist_;
63 }
64
65 t_struct* get_xceptions() const {
66 return xceptions_;
67 }
68
69 bool is_async() const {
70 return async_;
71 }
Mark Sleeb15a68b2006-06-07 06:46:24 +000072
Mark Slee31985722006-05-24 21:45:31 +000073 private:
74 t_type* returntype_;
75 std::string name_;
76 t_struct* arglist_;
Mark Slee9cb7c612006-09-01 22:17:45 +000077 t_struct* xceptions_;
Mark Slee52f643d2006-08-09 00:03:43 +000078 bool async_;
Mark Slee31985722006-05-24 21:45:31 +000079};
80
81#endif