Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "anim.h"
- anim::anim():phases(0){
- id=tkt++;
- }
- ---
- #include "attrib.h"
- ----
- #include "figura.h"
- //{Figura ---------------------------------------------------------
- int figura::tkt=0;
- figura::figura(vect _v, bool v=true):posRel(_v),visible(v){
- id=tkt++;
- }
- bool figura::setColor(t_RGB c){
- Color=c;
- }
- int figura::getId(){
- return id;
- }
- //}
- //{Circulo ----------------------------------------------
- circulo::circulo(vect _v=0, float _r=0, bool _f=false):posRel(_v),rad(_r),filled(_f){}
- float circulo::area(){
- return (M_PI*pow(rad,2.0));
- }
- float circulo::perim(){
- return (2.0*M_PI*rad);
- }
- //}
- ------
- #include "lists.h"
- //{ LISTA
- template <typename T>
- List<T>::List(int _egg=0):tam(0),first(nullptr),last(nullptr){
- if (_egg==39694694)
- {
- dev=true;
- cout<<"MRC-20/09/96-39694694-VT-SF-ARG"<<endl;
- }
- else
- dev=false;
- dummy=(T)NULL;
- }
- template <typename T>
- List<T>::~List(){
- cout<<"Destructor de Lista tipo "<<this->type()<<": "<<endl;
- T aux;
- while(tam>0)
- {
- cout<<"Tam: "<<tam;
- aux=this->pop();
- cout<<" -> Elemento borrado ["<<aux<<"] -> Tam: "<<tam<<endl;
- }
- }
- template <typename T>
- int List<T>::delIf(bool (*ptr)(T)){
- int tot=0;
- T aux;
- for (int i=0;i<tam;i++)
- {
- aux=(*this)[i];
- if ((*ptr)(aux))
- {
- tot++;
- this->del(i);
- }
- }
- return tot;
- }
- template <typename T>
- bool List<T>::del(int _i){
- if (_i>=tam || _i<0) //si el nodo que busco no existe
- {
- cerr<<"Out of Bounds"<<endl;
- return false;
- }
- if (_i==0 && tam>0) //si es el primero
- {
- this->pop();
- return true;
- }
- Node<T>* aux=first;
- for (int x=0;x<_i;x++)
- aux=aux->sig;
- tam--;
- aux->ant->sig=aux->sig;
- if (aux->sig!=nullptr)
- aux->sig->ant=aux->ant;
- delete aux;
- return true;
- }
- template <typename T>
- List<T> List<T>::reversed(){
- List<T> aux;
- for (int i=0;i<tam;i++)
- {
- aux.push((*this)[i]);
- }
- return aux;
- }
- template <typename T>
- void List<T>::reverseList(){
- List<T> aux=(*this);
- (*this)=aux.reversed();
- }
- template <typename T>
- List<T> List<T>::sorted(){
- List<T> aux=(*this);
- aux.sortList();
- return aux;
- }
- template <typename T>
- void List<T>::sortList(){
- T aux;
- for (int i=0;i<tam-1;i++) //burbujeo
- {
- for (int j=i+1;j<tam;j++)
- {
- if ((*this)[i]>(*this)[j])
- {
- aux=(*this)[i];
- (*this)[i]=(*this)[j];
- (*this)[j]=aux;
- }
- }
- }
- }
- template <typename T>
- int List<T>::length(){
- return tam;
- }
- template <typename T>
- string List<T>::type(){
- return first->type();
- }
- template <typename T>
- bool List<T>::append(T _e){
- Node<T>* node=nullptr;
- node=new Node<T>(_e);
- if (node==nullptr){return false;}
- tam++;
- if (first==nullptr) //tam==0
- {
- first=node;
- last=node;
- }
- else
- {
- last->sig=node;
- node->ant=last;
- last=node;
- }
- return true;
- }
- template <typename T>
- bool List<T>::push(T _e){
- Node<T>* node=nullptr;
- node=new Node<T>(_e);
- if (node==nullptr){return false;}
- tam++;
- if (first==nullptr) //tam==0
- {
- first=node;
- last=node;
- }
- else
- {
- node->sig=first;
- first->ant=node;
- first=node;
- }
- return true;
- }
- template <typename T>
- bool List<T>::insertNode(T _e, int _i=0){
- if (_i<0 || _i>tam){cerr<<"Index out of bounds"<<endl;return false;}
- if (_i==tam){return append(_e);}
- if (_i==0){return push(_e);}
- Node<T>* node=nullptr;
- node=new Node<T>(_e);
- if (node==nullptr){return false;}
- Node<T>* aux=first;
- for (int x=0;x<_i;x++)
- {
- aux=aux->sig;
- }
- tam++;
- aux->ant->sig=node;
- node->ant=aux->ant;
- node->sig=aux;
- aux->ant=node;
- return true;
- }
- template <typename T>
- bool List<T>::inOrder(T _e){
- if (tam==0){return push(_e);}
- //global function type resolver, returns false and cerrs if the type is not defined watchhhhhhhhhhhh
- Node<T>* node=nullptr;
- node=new Node<T>(_e);
- if (node==nullptr){return false;}
- Node<T>* aux=first;
- int x=0;
- for (x=0;x<tam && aux->data<_e;x++)
- {
- aux=aux->sig;
- }
- return insertNode(_e,x);
- }
- template <typename T>
- T List<T>::pop(){
- if(tam==0){cerr<<"EMPTY"<<endl;return (T)(NULL);}
- T dat=first->data;
- Node<T>* aux;
- if (first->sig!=nullptr)
- first->sig->ant=nullptr;
- tam--;
- aux=first;
- first=first->sig;
- delete aux;
- if (first==nullptr)
- last=nullptr;
- return dat;
- }
- template <typename T>
- void List<T>::printSlice(int _b, int _e, int _s=1){ //begin end step
- if (_b<0 || _e>=tam)
- {
- cerr<<"Out of bounds"<<endl;
- return;
- }
- cout<<"[";
- for (int x=_b;x<_e;x+=_s)
- {
- cout<<(*this)[x];
- if (x+_s<_e)
- {
- cout<<", ";
- }
- }
- cout<<"]"<<endl;
- }
- template <typename T>
- void List<T>::printSlice(int _b){
- printSlice(_b,tam,1);
- }
- template <typename T>
- void List<T>::printSlice(){
- printSlice(0,tam,1);
- }
- template <typename T>
- void List<T>::print(){
- printSlice();
- }
- template <typename T>
- ostream& operator<<(ostream& os, List<T>& _L){
- os<<"[";
- for (int x=0;x<_L.length();x++)
- {
- os<<_L[x];
- if (x<_L.length()-1)
- {
- cout<<", ";
- }
- }
- os<<"]";
- return os;
- }
- template <typename T>
- istream& operator>>(istream& is, List<T>& _L){
- T aux;
- is>>aux;
- Node<T> n(aux);
- if (n.type()==_L.type() && n.type()!="Unknown")
- _L.append(aux);
- else
- cerr<<"Type missmatch"<<endl;
- return is;
- }
- template <typename T>
- T& List<T>::operator[](int _i){
- dummy=(T)NULL;
- if(_i>=tam || _i<0)
- {
- cerr<<"Index out of bounds"<<endl;
- return dummy;
- }
- Node<T>* aux=first;
- for (int x=0;aux!=nullptr && aux->sig!=nullptr && x<_i;x++)
- {
- aux=aux->sig;
- }
- return aux->data;
- }
- template <typename T>
- List<T> List<T>::operator+(List<T> _L){
- List<T> retL;
- for (int i=0;i<tam;i++)
- {
- retL.append((*this)[i]);
- }
- for (int i=0;i<_L.tam;i++)
- {
- retL.append(_L[i]);
- }
- return retL;
- }
- template <typename T>
- List<T> List<T>::operator/(List<T> _L){
- List<T> retL;
- int a,b,i;
- for (i=0,a=0,b=0;i<tam+_L.tam;i++)
- {
- if (a<tam)
- {
- retL.append((*this)[a++]);
- }
- if (b<_L.tam)
- {
- retL.append(_L[b++]);
- }
- }
- return retL;
- }
- template <typename T>
- void List<T>::operator=(List<T>& _L){
- bool flag=true;
- for (int i=0;i<_L.tam && flag;i++)
- {
- flag=this->append(_L[i]);
- }
- tam=_L.tam;
- }
- //}
- //----------------------------------------------------------------------------------------------------------------------
- //{ NODO
- template <typename T>
- Node<T>::Node(T _d){
- data=_d;
- sig=nullptr;
- ant=nullptr;
- }
- template <typename T>
- void Node<T>::printDet(){
- cout<<
- "["<<ant<<"]->"<<
- data<<"->["<<sig<<"]";
- }
- template <typename T>
- bool Node<T>::operator<(Node _n){
- return (data<_n.data);
- }
- template <typename T>
- bool Node<T>::operator>(Node _n){
- return (data<_n.data);
- }
- template <typename T>
- bool Node<T>::operator<=(Node _n){
- return (data<=_n.data);
- }
- template <typename T>
- bool Node<T>::operator>=(Node _n){
- return (data<=_n.data);
- }
- template <typename T>
- bool Node<T>::operator==(Node _n){
- return (data==_n.data);
- }
- template <typename T>
- bool Node<T>::operator!=(Node _n){
- return (data!=_n.data);
- }
- template <typename T>
- ostream& operator<<(ostream& os, Node<T>& _N){
- return os<<_N.getDat();
- }
- template <typename T>
- string Node<T>::type(){
- string res="Unknown";
- string cmp=(string)(typeid(data).name());
- if (cmp==(string)(typeid(int).name())){res="Integer";}
- if (cmp==(string)(typeid(double).name())){res="Double";}
- if (cmp==(string)(typeid(float).name())){res="Float";}
- if (cmp==(string)(typeid(char).name())){res="Character";}
- if (cmp==(string)(typeid(short).name())){res="Short";}
- if (cmp==(string)(typeid(long).name())){res="Long";}
- if (cmp==(string)(typeid(long long).name())){res="Long Long";}
- if (cmp==(string)(typeid(long double).name())){res="Long Double";}
- if (cmp==(string)(typeid(string).name())){res="String";}
- if (cmp==(string)(typeid(bool).name())){res="Boolean";}
- return res;
- }
- template <typename T>
- T Node<T>::getDat(){
- return data;
- }
- //}
- ---
- #include "mainFrame.h"
- //#include <graphics.h>
- mainFrame::mainFrame(char* path=(char*)"C:\\path\\path")
- {
- item_count=0;
- //arr(0);
- //int gd=DETECT,gm=0;
- //initgraph(&gd,&gm,path);
- }
- mainFrame::~mainFrame(){
- }
- int mainFrame::list_items(){
- int i;
- for (i=0;i<item_count;i++)
- {
- cout << (i+1) << ") " ;
- arr[i]->pres();
- }
- return i;
- }
- bool mainFrame::add(Object _obj){
- Object* obj = new Object(_obj);
- arr.append(obj);
- item_count++;
- return true;
- }
- ----
- #include "objects.h"
- //{Object -------------------------------------
- int Object::tkt=0;
- Object::Object(string _n="", string _d=""):name(_n),desc(_d){
- id=tkt++;
- }
- void Object::set_desc(string _d){
- desc=_d;
- }
- void Object::set_name(string _n){
- name=_n;
- }
- string Object::get_name(){
- return name;
- }
- string Object::get_desc(){
- return desc;
- }
- void Object::pres(){
- cout<<"Object: "<<desc<<endl;
- }
- //}
- //{fObject ------------------------------------
- fObject::fObject(vect _v=0, string _n="", string _d=""):pos(_v){
- this->set_name(_n);
- this->set_desc(_d);
- }
- void fObject::pres(){
- cout<<"fObject "<<desc<<endl;
- }
- //}
- ----
- #include "sprite.h"
- sprite::sprite():cont(0){
- id=tkt++;
- }
- int sprite::getCont(){
- return cont;
- }
- bool sprite::add(figura _f){
- if (arr.append(_f))
- {
- cont++;
- return true;
- }
- else
- return false;
- }
- int sprite::draw(){
- int ret;
- for (int i=0;i<cont;i++)
- {
- ret+=arr[i].draw();
- }
- return ret;
- }
- int sprite::del(){
- int ret;
- for (int i=0;i<cont;i++)
- {
- ret+=arr[i].del();
- }
- return ret;
- }
- ----
- #include "vect.h"
- #define NULL_VECT
- vect::vect(float _x=0, float _y=0, float _z=0):x(_x),y(_y),z(_z){}
- static float vect::Mod(vect v){
- return v.getMod();
- }
- static float vect::Dist(vect v1, vect v2){
- return v1.dist(v2);
- }
- static float vect::Mod(float x=0, float y=0, float z=0){
- vect v(x,y,z);
- return v.getMod();
- }
- double vect::getMod(){
- return sqrt(pow(x,2)+pow(y,2)+pow(z,2));
- }
- float vect::getX(){
- return x;
- }
- float vect::getY(){
- return y;
- }
- float vect::getZ(){
- return z;
- }
- float vect::dist(vect v){
- return Mod( (*this) - v );
- }
- void vect::setVal(float _x=0, float _y=0, float _z=0){
- x=_x;
- y=_y;
- z=_z;
- }
- vect vect::operator+(vect v){
- vect res(x+v.x,y+v.y,z+v.z);return res;
- }
- vect vect::operator-(vect v){
- vect res(x-v.x,y-v.y,z-v.z);return res;
- }
- vect vect::operator*(vect v){
- return (x*v.x+y*v.y+z*v.z);
- }
- void vect::operator=(float mod){
- x=mod;
- y=0;
- z=0;
- }
- ostream& operator<<(ostream& os, vect _v){
- /*depends on final properties*/
- return os;
- }
- istream& operator>>(istream& is, vect& _v){
- /*depends on final properties*/
- return is;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement