From d14bf39b162a1744ae377c440147dbed21dfe3fc Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Thu, 19 Feb 2009 20:05:55 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@106 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- sources/reactphysics3d/physics/Kilogram.cpp | 46 +++++++++ sources/reactphysics3d/physics/Kilogram.h | 70 ++++++++++++++ sources/reactphysics3d/physics/Time.cpp | 46 +++++++++ sources/reactphysics3d/physics/Time.h | 100 ++++++++++++++++++++ sources/reactphysics3d/physics/physics.h | 27 ++++++ 5 files changed, 289 insertions(+) create mode 100644 sources/reactphysics3d/physics/Kilogram.cpp create mode 100644 sources/reactphysics3d/physics/Kilogram.h create mode 100644 sources/reactphysics3d/physics/Time.cpp create mode 100644 sources/reactphysics3d/physics/Time.h create mode 100644 sources/reactphysics3d/physics/physics.h diff --git a/sources/reactphysics3d/physics/Kilogram.cpp b/sources/reactphysics3d/physics/Kilogram.cpp new file mode 100644 index 00000000..807a6374 --- /dev/null +++ b/sources/reactphysics3d/physics/Kilogram.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** + * Copyright (C) 2009 Daniel Chappuis * + **************************************************************************** + * This file is part of ReactPhysics3D. * + * * + * ReactPhysics3D is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * ReactPhysics3D is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with ReactPhysics3D. If not, see . * + ***************************************************************************/ + + // Libraries + #include "Kilogram.h" + + // We want to use the ReactPhysics3D namespace + using namespace reactphysics3d; + + // Constructor + Kilogram::Kilogram(double value) throw(std::invalid_argument) { + // Check if the value is positive + if (value >= 0) { + this->value = value; + } + else { + // We throw an exception + throw std::invalid_argument("Exception in Kilogram : Wrong argument, a mass value has to be positive"); + } + } + + // Copy-constructor + Kilogram::Kilogram(const Kilogram& mass) { + this->value = mass.value; + } + + // Destructor + Kilogram::~Kilogram() { + + } diff --git a/sources/reactphysics3d/physics/Kilogram.h b/sources/reactphysics3d/physics/Kilogram.h new file mode 100644 index 00000000..33f53447 --- /dev/null +++ b/sources/reactphysics3d/physics/Kilogram.h @@ -0,0 +1,70 @@ +/**************************************************************************** + * Copyright (C) 2009 Daniel Chappuis * + **************************************************************************** + * This file is part of ReactPhysics3D. * + * * + * ReactPhysics3D is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * ReactPhysics3D is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with ReactPhysics3D. If not, see . * + ***************************************************************************/ + + #ifndef KILOGRAM_H + #define KILOGRAM_H + + // Libraries + #include + + // Namespace ReactPhysics3D + namespace reactphysics3d { + +/* ------------------------------------------------------------------- + Class Kilogram : + The Kilogram class represents a mass unity. The value inside is a + mass in kilogram. + ------------------------------------------------------------------- +*/ +class Kilogram { + private : + double value; // Mass value in kilogram + + public : + Kilogram(double value) throw(std::invalid_argument); // Constructor + Kilogram(const Kilogram& mass); // Copy-constructor + virtual ~Kilogram(); // Destructor + + double getValue() const; // Return the mass value in kilogram + void setValue(double value) throw(std::invalid_argument); // Set the mass value +}; + +// --- Inlines functions --- // + +// Return the value in kilogram +inline double Kilogram::getValue() const { + return value; +} + +// Set the value in kilogram +inline void Kilogram::setValue(double value) throw(std::invalid_argument) { + + // Check if the time value is positive + if (value >= 0) { + this->value = value; + } + else { + // We throw an exception + throw std::invalid_argument("Exception in Time: Wrong argument, a time value has to be positive"); + } +} + +} + + #endif diff --git a/sources/reactphysics3d/physics/Time.cpp b/sources/reactphysics3d/physics/Time.cpp new file mode 100644 index 00000000..3ebe04a4 --- /dev/null +++ b/sources/reactphysics3d/physics/Time.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** + * Copyright (C) 2009 Daniel Chappuis * + **************************************************************************** + * This file is part of ReactPhysics3D. * + * * + * ReactPhysics3D is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * ReactPhysics3D is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with ReactPhysics3D. If not, see . * + ***************************************************************************/ + + // Libraries + #include "Time.h" + + // We want to use the ReactPhysics3D namespace + using namespace reactphysics3d; + + // Constructor + Time::Time(double value) throw(std::invalid_argument) { + // Check if the value is positive + if (value >= 0.0) { + this->value = value; + } + else { + // We throw an exception + throw std::invalid_argument("Exception in Time : Wrong argument, a time value has to be positive"); + } + } + + // Copy-constructor + Time::Time(const Time& time) { + this->value = time.value; + } + + // Destructor + Time::~Time() { + + } diff --git a/sources/reactphysics3d/physics/Time.h b/sources/reactphysics3d/physics/Time.h new file mode 100644 index 00000000..c8dc2210 --- /dev/null +++ b/sources/reactphysics3d/physics/Time.h @@ -0,0 +1,100 @@ +/**************************************************************************** + * Copyright (C) 2009 Daniel Chappuis * + **************************************************************************** + * This file is part of ReactPhysics3D. * + * * + * ReactPhysics3D is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * ReactPhysics3D is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with ReactPhysics3D. If not, see . * + ***************************************************************************/ + + #ifndef TIME_H + #define TIME_H + + // Libraries + #include + #include + + // Namespace ReactPhysics3D + namespace reactphysics3d { + +/* ------------------------------------------------------------------- + Class Time : + The Time class represents a time unity. The value inside is the + time value in seconds. + ------------------------------------------------------------------- +*/ +class Time { + private : + double value; // Time in seconds + + public : + Time(double value) throw(std::invalid_argument); // Constructor + Time(const Time& time); // Copy-constructor + virtual ~Time(); // Destructor + + double getValue() const; // Return the time value in seconds + 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 +}; + +// --- Inlines functions --- // + +// Return the value in seconds +inline double Time::getValue() const { + return value; +} + +// Set the value in seconds +inline void Time::setValue(double value) throw(std::invalid_argument) { + + // Check if the time value is positive + if (value >= 0.0) { + this->value = value; + } + else { + std::cout << "ERROR TIME : " << value << std::endl; + + // We throw an exception + throw std::invalid_argument("Exception in test Time: Wrong argument, a time value has to be positive"); + } +} + +// Overloaded operator for addition with Time +inline Time Time::operator+(const Time& time2) const { + return Time(value + time2.value); +} + +// Overloaded operator for substraction with Time +inline Time Time::operator-(const Time& time2) const { + return Time(value - time2.value); +} + +// Overloaded operator for multiplication with a number +inline Time Time::operator*(double number) const throw(std::invalid_argument) { + // Check if the number is positive + if (number > 0.0) { + return Time(value*number); + } + else { + // We throw an exception + throw std::invalid_argument("Exception in Time::operator* : The argument number has to be positive"); + } +} + +} + + #endif diff --git a/sources/reactphysics3d/physics/physics.h b/sources/reactphysics3d/physics/physics.h new file mode 100644 index 00000000..18c7050a --- /dev/null +++ b/sources/reactphysics3d/physics/physics.h @@ -0,0 +1,27 @@ +/**************************************************************************** + * Copyright (C) 2009 Daniel Chappuis * + **************************************************************************** + * This file is part of ReactPhysics3D. * + * * + * ReactPhysics3D is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * ReactPhysics3D is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with ReactPhysics3D. If not, see . * + ***************************************************************************/ + +#ifndef PHYSICS_H +#define PHYSICS_H + +// Libraries +#include "Time.h" +#include "Kilogram.h" + +#endif