Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
FIC_DK_P GA Solving
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
6
Issues
6
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
M3TAL
FIC_DK_P GA Solving
Commits
4579ad4e
Commit
4579ad4e
authored
Apr 29, 2020
by
Alexis Lebis
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some redef of mag operator. Warning : rebase does not save modif (check @ mainl27)
parent
a45af4aa
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
18 deletions
+99
-18
main.cpp
application/main.cpp
+19
-2
magnitudeException.h
src/model/exception/magnitudeException.h
+8
-4
magnitude.cpp
src/model/magnitude.cpp
+54
-5
magnitude.h
src/model/magnitude.h
+18
-7
No files found.
application/main.cpp
View file @
4579ad4e
...
...
@@ -6,12 +6,29 @@
#include <queenEval.h>
#include <model/magnitude.h>
#include <model/exception/magnitudeException.h>
int
main
(
int
argc
,
char
*
argv
[]){
Magnitude
*
m
=
Magnitude
::
build
(
-
10.0
);
Magnitude
m
=
Magnitude
::
build
(
0.5
);
Magnitude
n
=
Magnitude
::
build
(
0.3
);
std
::
cout
<<
"Magnitude"
<<
m
.
value
()
<<
std
::
endl
;
m
+=
n
;
std
::
cout
<<
"New magnitude is "
<<
m
.
value
()
<<
std
::
endl
;
try
{
std
::
cout
<<
"After addition mag is : "
<<
(
m
+
m
).
value
()
<<
std
::
endl
;
}
catch
(
MagnitudeException
e
)
{
e
.
getMagnitude
().
rebase
();
std
::
cout
<<
"REBASE! New magnitude value is"
<<
e
.
getMagnitude
().
rebase
()
<<
std
::
endl
;
std
::
cout
<<
"Accessing magnitude value : "
<<
e
.
getMagnitude
().
value
()
<<
std
::
endl
;
}
std
::
cout
<<
"Magnitude"
<<
m
->
value
()
<<
std
::
endl
;
//Define a QUEEN -> 1 line
QUEEN
s1
;
...
...
src/model/exception/magnitudeException.h
View file @
4579ad4e
...
...
@@ -4,17 +4,19 @@
#include <exception>
#include <string>
#include "../magnitude.h"
class
MagnitudeException
:
public
std
::
exception
{
private
:
doubl
e
_triedValue
;
Magnitud
e
_triedValue
;
std
::
string
_phrase
;
public
:
MagnitudeException
(
double
v
)
throw
()
:
_triedValue
(
v
)
MagnitudeException
(
Magnitude
&
m
)
throw
()
:
_triedValue
(
m
)
{
this
->
_phrase
=
"Magnitude Exception: value ("
+
std
::
to_string
(
v
)
+
") is out of bound [0;1]."
;
this
->
_phrase
=
"Magnitude Exception: value ("
+
std
::
to_string
(
m
.
value
()
)
+
") is out of bound [0;1]."
;
}
virtual
const
char
*
what
()
const
throw
()
...
...
@@ -24,6 +26,8 @@ class MagnitudeException : public std::exception
virtual
~
MagnitudeException
()
throw
()
{}
Magnitude
getMagnitude
()
const
{
return
this
->
_triedValue
;}
};
#endif // SRC_EXCEPTION_MAGNITUDE_EXCEPTION_H_
\ No newline at end of file
src/model/magnitude.cpp
View file @
4579ad4e
...
...
@@ -2,14 +2,17 @@
#include "exception/magnitudeException.h"
// === FACTORY
Magnitude
*
Magnitude
::
build
(
double
value
=
0
)
Magnitude
Magnitude
::
build
(
double
value
=
0
)
{
bool
isInRange
=
!
(
_inRange
(
value
));
if
(
!
isInRange
)
throw
MagnitudeException
(
value
);
{
Magnitude
mag
(
value
);
throw
MagnitudeException
(
mag
);
}
else
return
new
Magnitude
(
value
);
return
Magnitude
(
value
);
}
// === CONSTRUCTOR
...
...
@@ -23,15 +26,52 @@ Magnitude::Magnitude(double d)
this
->
_value
=
d
;
}
Magnitude
::
Magnitude
(
const
Magnitude
&
m
)
{
this
->
_value
=
m
.
_value
;
}
// === OPERATOR
Magnitude
&
Magnitude
::
operator
+=
(
const
double
d
)
{
this
->
_value
+=
d
;
if
(
Magnitude
::
_inRange
(
this
->
_value
)
)
throw
MagnitudeException
(
*
this
);
return
*
this
;
}
Magnitude
&
Magnitude
::
operator
+=
(
const
Magnitude
&
m
)
{
this
->
_value
+=
m
.
_value
;
if
(
Magnitude
::
_inRange
(
this
->
_value
)
)
throw
MagnitudeException
(
*
this
);
return
*
this
;
}
Magnitude
operator
+
(
const
Magnitude
&
m
,
const
Magnitude
&
n
)
{
Magnitude
mag
(
m
);
mag
+=
n
.
value
();
return
mag
;
}
Magnitude
operator
+
(
const
Magnitude
&
m
,
const
double
d
)
{
Magnitude
mag
(
m
);
mag
+=
d
;
return
mag
;
}
// === FUNCTION
/** Checks if the value v is in [0;1]. If yes, return 0. Else, if v < 0 return -1, 1 otherwise
*/
const
int
Magnitude
::
_inRange
(
double
v
)
int
Magnitude
::
_inRange
(
double
v
)
{
return
v
<
0
?
-
1
:
v
>
1
?
1
:
0
;
}
const
double
Magnitude
::
value
()
{
return
this
->
_value
;}
double
Magnitude
::
value
()
const
{
return
this
->
_value
;}
/** Set the magnitude value of a competency. Indicates whether or not there is an overflow in
* the given v value (and that it has been automatically corrected)
...
...
@@ -56,3 +96,12 @@ bool Magnitude::set(double v)
return
!
isInRange
;
}
double
Magnitude
::
rebase
()
{
if
(
this
->
_value
<
0
)
this
->
_value
=
0
;
else
if
(
this
->
_value
>
1
)
this
->
_value
=
1
;
return
this
->
_value
;
}
\ No newline at end of file
src/model/magnitude.h
View file @
4579ad4e
...
...
@@ -15,16 +15,27 @@ class Magnitude
Magnitude
(
double
);
// function
static
const
int
_inRange
(
double
);
static
int
_inRange
(
double
);
public
:
static
Magnitude
*
build
(
double
);
//factory
static
Magnitude
build
(
double
);
//factory
Magnitude
(
const
Magnitude
&
m
);
double
rebase
();
/// if value is out of range, assign it the nearest value. Usefull when a MagnitudeException is caught
// Operator
Magnitude
&
operator
+=
(
const
Magnitude
&
m
);
Magnitude
&
operator
+=
(
double
const
d
);
//GETTER
const
double
value
()
;
double
value
()
const
;
//SETTER
bool
set
(
double
v
);
};
Magnitude
operator
+
(
const
Magnitude
&
m1
,
const
Magnitude
&
m2
);
Magnitude
operator
+
(
const
Magnitude
&
m1
,
double
d
);
#endif // SRC_MAGNITUDE_H_
\ No newline at end of file
Alexis Lebis
@alexis.lebis
mentioned in issue
#1 (closed)
·
Apr 30, 2020
mentioned in issue
#1 (closed)
mentioned in issue #1
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment