git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@116 92aac97c-a6ce-11dd-a772-7fcde58d38e6

This commit is contained in:
chappuis.daniel 2009-03-16 22:04:55 +00:00
parent 57afe1b48b
commit 13637f56fa
4 changed files with 39 additions and 17 deletions

View File

@ -24,6 +24,11 @@
using namespace reactphysics3d;
// Constructor
Kilogram::Kilogram() {
value = 0.0;
}
// Constructor with arguments
Kilogram::Kilogram(double value) throw(std::invalid_argument) {
// Check if the value is positive
if (value >= 0) {

View File

@ -37,7 +37,8 @@ class Kilogram {
double value; // Mass value in kilogram
public :
Kilogram(double value) throw(std::invalid_argument); // Constructor
Kilogram(); // Constructor
Kilogram(double value) throw(std::invalid_argument); // Constructor with arguments
Kilogram(const Kilogram& mass); // Copy-constructor
virtual ~Kilogram(); // Destructor

View File

@ -24,6 +24,11 @@
using namespace reactphysics3d;
// Constructor
Time::Time() {
value = 0.0;
}
// Constructor with arguments
Time::Time(double value) throw(std::invalid_argument) {
// Check if the value is positive
if (value >= 0.0) {

View File

@ -38,7 +38,8 @@ class Time {
double value; // Time in seconds
public :
Time(double value) throw(std::invalid_argument); // Constructor
Time(); // Constructor
Time(double value) throw(std::invalid_argument); // Constructor with arguments
Time(const Time& time); // Copy-constructor
virtual ~Time(); // Destructor
@ -47,7 +48,7 @@ class Time {
// Overloaded operators
Time operator+(const Time& time2) const; // Overloaded operator for addition with Time
Time operator-(const Time& time2) const; // Overloaded operator for substraction with Time
Time operator-(const Time& time2) const throw(std::invalid_argument); // Overloaded operator for substraction with Time
Time operator*(double number) const throw(std::invalid_argument); // Overloaded operator for multiplication with a number
};
@ -79,8 +80,18 @@ inline Time Time::operator+(const Time& time2) const {
}
// Overloaded operator for substraction with Time
inline Time Time::operator-(const Time& time2) const {
return Time(value - time2.value);
inline Time Time::operator-(const Time& time2) const throw(std::invalid_argument) {
// Compute the result of the substraction
double result = value - time2.value;
// If the result is negative
if (result <= 0.0) {
// We throw an exception
throw std::invalid_argument("Exception in Time::operator- : The result should be positive");
}
// Return the result
return Time(result);
}
// Overloaded operator for multiplication with a number