diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/Makefile | 2 | ||||
-rw-r--r-- | src/main/Particle.cc | 4 | ||||
-rw-r--r-- | src/main/Particle.h | 70 | ||||
-rw-r--r-- | src/main/Printable.cc | 20 | ||||
-rw-r--r-- | src/main/Printable.h | 28 | ||||
-rw-r--r-- | src/main/Vector3D.cc | 5 | ||||
-rw-r--r-- | src/main/Vector3D.h | 5 |
7 files changed, 101 insertions, 33 deletions
diff --git a/src/main/Makefile b/src/main/Makefile index c6dc1e1..8b68115 100644 --- a/src/main/Makefile +++ b/src/main/Makefile @@ -13,7 +13,7 @@ LOCALDIR = main # ==> Ajouter ici les objets a compiler # Si un objet necessite une compilation non-standard (i.e. pas de regle du style Foo.o : Foo.cc Foo.h), rajouter # cette regle. -LOCALOBJS = Vector3D.o Particle.o +LOCALOBJS = Vector3D.o Particle.o Printable.o OBJS=$(addprefix $(BINDIR)/$(LOCALDIR)/,$(LOCALOBJS)) .PHONY = lib diff --git a/src/main/Particle.cc b/src/main/Particle.cc index 2917449..34e4682 100644 --- a/src/main/Particle.cc +++ b/src/main/Particle.cc @@ -10,8 +10,4 @@ namespace vhc { -Particle::~Particle() { - // TODO Auto-generated destructor stub -} - } diff --git a/src/main/Particle.h b/src/main/Particle.h index cc15c93..c59d198 100644 --- a/src/main/Particle.h +++ b/src/main/Particle.h @@ -8,51 +8,81 @@ #ifndef PARTICLE_H_ #define PARTICLE_H_ +#include <sstream> #include "Vector3D.h" +#include "Printable.h" namespace vhc { -class Particle { +/** Classe representant une particule. + * TODO ajouter facteur gamma, energie, constructeur etc...*/ +class Particle: public Printable { private: + + /** Position de cette particule. */ Vector3D position; + + /** Vitesse de cette particule. */ + Vector3D velocity; + + /** Force resultante sur cette particule. */ Vector3D force; + + /** Masse de cette particlue. */ double mass; + + /** Charge de cette particule. */ double charge; public: - void applyForce(const Vector3D& f) {force = force + f;} + Particle(const Vector3D& position0, double mass, double charge): + position(position0), + velocity(0, 0, 0), + force(0, 0, 0), + mass(mass), + charge(charge) + {}; + + + /** Retourne la position de cette particule. */ Vector3D getPosition() const {return position;} + /** Affecte la position de cette particule. */ void setPosition(const Vector3D& pos) {position = pos;} + /** Retourne la force resultante sur cette particule. */ Vector3D getForce() const {return force;} - double getMass() const {return mass;} - - double getCharge() const {return charge;} - - - /* - Vector3D getPosition() {return position;} + /** Affecte la force resultante sur cette particule. */ + void setForce(const Vector3D& f) {force = f;} - Vector3D getVelocity(); + /** Applique une force sur cette particule. */ + void applyForce(const Vector3D& f) {force = force + f;} - Vector3D getEnergy(); + /** Retourne la masse de cette particule. */ + double getMass() const {return mass;} - Vector3D getGamma(); + /** Retourne la charge de cette particule. */ + double getCharge() const {return charge;} - Vector3D getMomentum(); -*/ - Particle(const Vector3D& position0, double mass, double charge): - position(position0), - force(0, 0, 0), - mass(mass), - charge(charge) {}; + /** Retourne la vitesse de cette particule. */ + Vector3D getVelocity() const {return velocity;} + + /** Retourne une representation en chaine de ce vecteur. */ + std::string toString() const { + std::stringstream s; + s << "Particle:" << "\n"; + s << "\tPosition: " << position << "\n"; + s << "\tVelocity: " << velocity << "\n"; + s << "\tMass: " << mass << "\n"; + s << "\tCharge: " << charge << "\n"; + s << "\tForce: " << force << "\n"; + return s.str(); + } - virtual ~Particle(); }; } diff --git a/src/main/Printable.cc b/src/main/Printable.cc new file mode 100644 index 0000000..5139ad1 --- /dev/null +++ b/src/main/Printable.cc @@ -0,0 +1,20 @@ +/* + * Printable.cc + * + * Created on: Mar 16, 2011 + * Author: jakob + */ + +#include "Printable.h" +#include <iostream> + +using namespace std; + +namespace vhc { + +std::ostream& operator<< (ostream& output, const Printable& p) { + output << p.toString(); + return output; +} + +} diff --git a/src/main/Printable.h b/src/main/Printable.h new file mode 100644 index 0000000..f7d3f9b --- /dev/null +++ b/src/main/Printable.h @@ -0,0 +1,28 @@ +/* + * Printable.h + * + * Created on: Mar 16, 2011 + * Author: jakob + */ + +#ifndef PRINTABLE_H_ +#define PRINTABLE_H_ + +#include <string> + +namespace vhc { + +class Printable { + +public: + + /** Retourne une representation en chaine de cet objet imprimable. */ + virtual std::string toString() const = 0; + +}; + +std::ostream& operator<< (std::ostream& output, const Printable& p); + +} + +#endif /* PRINTABLE_H_ */ diff --git a/src/main/Vector3D.cc b/src/main/Vector3D.cc index 8acaa86..9cca834 100644 --- a/src/main/Vector3D.cc +++ b/src/main/Vector3D.cc @@ -17,11 +17,6 @@ Vector3D const Vector3D::i = Vector3D(1.0, 0.0, 0.0); Vector3D const Vector3D::j = Vector3D(0.0, 1.0, 0.0); Vector3D const Vector3D::k = Vector3D(0.0, 0.0, 1.0); -std::ostream& operator<< (ostream& output, const Vector3D& v) { - output << v.toString(); - return output; -} - Vector3D operator* (double n, const Vector3D& v) { return v * n; } diff --git a/src/main/Vector3D.h b/src/main/Vector3D.h index 31094da..4e2acb4 100644 --- a/src/main/Vector3D.h +++ b/src/main/Vector3D.h @@ -12,6 +12,7 @@ #include <sstream> #include <math.h> #include <stdexcept> +#include "Printable.h" namespace vhc { @@ -24,7 +25,7 @@ namespace vhc { * performance perdue ainsi est minimale pour une classe ne contenant que trois * champs. */ -class Vector3D { +class Vector3D: public Printable { private: /** Composante x. */ @@ -116,8 +117,6 @@ public: }; -std::ostream& operator<< (std::ostream& output, const Vector3D& v); - Vector3D operator* (double n, const Vector3D& v); } // namespace |