xorp

operator_base.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License, Version 2, June
00008 // 1991 as published by the Free Software Foundation. Redistribution
00009 // and/or modification of this program under the terms of any other
00010 // version of the GNU General Public License is not permitted.
00011 // 
00012 // This program is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00015 // see the GNU General Public License, Version 2, a copy of which can be
00016 // found in the XORP LICENSE.gpl file.
00017 // 
00018 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00019 // http://xorp.net
00020 
00021 // $XORP: xorp/policy/common/operator_base.hh,v 1.9 2008/10/02 21:58:07 bms Exp $
00022 
00023 #ifndef __POLICY_COMMON_OPERATOR_BASE_HH__
00024 #define __POLICY_COMMON_OPERATOR_BASE_HH__
00025 
00026 
00027 
00028 #include "policy/policy_module.h"
00029 #include "libxorp/xlog.h"
00030 
00031 enum {
00032     HASH_OP_AND = 1,
00033     HASH_OP_OR,
00034     HASH_OP_XOR,
00035     HASH_OP_NOT,
00036     HASH_OP_EQ,
00037     HASH_OP_NE,
00038     HASH_OP_LT,
00039     HASH_OP_GT,
00040     HASH_OP_LE,
00041     HASH_OP_GE,
00042     HASH_OP_ADD,
00043     HASH_OP_SUB,
00044     HASH_OP_MUL,
00045     HASH_OP_REGEX,
00046     HASH_OP_CTR,
00047     HASH_OP_NEINT,
00048     HASH_OP_HEAD,
00049     HASH_OP_MAX = 32 // last
00050 };
00051 
00058 class Oper {
00059 public:
00060     typedef unsigned char Hash;
00061 
00062     Oper(Hash hash, unsigned arity) : _hash(hash), _arity(arity)
00063     {
00064     XLOG_ASSERT(_hash < HASH_OP_MAX);
00065     }
00066 
00067     virtual ~Oper() {};
00068 
00072     unsigned arity() const { return _arity; }
00073 
00079     virtual string str() const = 0;
00080 
00081     Hash hash() const { return _hash; }
00082 
00083 private:
00084     Hash    _hash;
00085     unsigned    _arity;
00086 };
00087 
00091 class UnOper : public Oper {
00092 public:
00093     UnOper(Hash hash) : Oper(hash, 1) {}
00094     virtual ~UnOper() {};
00095 
00096     virtual string str() const = 0;
00097 };
00098 
00102 class BinOper : public Oper {
00103 public:
00104     BinOper(Hash hash) : Oper(hash, 2) {}
00105     virtual ~BinOper() {};
00106 
00107     virtual string str() const = 0;
00108 };
00109 
00110 #endif // __POLICY_COMMON_OPERATOR_BASE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations