Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Attr.h

Go to the documentation of this file.
00001 // $Id: Attr.h,v 1.4 2004/11/02 06:22:08 vern Exp $
00002 //
00003 // Copyright (c) 1995-2004.
00004 //      The Regents of the University of California.  All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that: (1) source code distributions
00008 // retain the above copyright notice and this paragraph in its entirety, (2)
00009 // distributions including binary code include the above copyright notice and
00010 // this paragraph in its entirety in the documentation or other materials
00011 // provided with the distribution, and (3) all advertising materials mentioning
00012 // features or use of this software display the following acknowledgement:
00013 // ``This product includes software developed by the University of California,
00014 // Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
00015 // the University nor the names of its contributors may be used to endorse
00016 // or promote products derived from this software without specific prior
00017 // written permission.
00018 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
00019 // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 
00022 #ifndef attr_h
00023 #define attr_h
00024 
00025 #include "Obj.h"
00026 
00027 class Expr;
00028 
00029 // Note that there are two kinds of attributes: the kind (here) which
00030 // modify expressions or supply metadata on types, and the kind that
00031 // are extra metadata on every variable instance.
00032 
00033 typedef enum {
00034         ATTR_OPTIONAL,
00035         ATTR_DEFAULT,
00036         ATTR_REDEF,
00037         ATTR_ROTATE_INTERVAL,
00038         ATTR_ROTATE_SIZE,
00039         ATTR_ADD_FUNC,
00040         ATTR_DEL_FUNC,
00041         ATTR_EXPIRE_FUNC,
00042         ATTR_EXPIRE_READ,
00043         ATTR_EXPIRE_WRITE,
00044         ATTR_EXPIRE_CREATE,
00045         ATTR_PERSISTENT,
00046         ATTR_SYNCHRONIZED,
00047         ATTR_POSTPROCESSOR,
00048         ATTR_ENCRYPT,
00049         ATTR_MATCH,
00050 #define NUM_ATTRS (int(ATTR_MATCH) + 1)
00051 } attr_tag;
00052 
00053 class Attr : public BroObj {
00054 public:
00055         Attr(attr_tag t, Expr* e = 0);
00056         ~Attr();
00057 
00058         attr_tag Tag() const    { return tag; }
00059         Expr* AttrExpr() const  { return expr; }
00060 
00061         int RedundantAttrOkay() const
00062                 { return tag == ATTR_REDEF || tag == ATTR_OPTIONAL; }
00063 
00064         void Describe(ODesc* d) const;
00065 
00066 protected:
00067         void AddTag(ODesc* d) const;
00068 
00069         attr_tag tag;
00070         Expr* expr;
00071 };
00072 
00073 // Manages a collection of attributes.
00074 class Attributes : public BroObj {
00075 public:
00076         Attributes(attr_list* a, BroType* t);
00077         ~Attributes();
00078 
00079         void AddAttr(Attr* a);
00080         void AddAttrs(Attributes* a);   // Unref's 'a' when done
00081 
00082         Attr* FindAttr(attr_tag t) const;
00083 
00084         void RemoveAttr(attr_tag t);
00085 
00086         void Describe(ODesc* d) const;
00087 
00088         attr_list* Attrs()      { return attrs; }
00089 
00090         bool Serialize(SerialInfo* info) const;
00091         static Attributes* Unserialize(UnserialInfo* info);
00092 
00093 protected:
00094         Attributes()    { type = 0; attrs = 0; }
00095         void CheckAttr(Attr* attr);
00096 
00097         DECLARE_SERIAL(Attributes);
00098 
00099         BroType* type;
00100         attr_list* attrs;
00101 };
00102 
00103 #endif

Generated on Wed Sep 14 02:55:57 2005 for bro_docs by doxygen 1.3.5