1
2 /* Web Polygraph http://www.web-polygraph.org/
3 * Copyright 2003-2011 The Measurement Factory
4 * Licensed under the Apache License, Version 2.0 */
5
6 #include "pgl/pgl.h"
7
8 #include "xstd/String.h"
9 #include "pgl/PglRec.h"
10 #include "pgl/PglNumSym.h"
11 #include "pgl/PglRegExSym.h"
12 #include "pgl/AclSym.h"
13
14
15 String AclSym::TheType = "Acl";
16
17 static String strAllow = "allow";
18 static String strDeny = "deny";
19 static String strRewrite = "rewrite";
20 static String strCheckDomestic = "check_domestic";
21 static String strCheckForeign = "check_foreign";
22
23
AclSym()24 AclSym::AclSym(): RecSym(TheType, new PglRec) {
25 theRec->bAdd(RegExSym::TheType, strAllow, 0);
26 theRec->bAdd(RegExSym::TheType, strDeny, 0);
27 theRec->bAdd(RegExSym::TheType, strRewrite, 0);
28 theRec->bAdd(NumSym::TheType, strCheckDomestic, 0);
29 theRec->bAdd(NumSym::TheType, strCheckForeign, 0);
30 }
31
AclSym(const String & aType,PglRec * aRec)32 AclSym::AclSym(const String &aType, PglRec *aRec): RecSym(aType, aRec) {
33 }
34
isA(const String & type) const35 bool AclSym::isA(const String &type) const {
36 return RecSym::isA(type) || type == TheType;
37 }
38
dupe(const String & type) const39 SynSym *AclSym::dupe(const String &type) const {
40 if (isA(type))
41 return new AclSym(this->type(), theRec->clone());
42 return RecSym::dupe(type);
43 }
44
allow() const45 RegExExpr *AclSym::allow() const {
46 return getGroup(strAllow);
47 }
48
deny() const49 RegExExpr *AclSym::deny() const {
50 return getGroup(strDeny);
51 }
52
rewrite() const53 RegExExpr *AclSym::rewrite() const {
54 return getGroup(strRewrite);
55 }
56
checkDomestic(double & prob) const57 bool AclSym::checkDomestic(double &prob) const {
58 return getDouble(strCheckDomestic, prob);
59 }
60
checkForeign(double & prob) const61 bool AclSym::checkForeign(double &prob) const {
62 return getDouble(strCheckForeign, prob);
63 }
64
getGroup(const String & name) const65 RegExExpr *AclSym::getGroup(const String &name) const {
66 SynSymTblItem *gi = 0;
67 Assert(theRec->find(name, gi));
68 return gi->sym() ?
69 ((RegExSym&)gi->sym()->cast(RegExSym::TheType)).val() : 0;
70 }
71