Branch data Line data Source code
1 : : // $Id: Attr.h 6219 2008-10-01 05:39:07Z vern $
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : : #ifndef attr_h
6 : : #define attr_h
7 : :
8 : : #include "Obj.h"
9 : :
10 : : class Expr;
11 : :
12 : : // Note that there are two kinds of attributes: the kind (here) which
13 : : // modify expressions or supply metadata on types, and the kind that
14 : : // are extra metadata on every variable instance.
15 : :
16 : : typedef enum {
17 : : ATTR_OPTIONAL,
18 : : ATTR_DEFAULT,
19 : : ATTR_REDEF,
20 : : ATTR_ROTATE_INTERVAL,
21 : : ATTR_ROTATE_SIZE,
22 : : ATTR_ADD_FUNC,
23 : : ATTR_DEL_FUNC,
24 : : ATTR_EXPIRE_FUNC,
25 : : ATTR_EXPIRE_READ,
26 : : ATTR_EXPIRE_WRITE,
27 : : ATTR_EXPIRE_CREATE,
28 : : ATTR_PERSISTENT,
29 : : ATTR_SYNCHRONIZED,
30 : : ATTR_POSTPROCESSOR,
31 : : ATTR_ENCRYPT,
32 : : ATTR_MATCH,
33 : : ATTR_DISABLE_PRINT_HOOK,
34 : : ATTR_RAW_OUTPUT,
35 : : ATTR_MERGEABLE,
36 : : ATTR_PRIORITY,
37 : : ATTR_GROUP,
38 : : ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry
39 : : #define NUM_ATTRS (int(ATTR_TRACKED) + 1)
40 : : } attr_tag;
41 : :
42 : : class Attr : public BroObj {
43 : : public:
44 : : Attr(attr_tag t, Expr* e = 0);
45 : : ~Attr();
46 : :
47 : 209269 : attr_tag Tag() const { return tag; }
48 : 25454 : Expr* AttrExpr() const { return expr; }
49 : :
50 : 1645 : int RedundantAttrOkay() const
51 [ + + ][ + + ]: 1645 : { return tag == ATTR_REDEF || tag == ATTR_OPTIONAL; }
52 : :
53 : : void Describe(ODesc* d) const;
54 : :
55 : : protected:
56 : : void AddTag(ODesc* d) const;
57 : :
58 : : attr_tag tag;
59 : : Expr* expr;
60 : : };
61 : :
62 : : // Manages a collection of attributes.
63 : : class Attributes : public BroObj {
64 : : public:
65 : : Attributes(attr_list* a, BroType* t);
66 : : ~Attributes();
67 : :
68 : : void AddAttr(Attr* a);
69 : : void AddAttrs(Attributes* a); // Unref's 'a' when done
70 : :
71 : : Attr* FindAttr(attr_tag t) const;
72 : :
73 : : void RemoveAttr(attr_tag t);
74 : :
75 : : void Describe(ODesc* d) const;
76 : :
77 : 16 : attr_list* Attrs() { return attrs; }
78 : :
79 : : bool Serialize(SerialInfo* info) const;
80 : : static Attributes* Unserialize(UnserialInfo* info);
81 : :
82 : : protected:
83 : 0 : Attributes() { type = 0; attrs = 0; }
84 : : void CheckAttr(Attr* attr);
85 : :
86 : 13 : DECLARE_SERIAL(Attributes);
87 : :
88 : : BroType* type;
89 : : attr_list* attrs;
90 : : };
91 : :
92 : : #endif
|