From 13637f56fa5da8f071ae9fdb0251a3365011e7cf Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Mon, 16 Mar 2009 22:04:55 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@116 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- sources/reactphysics3d/physics/Kilogram.cpp | 17 +++++++++------ sources/reactphysics3d/physics/Kilogram.h | 3 ++- sources/reactphysics3d/physics/Time.cpp | 13 ++++++++---- sources/reactphysics3d/physics/Time.h | 23 +++++++++++++++------ 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/sources/reactphysics3d/physics/Kilogram.cpp b/sources/reactphysics3d/physics/Kilogram.cpp index 807a6374..ece681cd 100644 --- a/sources/reactphysics3d/physics/Kilogram.cpp +++ b/sources/reactphysics3d/physics/Kilogram.cpp @@ -17,14 +17,19 @@ * along with ReactPhysics3D. If not, see . * ***************************************************************************/ - // Libraries - #include "Kilogram.h" +// Libraries +#include "Kilogram.h" - // We want to use the ReactPhysics3D namespace - using namespace reactphysics3d; +// We want to use the ReactPhysics3D namespace +using namespace reactphysics3d; - // Constructor - Kilogram::Kilogram(double value) throw(std::invalid_argument) { +// 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) { this->value = value; diff --git a/sources/reactphysics3d/physics/Kilogram.h b/sources/reactphysics3d/physics/Kilogram.h index 33f53447..84b9c2f6 100644 --- a/sources/reactphysics3d/physics/Kilogram.h +++ b/sources/reactphysics3d/physics/Kilogram.h @@ -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 diff --git a/sources/reactphysics3d/physics/Time.cpp b/sources/reactphysics3d/physics/Time.cpp index 3ebe04a4..f145ec36 100644 --- a/sources/reactphysics3d/physics/Time.cpp +++ b/sources/reactphysics3d/physics/Time.cpp @@ -20,11 +20,16 @@ // Libraries #include "Time.h" - // We want to use the ReactPhysics3D namespace - using namespace reactphysics3d; +// We want to use the ReactPhysics3D namespace +using namespace reactphysics3d; - // Constructor - Time::Time(double value) throw(std::invalid_argument) { +// 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) { this->value = value; diff --git a/sources/reactphysics3d/physics/Time.h b/sources/reactphysics3d/physics/Time.h index c8dc2210..71ebda2a 100644 --- a/sources/reactphysics3d/physics/Time.h +++ b/sources/reactphysics3d/physics/Time.h @@ -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 @@ -46,9 +47,9 @@ class Time { void setValue(double value) throw(std::invalid_argument) ; // Set the time value // 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*(double number) const throw(std::invalid_argument); // Overloaded operator for multiplication with a number + Time operator+(const Time& time2) const; // Overloaded operator for addition 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 }; // --- Inlines functions --- // @@ -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