FLOPC++
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
FlopCpp
src
MP_domain.cpp
Go to the documentation of this file.
1
// ******************** FlopCpp **********************************************
2
// File: MP_domain.cpp
3
// $Id$
4
// Author: Tim Helge Hultberg (thh@mat.ua.pt)
5
// Copyright (C) 2003 Tim Helge Hultberg
6
// All Rights Reserved.
7
//****************************************************************************
8
9
#include "
MP_domain.hpp
"
10
#include "
MP_set.hpp
"
11
#include "
MP_boolean.hpp
"
12
#include "
MP_model.hpp
"
13
14
namespace
flopc {
15
MP_domain_set::MP_domain_set
(
const
MP_set
* s,
MP_index
* i)
16
: S(s), I(i) {}
17
MP_domain_set::~MP_domain_set
() {}
18
MP_domain
MP_domain_set::getDomain
(
MP_set
* s)
const
{
19
return
MP_domain
(const_cast<MP_domain_set*>(
this
));
20
}
21
22
class
Functor_conditional
:
public
Functor
{
23
public
:
24
Functor_conditional
(
const
Functor
* f,
const
std::vector<MP_boolean> & condition)
25
:
F
(f),
Condition
(condition) {}
26
virtual
~Functor_conditional
() {}
27
void
operator()
()
const
{
28
bool
goOn =
true
;
29
for
(
size_t
i = 0; i<
Condition
.size(); i++) {
30
if
(
Condition
[i]->evaluate()==
false
) {
31
goOn =
false
;
32
break
;
33
}
34
}
35
if
(goOn ==
true
) {
36
F
->operator()();
37
}
38
}
39
const
Functor
*
F
;
40
std::vector<MP_boolean>
Condition
;
41
};
42
}
43
44
using namespace
flopc;
45
46
const
MP_domain
*
MP_domain::Empty
= 0;
47
48
const
MP_domain
&
MP_domain::getEmpty
() {
49
if
(
Empty
== 0) {
50
Empty
=
new
MP_domain
(
new
MP_domain_set
(&
MP_set::getEmpty
(),&
MP_set::getEmpty
()));
51
}
52
return
*
Empty
;
53
}
54
55
56
MP_domain_base::MP_domain_base
() : count(0), donext(0) {}
57
MP_domain_base::~MP_domain_base
() {}
58
59
Functor
*
MP_domain_base::makeInsertFunctor
()
const
{
60
return
0;
61
}
62
63
size_t
MP_domain_base::size
()
const
{
64
return
count
;
65
}
66
67
68
void
MP_domain_base::display
()
const
{
69
std::stringstream ss;
70
ss<<
"domain_base::display() size="
<<
size
()<<std::ends;
71
MP_model::getCurrentModel
()->
getMessenger
()->
logMessage
(5,ss.str().c_str());
72
}
73
74
MP_domain::MP_domain
() :
Handle
<
MP_domain_base
*>(0), last(0) {}
75
MP_domain::MP_domain
(
MP_domain_base
* r) :
Handle
<
MP_domain_base
*>(r), last(r) {}
76
MP_domain::~MP_domain
() {}
77
78
MP_domain
MP_domain::such_that
(
const
MP_boolean
& b) {
79
if
(b.operator ->() != 0) {
80
condition
.push_back(b);
81
}
82
return
*
this
;
83
}
84
85
void
MP_domain::forall
(
const
Functor
& op)
const
{
86
forall
(&op);
87
}
88
void
MP_domain::forall
(
const
Functor
* op)
const
{
89
if
(
condition
.size()>0) {
90
last
->
donext
=
new
Functor_conditional
(op,
condition
);
91
}
else
{
92
last
->
donext
= op;
93
}
94
operator->
()->operator()();
95
}
96
97
const
MP_set_base
*
MP_domain_set::getSet
()
const
{
98
return
S
;
99
}
100
101
size_t
MP_domain::size
()
const
{
102
return
operator->
()->
getSet
()->
size
();
103
}
104
105
int
MP_domain_set::evaluate
()
const
{
106
return
I
->
evaluate
();
107
}
108
109
void
MP_domain_set::operator()
()
const
{
110
if
(
I
->
isInstantiated
() ==
true
) {
111
(*donext)();
112
}
else
{
113
I
->
instantiate
();
114
for
(
int
k=0; k<
S
->
size
(); k++) {
115
I
->
assign
(k);
116
(*donext)();
117
}
118
I
->
assign
(0);
119
I
->
unInstantiate
();
120
}
121
}
122
123
MP_index
*
MP_domain_set::getIndex
()
const
{
124
return
I
;
125
}
126
127
128
flopc::MP_domain
flopc::operator*
(
const
flopc::MP_domain
& a,
const
flopc::MP_domain
& b) {
129
if
(a.operator->() ==
MP_domain::getEmpty
().operator->()) {
130
return
b;
131
}
else
if
(b.operator->() ==
MP_domain::getEmpty
().operator->()) {
132
return
a;
133
}
else
{
134
MP_domain
retval = a;
135
retval.
last
->
donext
= b.operator->();
136
const_cast<
MP_domain
&
>
(b).increment();
137
const_cast<
MP_domain
&
>
(a).increment();
138
retval.
last
= b.
last
;
139
retval.
condition
.insert(retval.
condition
.end(),b.
condition
.begin(),
140
b.
condition
.end());
141
return
retval;
142
}
143
144
}
Generated on Sat Nov 1 2014 02:49:56 for FLOPC++ by
1.8.1.2