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

@ -17,14 +17,19 @@
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. * * along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/ ***************************************************************************/
// Libraries // Libraries
#include "Kilogram.h" #include "Kilogram.h"
// We want to use the ReactPhysics3D namespace // We want to use the ReactPhysics3D namespace
using namespace reactphysics3d; using namespace reactphysics3d;
// Constructor // Constructor
Kilogram::Kilogram(double value) throw(std::invalid_argument) { Kilogram::Kilogram() {
value = 0.0;
}
// Constructor with arguments
Kilogram::Kilogram(double value) throw(std::invalid_argument) {
// Check if the value is positive // Check if the value is positive
if (value >= 0) { if (value >= 0) {
this->value = value; this->value = value;

View File

@ -37,7 +37,8 @@ class Kilogram {
double value; // Mass value in kilogram double value; // Mass value in kilogram
public : 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 Kilogram(const Kilogram& mass); // Copy-constructor
virtual ~Kilogram(); // Destructor virtual ~Kilogram(); // Destructor

View File

@ -20,11 +20,16 @@
// Libraries // Libraries
#include "Time.h" #include "Time.h"
// We want to use the ReactPhysics3D namespace // We want to use the ReactPhysics3D namespace
using namespace reactphysics3d; using namespace reactphysics3d;
// Constructor // Constructor
Time::Time(double value) throw(std::invalid_argument) { Time::Time() {
value = 0.0;
}
// Constructor with arguments
Time::Time(double value) throw(std::invalid_argument) {
// Check if the value is positive // Check if the value is positive
if (value >= 0.0) { if (value >= 0.0) {
this->value = value; this->value = value;

View File

@ -38,7 +38,8 @@ class Time {
double value; // Time in seconds double value; // Time in seconds
public : 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 Time(const Time& time); // Copy-constructor
virtual ~Time(); // Destructor virtual ~Time(); // Destructor
@ -46,9 +47,9 @@ class Time {
void setValue(double value) throw(std::invalid_argument) ; // Set the time value void setValue(double value) throw(std::invalid_argument) ; // Set the time value
// Overloaded operators // Overloaded operators
Time operator+(const Time& time2) const; // Overloaded operator for addition with Time 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 Time operator*(double number) const throw(std::invalid_argument); // Overloaded operator for multiplication with a number
}; };
// --- Inlines functions --- // // --- Inlines functions --- //
@ -79,8 +80,18 @@ inline Time Time::operator+(const Time& time2) const {
} }
// Overloaded operator for substraction with Time // Overloaded operator for substraction with Time
inline Time Time::operator-(const Time& time2) const { inline Time Time::operator-(const Time& time2) const throw(std::invalid_argument) {
return Time(value - time2.value); // 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 // Overloaded operator for multiplication with a number