00001 /* 00002 ** TP 4ETI CPE Lyon 00003 ** Copyright (C) 2011 Damien Rohmer 00004 ** 00005 ** This program is free software: you can redistribute it and/or modify 00006 ** it under the terms of the GNU General Public License as published by 00007 ** the Free Software Foundation, either version 3 of the License, or 00008 ** (at your option) any later version. 00009 ** 00010 ** This program is distributed in the hope that it will be useful, 00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 ** GNU General Public License for more details. 00014 ** 00015 ** You should have received a copy of the GNU General Public License 00016 ** along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 00020 #ifndef _P2D_HPP_ 00021 #define _P2D_HPP_ 00022 00023 #include <iostream> 00024 #include <exception_cpe.hpp> 00025 00026 namespace cpe 00027 { 00029 class p2d 00030 { 00031 public: 00032 00033 // ********************************************* // 00034 // ********************************************* // 00035 // CONSTRUCTOR 00036 // ********************************************* // 00037 // ********************************************* // 00038 00040 p2d(); 00045 p2d(const int& x0,const int& y0); 00046 00047 // ********************************************* // 00048 // ********************************************* // 00049 // Coordinate access 00050 // ********************************************* // 00051 // ********************************************* // 00052 00054 void set(const int& x,const int& y); 00056 void get(int* x,int *y) const; 00057 00059 const int& x() const; 00061 int& x(); 00063 const int& y() const; 00065 int& y(); 00066 00067 00068 // ********************************************* // 00069 // ********************************************* // 00070 // Operators 00071 // ********************************************* // 00072 // ********************************************* // 00073 00075 friend p2d operator+(const p2d& u1,const p2d& u2); 00077 friend p2d operator-(const p2d& u1,const p2d& u2); 00079 p2d& operator+=(const p2d& u); 00081 p2d& operator-=(const p2d& u); 00082 00083 // ********************************************* // 00084 // ********************************************* // 00085 // I/O 00086 // ********************************************* // 00087 // ********************************************* // 00088 00090 friend std::ostream& operator<<(std::ostream& stream,const p2d& u); 00091 00092 00093 private: 00094 00095 // ********************************************* // 00096 // ********************************************* // 00097 // Internal storage 00098 // ********************************************* // 00099 // ********************************************* // 00100 00102 int internal_x; 00104 int internal_y; 00105 00106 }; 00107 00109 class exception_p2d : public exception_cpe 00110 { 00111 public: 00113 exception_p2d():exception_cpe(){} 00115 exception_p2d(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){} 00116 }; 00117 } 00118 00119 00120 #endif