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/>. *
***************************************************************************/
// 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;

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

@ -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;

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
@ -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