Actual source code: Stack.cxx
1: #define ALE_Stack_cxx
3: #ifndef included_ALE_Stack_hh
4: #include <Stack.hh>
5: #endif
7: namespace ALE {
9: #undef __FUNCT__
11: Obj<PreSieve> Stack::top() {
12: return _top;
13: }// Stack::top()
15: #undef __FUNCT__
17: Stack& Stack::setTop(Obj<PreSieve> top) {
18: CHKCOMM(*this);
19: this->__checkLock();
20: PreSieve::clear();
21: this->_top = top;
22: return *this;
23: }// Stack::setTop()
25: #undef __FUNCT__
27: Obj<PreSieve> Stack::left() {
28: return top();
29: }// Stack::left()
31: #undef __FUNCT__
33: Stack& Stack::setLeft(Obj<PreSieve> left) {
34: return this->setTop(left);
35: }// Stack::setLeft()
38: #undef __FUNCT__
40: Obj<PreSieve> Stack::bottom() {
41: return _bottom;
42: }// Stack::bottom()
44: #undef __FUNCT__
46: Stack& Stack::setBottom(Obj<PreSieve> bottom) {
47: CHKCOMM(*this);
48: this->__checkLock();
49: this->_bottom = bottom;
50: PreSieve::clear();
51: return *this;
52: }// Stack::setBottom()
54: #undef __FUNCT__
56: Obj<PreSieve> Stack::right() {
57: return this->bottom();
58: }// Stack::right()
60: #undef __FUNCT__
62: Stack& Stack::setRight(Obj<PreSieve> right) {
63: return this->setBottom(right);
64: }// Stack::setBottom()
65:
67: #undef __FUNCT__
69: Stack* Stack::baseRestriction(Point_set& base) {
70: CHKCOMM(*this);
71: Stack *s = new Stack(this->_top, this->_bottom);
72: for(Point_set::iterator b_itor = base.begin(); b_itor != base.end(); b_itor++){
73: Point p = *b_itor;
74: // is point p present in the base of *this?
75: if(this->_cone.find(p) != this->_cone.end()){
76: s->addCone(this->_cone[p],p);
77: }
78: }// for(Point_set::iterator b_itor = base.begin(); b_itor != base.end(); b_itor++){
79: return s;
80: }// Stack::baseRestriction()
82: #undef __FUNCT__
84: Stack* Stack::baseExclusion(Point_set& base) {
85: CHKCOMM(*this);
86: Stack *s = new Stack(this->_top, this->_bottom);
87: this->__computeBaseExclusion(base, s);
88: return s;
89: }// Stack::baseExclusion()
91: #undef __FUNCT__
93: Stack* Stack::capRestriction(Point_set& cap) {
94: CHKCOMM(*this);
95: Stack *s = new Stack(this->_top, this->_bottom);
96: for(Point_set::iterator c_itor = cap.begin(); c_itor != cap.end(); c_itor++){
97: Point q = *c_itor;
98: // is point q present in the cap of *this?
99: if(this->_support.find(q) == this->_support.end()){
100: s->addSupport(q,this->_support[q]);
101: }
102: }// for(Point_set::iterator c_itor = cap.begin(); c_itor != cap.end(); c_itor++){
103: return s;
104: }// Stack::capRestriction()
107: #undef __FUNCT__
109: Stack* Stack::capExclusion(Point_set& cap) {
110: CHKCOMM(*this);
111: Stack *s = new Stack(this->_top, this->_bottom);
112: this->__computeCapExclusion(cap, s);
113: return s;
114: }// Stack::capExclusion()
116: // ---------------------------------------------------------------------------------------
117: #undef __FUNCT__
119: Stack& Stack::addBasePoint(Point& p) {
120: this->__checkLock();
121: // Check whether the point is in the _bottom, and reject the addition if it isn't
122: if(!this->_bottom->spaceContains(p)) {
123: throw ALE::Exception("Stack cannot add base points absent from its bottom Sieve");
124: }
125: // Invoke PreSieve's addition method
126: PreSieve::addBasePoint(p);
127: return *this;
128: }// Stack::addBasePoint()
130: #undef __FUNCT__
132: Stack& Stack::addCapPoint(Point& p) {
133: this->__checkLock();
134: // Check whether the point is in the _top, and reject the addition if it isn't
135: if(!this->_top->spaceContains(p)) {
136: throw ALE::Exception("Stack cannot add cap points absent from its top Sieve");
137: }
138: // Invoke PreSieve's addition method
139: PreSieve::addCapPoint(p);
140: return *this;
141: }// Stack::addCapPoint()
143: #undef __FUNCT__
145: Stack& Stack::stackAbove(Stack& s) {
146: PreSieve::stackAbove(s);
147: this->_bottom = s._bottom;
148: return *this;
149: }// Stack::stackAbove()
150:
151: #undef __FUNCT__
153: Stack& Stack::stackBelow(Stack& s) {
154: PreSieve::stackBelow(s);
155: this->_top = s._top;
156: return *this;
157: }// Stack::stackAbove()
158:
160: #undef __FUNCT__
162: Stack& Stack::invert() {
163: PreSieve::invert();
164: Obj<PreSieve> tmp = this->_top;
165: this->_top = this->_bottom;
166: this->_bottom = tmp;
167: return *this;
168: }// Stack::invert()
170: #undef __FUNCT__
172: Obj<Point_set> Stack::space() {
173: // Take the union of the top and bottom spaces
174: Obj<Point_set> top = this->_top->space();
175: Obj<Point_set> bottom = this->_bottom->space();
176: Obj<Point_set> tmp;
178: // Make top the smallest set to limit the iteration loop
179: if(bottom->size() < top->size()) {tmp = top; top = bottom; bottom = tmp;}
180: for(Point_set::iterator t_itor = top->begin(); t_itor != top->end(); t_itor++) {
181: bottom->insert(*t_itor);
182: }
183: return bottom;
184: }// Stack::space()
186:
189: void Stack::view(const char *name) {
190: ostringstream vName, topName, bottomName, hdr;
191: // Print header
193: vName << "vertical part";
194: hdr << "Viewing";
195: if(this->isLocked()) {
196: hdr << " (a locked)";
197: }
198: hdr << " Stack";
199: if(name != NULL) {
200: hdr << " " << name << std::endl;
201: topName << name << "'s top";
202: bottomName << name << "'s bottom";
203: vName << " of " << name;
204: }
205: else {
206: topName << "top";
207: bottomName << "bottom";
208: }
209: // Print header
210: PetscPrintf(comm, hdr.str().c_str()); CHKERROR(ierr, "Error in PetscPrintf");
211:
212: // First view the top and the bottom
213: this->_top->view(topName.str().c_str());
214: this->_bottom->view(bottomName.str().c_str());
215: // Then the vertical part
216: PreSieve::view(vName.str().c_str());
218: }// Stack::view()
220: } // namespace ALE
222: #undef ALE_Stack_cxx