#ifndef __INDICES_H__ #define __INDICES_H__ #include #define INFINI (std::numeric_limits::infinity()) /** types d'indices utilisés * * utiliser ces types permet d'être prévenu à la compilation * lorsqu'on se trompe dans l'ordre des indices pour accéder * à des tableaux multidimensionnels */ typedef enum {C13=13,C14,C15,C16,C17,C18,C19,C20,C21} constraint_t ; struct week_t; struct wlen_t; struct monEntier { int v ; operator int() const {return v;} explicit monEntier(int i) {v=i;} monEntier() {v=0;} }; struct tlen_t : monEntier { explicit tlen_t(int i) {v=i;} tlen_t() {v=0;} }; struct timestep_t : monEntier { explicit timestep_t(int i) {v=i;} timestep_t() {v=0;} inline tlen_t operator/(week_t h) const ; inline timestep_t operator-(tlen_t h) const ; inline timestep_t operator+(tlen_t h) const ; timestep_t & operator ++() { ++v; return (*this); } timestep_t & operator --() { --v; return (*this); } }; struct week_t : monEntier { explicit week_t(int i) {v=i;} week_t() {v=0;} timestep_t operator*(timestep_t t) {return (timestep_t) (v*(int)t);} bool operator<(week_t other) const { return v(week_t other) const { return v>other.v; } week_t & operator ++() { ++v; return (*this); } inline week_t operator +(wlen_t l) const; inline wlen_t operator -(week_t other) const; }; struct wlen_t : monEntier { explicit wlen_t(int i) {v=i;} wlen_t() {v=0;} }; struct scenario_t : monEntier { explicit scenario_t(int i) {v=i;} scenario_t() {v=0;} scenario_t & operator ++() { ++v; return (*this); } }; struct powerplants1_t : monEntier { explicit powerplants1_t(int i) {v=i;} powerplants1_t() {v=0;} powerplants1_t & operator ++() { ++v; return (*this); } }; struct powerplants2_t : monEntier { explicit powerplants2_t(int i) {v=i;} powerplants2_t() {v=0;} powerplants2_t & operator ++() { ++v; return (*this); } }; struct campaign_t : monEntier { #define K_Tp1 ((campaign_t)-2) explicit campaign_t(int i) {v=i;} campaign_t() {v=0;} campaign_t & operator ++() { ++v; return (*this); } }; struct points_t : monEntier { explicit points_t(int i) {v=i;} points_t() {v=0;} }; tlen_t timestep_t::operator/(week_t h) const {return (tlen_t) (v/(int)h);} timestep_t timestep_t::operator-(tlen_t h) const {return timestep_t(v-(int)h);} timestep_t timestep_t::operator+(tlen_t h) const {return timestep_t(v+(int)h);} week_t week_t::operator +(wlen_t l) const { return week_t(v+l.v); } wlen_t week_t::operator -(week_t other) const { return wlen_t(v-other.v); } /* foncteurs et fonctions utilitaires */ // Foncteur servant à libérer un pointeur - applicable à n'importe quel type struct Delete { template void operator ()(T*& p) const { delete p; p = (T*) 0; } }; // Foncteur servant à vider un vecteur - applicable à n'importe quel type de vecteur #include struct Vide { template void operator ()(std::vector& p) const { p.resize(0); } }; // Foncteur servant à créer un vecteur - applicable à n'importe quel type de pointeur sur un vecteur template struct New { size_t m_s; T m_v; New(size_t size, T val) {m_s = size;} void operator ()(std::vector*& p) const { p = new std::vector( m_s, m_v); } }; #endif