blob: 1caf54a3863aaeb7ed201defe7752e74ad4031bc [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001#ifndef T_FUNCTION_H
2#define T_FUNCTION_H
3
4#include <string>
5#include "t_type.h"
6#include "t_struct.h"
7
8/**
9 * Representation of a function. Key parst are return type, function name,
10 * optional modifiers, and an argument list. Each function also has a
11 * hash signature that is used in the network protocol.
12 *
13 * @author Mark Slee <mcslee@facebook.com>
14 */
15class t_function {
16 public:
17 t_function(t_type* returntype, std::string name, t_struct* arglist) :
18 returntype_(returntype), name_(name), arglist_(arglist) {}
19
20 ~t_function() {}
21
22 /**
23 * Implementation of the Fowler / Noll / Vo (FNV) Hash
24 * http://www.isthe.com/chongo/tech/comp/fnv/
25 */
26 static uint32_t fnv32(const char *s) {
27 uint32_t hash = (uint32_t)216613626;
28 while (*s) {
29 hash +=
30 (hash << 1) +
31 (hash << 4) +
32 (hash << 7) +
33 (hash << 8) +
34 (hash << 24);
35 hash ^= *s++;
36 }
37 return hash;
38 }
39
40 t_type* get_returntype() const { return returntype_; }
41 const std::string& get_name() const { return name_; }
42 t_struct* get_arglist() const { return arglist_; }
43 uint32_t get_hash() const { return fnv32(name_.c_str()); }
44
45 private:
46 t_type* returntype_;
47 std::string name_;
48 t_struct* arglist_;
49};
50
51#endif