Hi, I'm back :P.
I'm programming a MUD game with the book "MUD game programming by Ron Penton" and i have had some issues that i can't get the solution.
Here, This is the entityDataBase class(the code is in spanish but can be understand it)
There are some problems like these:
27 expected `)' before '&' token
In member function `database& Tyrim::EntityBaseDatos<database>::iterator::operator*()':
35 `itr' undeclared (first use this function)
I can't understand it. I work with Dev C++, and the problem is in "typedef map<entityid, database> contenedor;"
Display All
//class Entity
Display All
Thanks.
I'm programming a MUD game with the book "MUD game programming by Ron Penton" and i have had some issues that i can't get the solution.
Here, This is the entityDataBase class(the code is in spanish but can be understand it)
There are some problems like these:
27 expected `)' before '&' token
In member function `database& Tyrim::EntityBaseDatos<database>::iterator::operator*()':
35 `itr' undeclared (first use this function)
I can't understand it. I work with Dev C++, and the problem is in "typedef map<entityid, database> contenedor;"
C Source Code
- #ifndef ENTITYBASEDATOS_H
- #define ENTITYBASEDATOS_H
- #include <string>
- #include <map>
- #include <vector>
- #include <fstream>
- #include <iterator>
- #include "Entity.h"
- using std::istream;
- using std::ostream;
- namespace Tyrim{
- template<class database>
- class EntityBaseDatos{
- public:
- typedef map<entityid, database> contenedor;
- //clase que hereda de iterator
- class iterator : public contenedor::iterator{
- public:
- iterator(){}//constructor por defecto
- iterator(contenedor::iterator& p_itr){ //constructor copia
- contenedor::iterator& itr = *this;
- itr = p_itr;
- }
- //desreferencia el iterador para devolver la referencia a la que apunta
- inline database& operator*(){
- contenedor::iterator& itr = *this;
- return itr->second;
- }
- inline database* operator->(){
- contenedor::iterator& itr = *this;
- return &(itr->second);
- }
- };//end class iterator
- inline static iterator begin(){
- return iterator(m_map.begin());
- }
- inline static iterator end(){
- return iterator(m_map.end());
- }
- inline static iterator find(entityid p_id){
- return iterator(m_map.find(p_id));
- }
- static iterator findfull(const string& p_str){
- return std::find_if(begin(),end(),BusquedaEntDeEntity(p_str));
- }
- static iterator find(const string& p_str){
- return double_find_if(begin(),end(),BusquedaEntDeEntity(p_str),BusquedaParcDeEntity(p_str));
- }
- inline static database& get(entityid p_id){
- iterator itr = find(p_id);
- if(itr == 0)
- throw std::exception();
- return *itr;
- }
- inline static bool has(entityid p_id){
- return (m_map.find(p_id) != m_map.end());
- }
- inline static bool hasfull(const string& p_str){
- return findfull(p_str) != end();
- }
- inline static bool has(const string& p_str){
- return find(p_str) != end();
- }
- inline static int size(){return (int)m_map.size();}
- static entityid EncontrarDisponibleID(){
- if(m_map.size() == 0)
- return 1;
- if(m_map.size() == m_map.rend()->first)
- return m_map.size() + 1;
- entityid dispid = 0;
- entityid previo = 0;
- map<entityid,database>::iterator itr = m_map.begin();
- while(!dispid){
- if(itr->firts != previo + 1)
- dispid = previo + 1;
- else
- previo = itr->first;
- itr++;
- }
- return dispid;
- }
- protected:
- static map<entityid, database> m_map;
- }; //end class EntityBaseDatos
- //class o typename lo mismo es
- template<typename database>
- class EntityBaseDatosVector{
- typedef std::vector<database>::iterator iterator;
- public:
- inline static iterator begin(){return m_vector.begin() + 1;}
- inline static iterator end(){return m_vector.end();}
- inline static size_t size(){return m_vector.size() - 1;}
- inline static database& get(entityid p_id){
- if(p_id >= m_vector.size() || p_id == 0)
- throw std::exception();
- return m_vector[p_id];
- }
- protected:
- static std::vector<database> m_vector;
- };
- }//end Tyrim
- #endif
//class Entity
C Source Code
- #ifndef ENTITY_H
- #define ENTITY_H
- #include <string>
- #include "Librerias/BasicLib.h"
- using namespace std;
- namespace Tyrim{
- typedef unsigned int entityid;
- class Entity{
- public:
- //constructor
- inline Entity(){
- m_id = 0;
- m_name = "UNDEFINED";
- }
- inline string& Nombre(){return m_name;}
- inline entityid& id(){return m_id;}
- inline string NomMin(){
- return BasicLib::LowerCase(m_name);
- }
- inline bool BuscarEnt(const string& p_str){
- return NomMin() == BasicLib::LowerCase(p_str);
- }
- inline bool BuscarParcial(const string& p_str){
- if(p_str.size() == 0)
- return true;
- string nombre = NomMin();
- string busqueda = BasicLib::LowerCase(p_str);
- size_t pos = nombre.find(busqueda);
- while(pos != string::npos){
- if(pos == 0 || m_name[pos -1] == ' '){
- return true;
- }
- pos = nombre.find(busqueda, pos +1);
- }
- return false;
- }
- protected:
- entityid m_id;
- string m_name;
- };
- struct BusquedaEntDeEntity{
- BusquedaEntDeEntity(const string& p_str)
- :m_name(p_str){/*No hace nada*/};
- bool operator()(Entity& p_entity){
- return p_entity.BuscarEnt(m_name);
- }
- bool operator()(Entity* p_entity){
- return p_entity != 0 && p_entity->BuscarEnt(m_name);
- }
- string m_name;
- }; //end clase Entity
- struct BusquedaParcDeEntity{
- BusquedaParcDeEntity(const string& p_str)
- :m_name(p_str){/*No hace nade*/}
- bool operator()(Entity& p_entity){
- return p_entity.BuscarParcial(m_name);
- }
- bool operator()(Entity* p_entity){
- return p_entity != 0 && p_entity->BuscarParcial(m_name);
- }
- string m_name;
- };
- } //end namespace Tyrim
- #endif
Thanks.
Be a pointer my friend