ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Tree-M/GiST/GiSTpredicate.h
Revision: 1.1
Committed: Sun May 6 00:45:52 2001 UTC (23 years ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 // -*- Mode: C++ -*-
2
3 // GiSTpredicate.h
4 //
5 // Copyright (c) 1996, Regents of the University of California
6 // $Header: /usr/local/devel/GiST/libGiST/libGiST/GiSTpredicate.h,v 1.1.1.1 1996/08/06 23:47:22 jmh Exp $
7
8 #ifndef GISTPREDICATE_H
9 #define GISTPREDICATE_H
10
11 #include <iostream.h>
12 #include "GiSTdefs.h"
13 #include "GiSTentry.h"
14
15 // The GiSTpredicate class itself doesn't do much except serve as a
16 // placeholder for the Consistent method. However, some handy Boolean
17 // connectors are here as well (And, Or, Not) and well as True.
18
19
20 class GiSTentry;
21
22 class GiSTpredicate: public GiSTobject {
23 public:
24 GiSTobjid IsA() const { return GISTPREDICATE_CLASS; }
25 virtual int Consistent(const GiSTentry& entry) const=0;
26 virtual ~GiSTpredicate() {}
27 };
28
29 class PtrPredicate: public GiSTpredicate {
30 public:
31 PtrPredicate(GiSTpage page): page(page) {}
32 int Consistent(const GiSTentry& entry) const;
33 GiSTobject *Copy() const;
34 #ifdef PRINTING_OBJECTS
35 void Print(ostream& os) const;
36 #endif
37
38 private:
39 GiSTpage page;
40 };
41
42 class AndPredicate: public GiSTpredicate {
43 public:
44 AndPredicate(GiSTpredicate *q1, GiSTpredicate *q2): q1(q1), q2(q2) {}
45 int Consistent(const GiSTentry& entry) const { return q1->Consistent(entry)&&q2->Consistent(entry); }
46 #ifdef PRINTING_OBJECTS
47 void Print(ostream& os) const {
48 os << "(" << *q1 << " and " << *q2 << ")";
49 }
50 #endif
51 GiSTobject *Copy() const {
52 return new AndPredicate((GiSTpredicate*)q1->Copy(), (GiSTpredicate*)q2->Copy());
53 }
54 ~AndPredicate() {
55 if(q1) delete q1;
56 if(q2) delete q2;
57 }
58
59 private:
60 GiSTpredicate *q1, *q2;
61 };
62
63 class OrPredicate: public GiSTpredicate {
64 public:
65 OrPredicate(GiSTpredicate *q1, GiSTpredicate *q2): q1(q1), q2(q2) {}
66 int Consistent(const GiSTentry& entry) const {
67 return q1->Consistent(entry)||q2->Consistent(entry);
68 }
69 #ifdef PRINTING_OBJECTS
70 void Print(ostream& os) const {
71 os << "(" << *q1 << " or " << *q2 << ")";
72 }
73 #endif
74 GiSTobject *Copy() const {
75 return new OrPredicate((GiSTpredicate*)q1->Copy(), (GiSTpredicate*)q2->Copy());
76 }
77 ~OrPredicate() {
78 if(q1) delete q1;
79 if(q2) delete q2;
80 }
81
82 private:
83 GiSTpredicate *q1, *q2;
84 };
85
86 class NotPredicate: public GiSTpredicate {
87 public:
88 NotPredicate(GiSTpredicate *q): q(q) {}
89 int Consistent(const GiSTentry& entry) const {
90 return !q->Consistent(entry);
91 }
92 GiSTobject *Copy() const {
93 return new NotPredicate((GiSTpredicate*)q->Copy());
94 }
95 #ifdef PRINTING_OBJECTS
96 void Print(ostream& os) const {
97 os << "(not " << *q << ")";
98 }
99 #endif
100 ~NotPredicate() { if(q) delete q; }
101
102 private:
103 GiSTpredicate *q;
104 };
105
106 class TruePredicate: public GiSTpredicate {
107 public:
108 TruePredicate() {}
109 int Consistent(const GiSTentry& entry) const { return 1; }
110 GiSTobject *Copy() const { return new TruePredicate; }
111 #ifdef PRINTING_OBJECTS
112 void Print(ostream& os) const {
113 os << "true";
114 }
115 #endif
116 };
117
118 #endif