Version inicial en v2017 partiendo de la v2008
commit
d31aa6abec
|
|
@ -0,0 +1,64 @@
|
||||||
|
/lib
|
||||||
|
/bin
|
||||||
|
/includes
|
||||||
|
/utiles.suo
|
||||||
|
/utiles.ncb
|
||||||
|
/utiles.aps
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
*.Cache
|
||||||
|
*.bak
|
||||||
|
*.ncb
|
||||||
|
/Debug/vc90.pdb
|
||||||
|
/Debug/_app.obj
|
||||||
|
/Debug/_error.obj
|
||||||
|
/Debug/_log.obj
|
||||||
|
/Debug/_proceso.obj
|
||||||
|
/Debug/ascii_file.obj
|
||||||
|
/Debug/b_file.obj
|
||||||
|
/Debug/bmp_control.obj
|
||||||
|
/Debug/BuildLog.htm
|
||||||
|
/Debug/cola_asincrona.obj
|
||||||
|
/Debug/control_usu_con.obj
|
||||||
|
/Debug/Csock_cl.obj
|
||||||
|
/Debug/csv_file.obj
|
||||||
|
/Debug/DijkstraUtiles.obj
|
||||||
|
/Debug/dir_manager.obj
|
||||||
|
/Debug/gconect_srv.obj
|
||||||
|
/Debug/ini_file.obj
|
||||||
|
/Debug/lock.obj
|
||||||
|
/Debug/mapmatrix.obj
|
||||||
|
/Debug/mt.dep
|
||||||
|
/Debug/proceso_cliente.obj
|
||||||
|
/Debug/puerto_com.obj
|
||||||
|
/Debug/sock_http.obj
|
||||||
|
/Debug/sock_sv.obj
|
||||||
|
/Debug/static_array.obj
|
||||||
|
/Debug/static_array_ord.obj
|
||||||
|
/Debug/static_cola.obj
|
||||||
|
/Debug/stdafx.obj
|
||||||
|
/Debug/str_array.obj
|
||||||
|
/Debug/TaskProcess.obj
|
||||||
|
/Debug/th.obj
|
||||||
|
/Debug/utiles.dll
|
||||||
|
/Debug/utiles.dll.embed.manifest
|
||||||
|
/Debug/utiles.dll.embed.manifest.res
|
||||||
|
/Debug/utiles.dll.intermediate.manifest
|
||||||
|
/Debug/utiles.exp
|
||||||
|
/Debug/utiles.ilk
|
||||||
|
/Debug/utiles.lib
|
||||||
|
/Debug/utiles.obj
|
||||||
|
/Debug/utiles.pch
|
||||||
|
/Debug/utiles.pdb
|
||||||
|
/Debug/utiles.res
|
||||||
|
/Debug/utiles_dll.obj
|
||||||
|
/Debug/utl.obj
|
||||||
|
/Debug/vc90.idb
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||||
|
# Visual Studio 2008
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "utiles", "utiles.vcproj", "{AA58C828-7025-4A4C-868E-76B8902AF6BB}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Win32 = Debug|Win32
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Release|Win32 = Release|Win32
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{AA58C828-7025-4A4C-868E-76B8902AF6BB}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||||
|
{AA58C828-7025-4A4C-868E-76B8902AF6BB}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
|
{AA58C828-7025-4A4C-868E-76B8902AF6BB}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{AA58C828-7025-4A4C-868E-76B8902AF6BB}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{AA58C828-7025-4A4C-868E-76B8902AF6BB}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
|
{AA58C828-7025-4A4C-868E-76B8902AF6BB}.Release|Win32.Build.0 = Release|Win32
|
||||||
|
{AA58C828-7025-4A4C-868E-76B8902AF6BB}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{AA58C828-7025-4A4C-868E-76B8902AF6BB}.Release|x64.Build.0 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
|
|
@ -0,0 +1,695 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "CartoBase.h"
|
||||||
|
#include "CartoBaseShpManager.h"
|
||||||
|
#include "CartoBaseDBFManager.h"
|
||||||
|
#include "dir_manager.h"
|
||||||
|
#include "Fdbf.h"
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBase::CartoBase(void)
|
||||||
|
{
|
||||||
|
ref = 0;
|
||||||
|
typeIA = IntIa;
|
||||||
|
strcpy(iaName, "Ia");
|
||||||
|
iaEx =this;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
|
||||||
|
CartoBase::~CartoBase(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::getNumberEntities()
|
||||||
|
{
|
||||||
|
return _entities.n;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double* CartoBase::getPto(int i)
|
||||||
|
{
|
||||||
|
return _points[i].pts;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::getNumberPtos()
|
||||||
|
{
|
||||||
|
return _points.n;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseInfoEntity CartoBase::getEntity(int i)
|
||||||
|
{
|
||||||
|
return get(i);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseInfoEntity CartoBase::get(int i)
|
||||||
|
{
|
||||||
|
return CartoBaseInfoBuilder::get(i, this);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseInfoEntity CartoBase::getRef(int r)
|
||||||
|
{
|
||||||
|
return CartoBaseInfoBuilder::get(refIndex[r], this);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::getEntityRef( int ientity )
|
||||||
|
{
|
||||||
|
return _entities[ientity].ref;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::add(CartoEntity& element)
|
||||||
|
{
|
||||||
|
bool res = 0<=element.CopyInTo(this);
|
||||||
|
if(res && iaEx && typeIA != NIa)
|
||||||
|
iaEx->IaAdd(_entities[_entities.n-1].ref);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::add(CartoBase& cad)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::grabar(char *path)
|
||||||
|
{
|
||||||
|
Cb_file f;
|
||||||
|
if(!f.abre(path,2,1))
|
||||||
|
return false;
|
||||||
|
return grabar(&f);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::leer(char *path)
|
||||||
|
{
|
||||||
|
Cb_file f;
|
||||||
|
if(!f.abre(path,1,0,true))
|
||||||
|
return false;
|
||||||
|
return leer(&f);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::grabar(Cb_file *f)
|
||||||
|
{
|
||||||
|
char st[16];
|
||||||
|
int version;
|
||||||
|
memset(st,0,16);
|
||||||
|
strcpy(st,TYPE_FILE);
|
||||||
|
if(!f->escribe(st, 16))
|
||||||
|
return false;
|
||||||
|
version = VERSION_CART_BASE;
|
||||||
|
if(!f->escribe(&version, sizeof(version)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!f->escribe(&_defaultColor, sizeof(_defaultColor)))
|
||||||
|
return false;
|
||||||
|
if(!f->escribe(&_defaultpaintedProps, sizeof(_defaultpaintedProps)))
|
||||||
|
return false;
|
||||||
|
if(!_entities.graba(f))
|
||||||
|
return false;
|
||||||
|
if(!_points.graba(f))
|
||||||
|
return false;
|
||||||
|
if(!_lines.graba(f))
|
||||||
|
return false;
|
||||||
|
if(!_paintedProps.graba(f))
|
||||||
|
return false;
|
||||||
|
if(!_colors.graba(f))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::leer (Cb_file* f)
|
||||||
|
{
|
||||||
|
char st[16];
|
||||||
|
int version;
|
||||||
|
memset(st,0,16);
|
||||||
|
if(!f->lee(st, 16) || strcmp(st, TYPE_FILE))
|
||||||
|
return false;
|
||||||
|
if(!f->lee(&version, sizeof(version)) || version!= VERSION_CART_BASE)
|
||||||
|
return false;
|
||||||
|
if(!f->lee(&_defaultColor, sizeof(_defaultColor)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!f->lee(&_defaultpaintedProps, sizeof(_defaultpaintedProps)))
|
||||||
|
return false;
|
||||||
|
_entities.n = 0;
|
||||||
|
if(!_entities.leer(f))
|
||||||
|
return false;
|
||||||
|
_points.n = 0;
|
||||||
|
if(!_points.leer(f))
|
||||||
|
return false;
|
||||||
|
_lines.n = 0;
|
||||||
|
if(!_lines.leer(f))
|
||||||
|
return false;
|
||||||
|
_paintedProps.n = 0;
|
||||||
|
if(!_paintedProps.leer(f))
|
||||||
|
return false;
|
||||||
|
_colors.n = 0;
|
||||||
|
if(!_colors.leer(f))
|
||||||
|
return false;
|
||||||
|
iniIndexRef();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::add(CartoBaseEntity* src)
|
||||||
|
{
|
||||||
|
if(_entities+(*src))
|
||||||
|
{
|
||||||
|
_entities[_entities.n-1].ref = ref;
|
||||||
|
refIndex[ref++] = _entities.n-1;
|
||||||
|
return _entities.n-1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::add(CartoBasePoint* src)
|
||||||
|
{
|
||||||
|
if(_points+(*src))
|
||||||
|
return _points.n-1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::add(CartoBaseLine* src)
|
||||||
|
{
|
||||||
|
if(_lines+(*src))
|
||||||
|
return _lines.n-1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::add(CartoBasePaintedProps* src)
|
||||||
|
{
|
||||||
|
if(_paintedProps+(*src))
|
||||||
|
return _paintedProps.n-1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::add(CartoBaseColor* src)
|
||||||
|
{
|
||||||
|
if(_colors+(*src))
|
||||||
|
return _colors.n-1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBase::addDefaultPaintedProps()
|
||||||
|
{
|
||||||
|
_defaultpaintedProps.color = _colors.n;
|
||||||
|
_colors+_defaultColor;
|
||||||
|
_paintedProps+_defaultpaintedProps;
|
||||||
|
_defaultpaintedProps.color = -1;
|
||||||
|
return _paintedProps.n-1;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void CartoBase::del()
|
||||||
|
{
|
||||||
|
_entities.n=0;
|
||||||
|
_points.n=0;
|
||||||
|
_lines.n=0;
|
||||||
|
_paintedProps.n=0;
|
||||||
|
_colors.n=0;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
EntitiesArray* CartoBase::filter(EntitiesArray* dst, FilterEntities* filter)
|
||||||
|
{
|
||||||
|
CartoBaseInfoEntity e = get(0);
|
||||||
|
while(e.isValid())
|
||||||
|
{
|
||||||
|
if(filter->IsSeletedEntity(&e))
|
||||||
|
{
|
||||||
|
if(!((*dst)+e))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
e = e.next();
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::remove(int i)
|
||||||
|
{
|
||||||
|
if(i<_entities.n)
|
||||||
|
{
|
||||||
|
_entities[i].flagsInt |= CARTOBASE_DELETED_ENTITY;
|
||||||
|
if(iaEx)
|
||||||
|
iaEx->IaRemove(_entities[i].ref);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::removeRef(int r)
|
||||||
|
{
|
||||||
|
return remove(refIndex[r]);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::clear()
|
||||||
|
{
|
||||||
|
return false;//no funciona
|
||||||
|
//verifica entidades
|
||||||
|
int ind =0;
|
||||||
|
std::map<int,int> indsl;
|
||||||
|
int il,ip,ic, id;
|
||||||
|
std::map<int,int> indsp;
|
||||||
|
std::map<int,int> indsc;
|
||||||
|
std::map<int,int> indsd;//indices de pintado
|
||||||
|
il = ip=ic=id = 0;
|
||||||
|
//borra entidades marcadas
|
||||||
|
for(int i =0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
if(_entities[i].flagsInt & CARTOBASE_DELETED_ENTITY)
|
||||||
|
continue;
|
||||||
|
if(i == ind)
|
||||||
|
{
|
||||||
|
ind++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_entities[ind++]=_entities[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//si borrados
|
||||||
|
if(ind == _entities.n)
|
||||||
|
goto ajus_mem;
|
||||||
|
|
||||||
|
//verifica
|
||||||
|
_entities.n = ind;
|
||||||
|
for(int i =0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
int aux = _entities[i].idPaintp;
|
||||||
|
//revisa propiedades de pintado
|
||||||
|
if(indsd.find(aux) == indsd.end())
|
||||||
|
{
|
||||||
|
indsd[aux] = id++;
|
||||||
|
//revisa color
|
||||||
|
if(indsc.find(_paintedProps[i].color) == indsc.end())
|
||||||
|
indsc[_paintedProps[i].color] =ic++;
|
||||||
|
_paintedProps[i].color = indsc[_paintedProps[i].color];
|
||||||
|
}
|
||||||
|
_entities[i].idPaintp = indsd[aux];
|
||||||
|
//segun tipo de entidad
|
||||||
|
aux =_entities[i].id;
|
||||||
|
switch(_entities[i].type)
|
||||||
|
{
|
||||||
|
case(CartoBaseTypes::Point):
|
||||||
|
{
|
||||||
|
if(indsp.find(aux) == indsp.end())
|
||||||
|
indsp[aux] = ip++;
|
||||||
|
_entities[i].id = indsp[aux];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(CartoBaseTypes::Line):
|
||||||
|
{
|
||||||
|
if(indsl.find(aux) == indsl.end())
|
||||||
|
{
|
||||||
|
indsl[aux] = il++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nn = _lines[aux].n;
|
||||||
|
aux= _lines[aux].ini;
|
||||||
|
|
||||||
|
for(int ii =0; ii<nn; ii++)
|
||||||
|
{
|
||||||
|
if(indsp.find(aux+ii) == indsp.end())
|
||||||
|
indsp[aux+ii] = ip++;
|
||||||
|
}
|
||||||
|
_lines[_entities[i].id].ini = indsp[aux];
|
||||||
|
|
||||||
|
_entities[i].id = indsl[_entities[i].id];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//recolocacion---------------------
|
||||||
|
|
||||||
|
for (std::map<int, int>::iterator
|
||||||
|
iid = indsp.begin();
|
||||||
|
iid != indsp.end();
|
||||||
|
++iid)
|
||||||
|
{
|
||||||
|
if(iid->second ==iid->first)
|
||||||
|
continue;
|
||||||
|
_points[iid->second] = _points[iid->first];
|
||||||
|
}
|
||||||
|
_points.n=(int)indsp.size();
|
||||||
|
for (std::map<int, int>::iterator
|
||||||
|
iid = indsl.begin();
|
||||||
|
iid != indsl.end();
|
||||||
|
++iid)
|
||||||
|
{
|
||||||
|
if(iid->second ==iid->first)
|
||||||
|
continue;
|
||||||
|
_lines[iid->second] = _lines[iid->first];
|
||||||
|
}
|
||||||
|
_lines.n=(int)indsl.size();
|
||||||
|
for (std::map<int, int>::iterator
|
||||||
|
iid = indsd.begin();
|
||||||
|
iid != indsd.end();
|
||||||
|
++iid)
|
||||||
|
{
|
||||||
|
if(iid->second ==iid->first)
|
||||||
|
continue;
|
||||||
|
_paintedProps[iid->second] = _paintedProps[iid->first];
|
||||||
|
}
|
||||||
|
_paintedProps.n=(int)indsd.size();
|
||||||
|
for (std::map<int, int>::iterator
|
||||||
|
iid = indsc.begin();
|
||||||
|
iid != indsc.end();
|
||||||
|
++iid)
|
||||||
|
{
|
||||||
|
if(iid->second ==iid->first)
|
||||||
|
continue;
|
||||||
|
_colors[iid->second] = _colors[iid->first];
|
||||||
|
}
|
||||||
|
_colors.n=(int)indsc.size();
|
||||||
|
|
||||||
|
ajus_mem:
|
||||||
|
//ajusta memoria
|
||||||
|
if(!_entities.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
if(!_points.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
if(!_lines.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
if(!_paintedProps.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
if(!_colors.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
indexRef();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::FastClear()
|
||||||
|
{
|
||||||
|
//verifica entidades
|
||||||
|
|
||||||
|
int ind =0;
|
||||||
|
//borra entidades marcadas
|
||||||
|
for(int i =0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
if(_entities[i].flagsInt & CARTOBASE_DELETED_ENTITY)
|
||||||
|
continue;
|
||||||
|
if(i == ind)
|
||||||
|
{
|
||||||
|
ind++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_entities[ind++]=_entities[i];
|
||||||
|
}
|
||||||
|
_entities.n =ind;
|
||||||
|
reIndexRef();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::MemClear()
|
||||||
|
{
|
||||||
|
if(!FastClear())
|
||||||
|
return false;
|
||||||
|
int npts =0;
|
||||||
|
int nlin=0;
|
||||||
|
//cuenta tipos de entidades-----------
|
||||||
|
for(int i =0; i< _entities.n; i++)
|
||||||
|
{
|
||||||
|
switch(_entities[i].type)
|
||||||
|
{
|
||||||
|
case(CartoBaseTypes::Point):
|
||||||
|
npts++;
|
||||||
|
break;
|
||||||
|
case(CartoBaseTypes::Line):
|
||||||
|
|
||||||
|
nlin++;
|
||||||
|
npts+=_lines[_entities[i].id].n;
|
||||||
|
break;;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i =0; i<_paintedProps.n; i++)
|
||||||
|
_paintedProps[i].flags &= ~0x1;
|
||||||
|
for(int i =0; i<_colors.n; i++)
|
||||||
|
_colors[i].flags &= ~0x1;
|
||||||
|
Cgarray<CartoBasePoint> points;//coordenadas
|
||||||
|
Cgarray<CartoBaseLine> lines;//lineas
|
||||||
|
Cgarray<CartoBasePaintedProps> paintedProps;//propiedades de pintado
|
||||||
|
Cgarray<CartoBaseColor> colors;
|
||||||
|
//pide memoria para arrays auxiliares
|
||||||
|
|
||||||
|
if(!(points+=npts))
|
||||||
|
return false;
|
||||||
|
if(!(lines+=nlin))
|
||||||
|
return false;
|
||||||
|
for(int i =0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
CartoBaseInfoEntity e =get(i);
|
||||||
|
|
||||||
|
switch(e.entity()->type)
|
||||||
|
{
|
||||||
|
case(CartoBaseTypes::Point):
|
||||||
|
points+ *e.pto();
|
||||||
|
e.entity()->id = points.n-1;
|
||||||
|
break;
|
||||||
|
case(CartoBaseTypes::Line):
|
||||||
|
lines+*e.line();
|
||||||
|
lines[lines.n-1].ini = points.n;
|
||||||
|
for(int jj =0; jj<e.line()->n; jj++)
|
||||||
|
points+ e.pto()[jj];
|
||||||
|
e.entity()->id = lines.n-1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//revisa propiedades de pintado
|
||||||
|
if(e.paintp()->flags & 0x1)
|
||||||
|
{
|
||||||
|
e.entity()->idPaintp = e.paintp()->color;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
paintedProps+*e.paintp();
|
||||||
|
//revisa color
|
||||||
|
|
||||||
|
if(e.color()->flags & 0x1)
|
||||||
|
{
|
||||||
|
paintedProps[paintedProps.n-1].color = e.color()->color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
paintedProps[paintedProps.n-1].color = colors.n;
|
||||||
|
colors+*e.color();
|
||||||
|
e.color()->flags |=0x1 ;
|
||||||
|
e.color()->color = colors.n-1;
|
||||||
|
}
|
||||||
|
e.paintp()->flags |= 0x1;
|
||||||
|
e.entity()->idPaintp = paintedProps.n;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_colors.ptr)
|
||||||
|
free(_colors.ptr);
|
||||||
|
_colors = colors;
|
||||||
|
colors.ptr = NULL;
|
||||||
|
|
||||||
|
if(_lines.ptr)
|
||||||
|
free(_lines.ptr);
|
||||||
|
_lines = lines;
|
||||||
|
lines.ptr = NULL;
|
||||||
|
|
||||||
|
if(_paintedProps.ptr)
|
||||||
|
free(_paintedProps.ptr);
|
||||||
|
_paintedProps = paintedProps;
|
||||||
|
paintedProps.ptr = NULL;
|
||||||
|
|
||||||
|
if(_points.ptr)
|
||||||
|
free(_points.ptr);
|
||||||
|
_points = points;
|
||||||
|
points.ptr = NULL;
|
||||||
|
|
||||||
|
//ajusta memoria
|
||||||
|
if(!_entities.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
if(!_points.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
if(!_lines.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
if(!_paintedProps.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
if(!_colors.ajusta_mem())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::importShp(char* path)
|
||||||
|
{
|
||||||
|
CartoBaseShpManager shp;
|
||||||
|
Cb_file f;
|
||||||
|
char patdbf[256];
|
||||||
|
if(!f.abre(path,1,0,1))
|
||||||
|
return false;
|
||||||
|
shp.set(this);
|
||||||
|
int oldia =typeIA ;
|
||||||
|
typeIA = NIa;
|
||||||
|
if(!shp.ImportShp(&f))
|
||||||
|
{
|
||||||
|
typeIA = oldia;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
typeIA = oldia;
|
||||||
|
if(typeIA== NIa || typeIA == IntIa)
|
||||||
|
return true;
|
||||||
|
CartoBaseDBFManager dbf;
|
||||||
|
return dbf.leer(Cdir_manager::cambia_extension_archivo(path,patdbf,"dbf"),this);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::exportShp(char* path)
|
||||||
|
{
|
||||||
|
return fexportShp(path);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::ptosExportShp(char* path)
|
||||||
|
{
|
||||||
|
return fexportShp(path, CartoBaseTypes::Point);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::linesExportShp(char* path)
|
||||||
|
{
|
||||||
|
return fexportShp(path, CartoBaseTypes::Line);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::fexportShp(char* path, int type)
|
||||||
|
{
|
||||||
|
char patdbf[256];
|
||||||
|
|
||||||
|
CartoBaseShpManager shp;
|
||||||
|
|
||||||
|
Cb_file f;
|
||||||
|
Cb_file fshx;
|
||||||
|
|
||||||
|
if(!f.abre(path,2,1))
|
||||||
|
return false;
|
||||||
|
if(!fshx.abre(Cdir_manager::cambia_extension_archivo(path,patdbf,"shx"),2,1))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!shp.ExportShp(&f,&fshx,this, type))
|
||||||
|
return false;
|
||||||
|
if(typeIA== NIa)
|
||||||
|
return true;
|
||||||
|
CartoBaseDBFManager dbf;
|
||||||
|
FiterCartoBase enti;
|
||||||
|
if(type == CartoBaseTypes::Ndef)
|
||||||
|
type = _entities[0].type;
|
||||||
|
for(int i =0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
if(_entities[i].type == type)
|
||||||
|
enti.ind+i;
|
||||||
|
|
||||||
|
}
|
||||||
|
enti.cb = this;
|
||||||
|
return dbf.grabar(Cdir_manager::cambia_extension_archivo(path,patdbf,"dbf"), this,&enti);
|
||||||
|
//exporta dbf;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void CartoBase::iniIndexRef()
|
||||||
|
{
|
||||||
|
refIndex.clear();
|
||||||
|
for(int i=0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
_entities[i].ref=i;
|
||||||
|
refIndex[i]=i;
|
||||||
|
}
|
||||||
|
ref = _entities.n;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void CartoBase::reIndexRef()
|
||||||
|
{
|
||||||
|
refIndex.clear();
|
||||||
|
for(int i=0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
refIndex[_entities[i].ref]=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void CartoBase::indexRef(bool buscaRepes)
|
||||||
|
{
|
||||||
|
refIndex.clear();
|
||||||
|
int ref_max=-1;
|
||||||
|
int r;
|
||||||
|
bool repes =false;
|
||||||
|
//busca maximo u si hay repes
|
||||||
|
for(int i=0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
r =_entities[i].ref;
|
||||||
|
refIndex[r]=i;
|
||||||
|
if(r>ref_max)
|
||||||
|
ref_max = r;
|
||||||
|
}
|
||||||
|
if(ref<= ref_max)
|
||||||
|
ref = ref_max;
|
||||||
|
if(!buscaRepes)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(int i=0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
r =_entities[i].ref;
|
||||||
|
if(refIndex[r]!= i)
|
||||||
|
{
|
||||||
|
//referencias repetidas
|
||||||
|
_entities[i].ref =ref;
|
||||||
|
refIndex[ref] = i;
|
||||||
|
ref++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void* CartoBase::getIa( int refEnt )
|
||||||
|
{
|
||||||
|
if(iaEx)
|
||||||
|
return iaEx->IaGet(refEnt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void CartoBase::setExIa( DataIaCartoBase* ia )
|
||||||
|
{
|
||||||
|
typeIA = ExIa;
|
||||||
|
iaEx=ia;
|
||||||
|
iaEx->CBSet(this);
|
||||||
|
//añade a ia entidades existentes
|
||||||
|
for (int i =0; i<_entities.n; i++)
|
||||||
|
{
|
||||||
|
if(_entities[i].flagsInt & CARTOBASE_DELETED_ENTITY)
|
||||||
|
continue;
|
||||||
|
iaEx->IaAdd((_entities[i].ref));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::IaGetSize( int *ncolm )
|
||||||
|
{
|
||||||
|
*ncolm =1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::IaGetColm( int icol, char* name, BYTE *type, int *size, int*ndecimal )
|
||||||
|
{
|
||||||
|
if(icol!=0)
|
||||||
|
return false;
|
||||||
|
*size = 10;
|
||||||
|
*ndecimal=0;
|
||||||
|
*type = DBF_TYPE_DATA_I;
|
||||||
|
strcpy(name,iaName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBase::IaGetVal( int refEnt, int icol, int* v )
|
||||||
|
{
|
||||||
|
if(icol!=0)
|
||||||
|
return false;
|
||||||
|
*v =getRef(refEnt).entity()->ia;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void CartoBase::setNameIa( char *name )
|
||||||
|
{
|
||||||
|
strcpy(iaName, name);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
|
||||||
|
CartoBaseInfoEntity FiterCartoBase::getEntity( int i )
|
||||||
|
{
|
||||||
|
return cb->get(ind[i]);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int FiterCartoBase::getNumberEntities()
|
||||||
|
{
|
||||||
|
return ind.n;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
|
@ -0,0 +1,134 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef CartoBase_h
|
||||||
|
#define CartoBase_h
|
||||||
|
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "CartoBaseDef.h"
|
||||||
|
#include "CartoBaseElements.h"
|
||||||
|
#include "CartoElements.h"
|
||||||
|
#include "IaDataTable.h"
|
||||||
|
#include <map>
|
||||||
|
/*
|
||||||
|
hacer el memoryclear
|
||||||
|
guardar dbf ia
|
||||||
|
*/
|
||||||
|
class Cb_file;
|
||||||
|
class UTILES_EXPORT CartoBase: public SetEntities, public SetPtsR, public DataIaCartoBase
|
||||||
|
{
|
||||||
|
//clases amigo-----------------
|
||||||
|
friend class CartoBaseInfoEntity;
|
||||||
|
friend class CartoBaseInfoPto;
|
||||||
|
friend class CartoBaseInfoLine;
|
||||||
|
friend class CartoBaseInfoBuilder;
|
||||||
|
friend class CartoPto;
|
||||||
|
friend class CartoLine;
|
||||||
|
private:
|
||||||
|
//info interna-------------------------------
|
||||||
|
int ref;//referencia para el siguiente elemento
|
||||||
|
CartoBasePaintedProps _defaultpaintedProps;
|
||||||
|
CartoBaseColor _defaultColor;
|
||||||
|
//array de informacion de entidades
|
||||||
|
Cgarray<CartoBaseEntity> _entities;//entidades
|
||||||
|
Cgarray<CartoBasePoint> _points;//coordenadas
|
||||||
|
Cgarray<CartoBaseLine> _lines;//lineas
|
||||||
|
Cgarray<CartoBasePaintedProps> _paintedProps;//propiedades de pintado
|
||||||
|
Cgarray<CartoBaseColor> _colors;
|
||||||
|
std::map<int, int> refIndex;//indexado por referencias;
|
||||||
|
//datos de ia-----------------------------------------
|
||||||
|
char iaName[12];//nombre columna ia tipo IntIa
|
||||||
|
int typeIA;//indica el tipo de informacion asociada que se utilizara
|
||||||
|
public:
|
||||||
|
|
||||||
|
IaDataTable dataIa;
|
||||||
|
DataIaCartoBase *iaEx;
|
||||||
|
enum TypedataIa
|
||||||
|
{
|
||||||
|
NIa=0,//sin informacion asociada
|
||||||
|
IntIa,//usa solo un entero por entidad como ia con nombre de columna iaName
|
||||||
|
DtIa,//usa la dataIa para almacenar info asociada
|
||||||
|
ExIa//informacion asociada externa
|
||||||
|
};
|
||||||
|
|
||||||
|
CartoBase(void);
|
||||||
|
~CartoBase(void);
|
||||||
|
|
||||||
|
//funciones-----------------------------------------------------------------
|
||||||
|
CartoBaseInfoEntity get(int i);//acceso a entidad iesima (modo lectura)
|
||||||
|
CartoBaseInfoEntity getRef(int r);//acceso a entidad con referencia r (modo lectura)
|
||||||
|
|
||||||
|
|
||||||
|
//añade elementos
|
||||||
|
bool add(CartoEntity& element);
|
||||||
|
bool add(CartoBase& cad);
|
||||||
|
|
||||||
|
bool remove(int i);//pone marca de flag de borrado (pero sigue siendo accesible)
|
||||||
|
bool removeRef(int r);
|
||||||
|
|
||||||
|
bool FastClear();//solo borra entidades y rehace las referencias
|
||||||
|
bool clear();//limpia elementos borrados y ajusta memoria
|
||||||
|
bool MemClear();//limpia memoria de todos los arrays
|
||||||
|
|
||||||
|
EntitiesArray* filter(EntitiesArray* dst, FilterEntities *filter);
|
||||||
|
|
||||||
|
virtual bool leer(char *path);
|
||||||
|
virtual bool grabar(char *path);
|
||||||
|
virtual bool leer(Cb_file *f);
|
||||||
|
virtual bool grabar(Cb_file *f);
|
||||||
|
|
||||||
|
int addDefaultPaintedProps();//crea unas propiedades de pintado como las por defecto
|
||||||
|
|
||||||
|
bool importShp(char* path);//importa shp
|
||||||
|
bool exportShp(char* path);//exporta a shp (todos los tipos que cuinciden con la primera)
|
||||||
|
bool ptosExportShp(char* path);
|
||||||
|
bool linesExportShp(char* path);
|
||||||
|
|
||||||
|
void del();//limpia toda la carto (sin liberar memoria)
|
||||||
|
|
||||||
|
//funciones de ia-------------------------------------------------------------------
|
||||||
|
void* getIa(int refEnt);//devuelve informacion asociada externa de la entidad refEnt
|
||||||
|
int getTypeIA(){return typeIA;}//devuelve el tipo de ia que tiene actualmente
|
||||||
|
void setExIa(DataIaCartoBase* ia);//setea un ia externo
|
||||||
|
int getEntityRef(int ientity);//devuelve la referencia
|
||||||
|
void setNameIa(char *name);//pone el nombre de la col
|
||||||
|
|
||||||
|
//funciones por ser SetEntities
|
||||||
|
virtual CartoBaseInfoEntity getEntity(int i);
|
||||||
|
virtual int getNumberEntities();
|
||||||
|
//funciones por ser SetPts
|
||||||
|
virtual double* getPto(int i);
|
||||||
|
virtual int getNumberPtos();
|
||||||
|
//funciones auxiliares------------
|
||||||
|
int getNexRef(){return ref;};
|
||||||
|
|
||||||
|
//funciones DataIaCartoBase
|
||||||
|
virtual bool IaGetSize( int *ncolm );
|
||||||
|
virtual bool IaGetColm( int icol, char* name, BYTE *type, int *size, int*ndecimal );
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, int* v );
|
||||||
|
virtual bool IaFinW(){return true;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int add(CartoBaseEntity* src);
|
||||||
|
int add(CartoBasePoint* src);
|
||||||
|
int add(CartoBaseLine* src);
|
||||||
|
int add(CartoBasePaintedProps* src);
|
||||||
|
int add(CartoBaseColor* src);
|
||||||
|
|
||||||
|
bool fexportShp(char* path, int type = CartoBaseTypes::Ndef);
|
||||||
|
|
||||||
|
void indexRef(bool buscaRepes=false);//indexa referencias
|
||||||
|
void iniIndexRef();//crea indexado
|
||||||
|
void reIndexRef();
|
||||||
|
};
|
||||||
|
|
||||||
|
class FiterCartoBase: public SetEntities
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CartoBase* cb;
|
||||||
|
Cgarray<int> ind;
|
||||||
|
|
||||||
|
virtual CartoBaseInfoEntity getEntity( int i );
|
||||||
|
|
||||||
|
virtual int getNumberEntities();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,165 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "CartoBaseDBFManager.h"
|
||||||
|
|
||||||
|
#include "ManagerDbfGdataTable.h"
|
||||||
|
//#include "CartoBaseElements.h"
|
||||||
|
//***************************************************************************
|
||||||
|
CartoBaseDBFManager::CartoBaseDBFManager(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
CartoBaseDBFManager::~CartoBaseDBFManager(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfSet( int nrow, int ncolm )
|
||||||
|
{
|
||||||
|
_icol = 0;
|
||||||
|
_nncol = ncolm;
|
||||||
|
_oldRef = cb->getNexRef()-nrow;
|
||||||
|
return cb->iaEx->IaSet(nrow, ncolm);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfSetColm( char* name, BYTE type, int size )
|
||||||
|
{
|
||||||
|
bool res =cb->iaEx->IaSetColm(_icol++,name, type, size);
|
||||||
|
if(res && _nncol<=_icol)
|
||||||
|
cb->iaEx->IaAdd(_oldRef);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfaddVal( int icol, int v )
|
||||||
|
{
|
||||||
|
return cb->iaEx->IaAddVal(_oldRef, icol, v);
|
||||||
|
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfaddVal( int icol, double v )
|
||||||
|
{
|
||||||
|
return cb->iaEx->IaAddVal(_oldRef, icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfaddVal( int icol, __int64 v )
|
||||||
|
{
|
||||||
|
return cb->iaEx->IaAddVal(_oldRef, icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfaddVal( int icol, char* v )
|
||||||
|
{
|
||||||
|
return cb->iaEx->IaAddVal(_oldRef, icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfaddVal( int icol, void* v )
|
||||||
|
{
|
||||||
|
return cb->iaEx->IaAddVal(_oldRef, icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfFinRow()
|
||||||
|
{
|
||||||
|
bool res = cb->iaEx->IaFinRow(_oldRef);
|
||||||
|
|
||||||
|
_oldRef++;
|
||||||
|
if(cb->getNexRef()>_oldRef)
|
||||||
|
cb->iaEx->IaAdd(_oldRef);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfFinR()
|
||||||
|
{
|
||||||
|
return cb->iaEx->IaFinR();
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfGet( int *nrow, int *ncolm )
|
||||||
|
{
|
||||||
|
rowE =-1;
|
||||||
|
_nnrow =0;
|
||||||
|
*nrow=setEnt->getNumberEntities();
|
||||||
|
return ia->IaGetSize(ncolm);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfGetColm( int icol, char* name, BYTE *type, int *size, int*ndecimal )
|
||||||
|
{
|
||||||
|
return ia->IaGetColm(icol,name,type,size,ndecimal);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfGetVal( int irow, int icol, int* v )
|
||||||
|
{
|
||||||
|
if(rowE!= irow)
|
||||||
|
{
|
||||||
|
e = setEnt->getEntity(irow);
|
||||||
|
rowE = irow;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ia->IaGetVal(e.entity()->ref,icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfGetVal( int irow, int icol, double* v )
|
||||||
|
{
|
||||||
|
if(rowE!= irow)
|
||||||
|
{
|
||||||
|
e = setEnt->getEntity(irow);
|
||||||
|
rowE = irow;
|
||||||
|
}
|
||||||
|
return ia->IaGetVal(e.entity()->ref ,icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfGetVal( int irow, int icol, __int64* v )
|
||||||
|
{
|
||||||
|
if(rowE!= irow)
|
||||||
|
{
|
||||||
|
e = setEnt->getEntity(irow);
|
||||||
|
rowE = irow;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ia->IaGetVal(e.entity()->ref, icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfGetVal( int irow, int icol, char** v )
|
||||||
|
{
|
||||||
|
if(rowE!= irow)
|
||||||
|
{
|
||||||
|
e = setEnt->getEntity(irow);
|
||||||
|
rowE = irow;
|
||||||
|
}
|
||||||
|
return ia->IaGetVal(e.entity()->ref,icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfGetVal( int irow, int icol, void** v )
|
||||||
|
{
|
||||||
|
if(rowE!= irow)
|
||||||
|
{
|
||||||
|
e = setEnt->getEntity(irow);
|
||||||
|
rowE = irow;
|
||||||
|
}
|
||||||
|
return ia->IaGetVal(e.entity()->ref,icol, v);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::DbfFinW()
|
||||||
|
{
|
||||||
|
return ia->IaFinW();
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::leer( char *path, CartoBase*cartb )
|
||||||
|
{
|
||||||
|
cb = cartb;
|
||||||
|
switch(cb->getTypeIA())
|
||||||
|
{
|
||||||
|
case(CartoBase::DtIa):
|
||||||
|
case (CartoBase::ExIa):
|
||||||
|
return ManagerDbf::leer(path,this);
|
||||||
|
case(CartoBase::NIa):
|
||||||
|
case(CartoBase::IntIa):
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool CartoBaseDBFManager::grabar( char *path, DataIaCartoBase* iawx, SetEntities* s )
|
||||||
|
{
|
||||||
|
setEnt =s;
|
||||||
|
rowE =-1;
|
||||||
|
ia = iawx;
|
||||||
|
|
||||||
|
return ManagerDbf::grabar(path,this);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "Fdbf.h"
|
||||||
|
#include "CartoBase.h"
|
||||||
|
|
||||||
|
//clase helper para imporacion de un dbf a informacion asociada de cartobase
|
||||||
|
class UTILES_EXPORT CartoBaseDBFManager: public ListenerDbf_W, public ListenerDbf_R
|
||||||
|
{
|
||||||
|
CartoBase *cb;
|
||||||
|
int _oldRef;
|
||||||
|
int _icol;
|
||||||
|
int _nncol;
|
||||||
|
int _nnrow;
|
||||||
|
CartoBaseInfoEntity e;
|
||||||
|
int rowE;
|
||||||
|
SetEntities *setEnt;
|
||||||
|
DataIaCartoBase* ia;
|
||||||
|
public:
|
||||||
|
|
||||||
|
CartoBaseDBFManager(void);
|
||||||
|
~CartoBaseDBFManager(void);
|
||||||
|
virtual bool leer(char *path, CartoBase*cartb);
|
||||||
|
virtual bool grabar(char *path, DataIaCartoBase* iawx, SetEntities* s);
|
||||||
|
|
||||||
|
|
||||||
|
//funciones auxiliares-----------------------------------
|
||||||
|
//funciones de lectura de shp--------------------------
|
||||||
|
virtual bool DbfSet( int nrow, int ncolm );
|
||||||
|
virtual bool DbfSetColm( char* name, BYTE type, int size );
|
||||||
|
virtual bool DbfaddVal( int icol, int v );
|
||||||
|
virtual bool DbfaddVal( int icol, double v );
|
||||||
|
virtual bool DbfaddVal( int icol, __int64 v );
|
||||||
|
virtual bool DbfaddVal( int icol, char* v );
|
||||||
|
virtual bool DbfaddVal( int icol, void* v );
|
||||||
|
virtual bool DbfFinRow();
|
||||||
|
virtual bool DbfFinR();
|
||||||
|
|
||||||
|
//funciones de escritura de dbf-----------------------
|
||||||
|
virtual bool DbfGet( int *nrow, int *ncolm);
|
||||||
|
virtual bool DbfGetColm( int icol, char* name, BYTE *type, int *size, int*ndecimal );
|
||||||
|
virtual bool DbfGetVal( int irow, int icol, int* v );
|
||||||
|
virtual bool DbfGetVal( int irow, int icol, double* v );
|
||||||
|
virtual bool DbfGetVal( int irow, int icol, __int64* v );
|
||||||
|
virtual bool DbfGetVal( int irow, int icol, char** v );
|
||||||
|
virtual bool DbfGetVal( int irow, int icol, void** v );
|
||||||
|
virtual bool DbfFinW();
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef CartoBaseDef_H
|
||||||
|
#define CartoBaseDef_H
|
||||||
|
#include "base_head.h"
|
||||||
|
|
||||||
|
namespace CartoBaseTypes{
|
||||||
|
enum {
|
||||||
|
Ndef = 0,
|
||||||
|
Point,
|
||||||
|
Line
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
//calse coleccion de puntos (double[3]) solo lectura
|
||||||
|
class UTILES_EXPORT SetPtsR
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual double* getPto(int i)=0;//devuelve el punto iesimo
|
||||||
|
virtual int getNumberPtos()=0;//devuelve numero de puntos totales
|
||||||
|
};
|
||||||
|
//coleccion de puntos al que se le puede añadir mas
|
||||||
|
class UTILES_EXPORT SetPtsW
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool addPto(double* p)=0;//añade el punto p al conjunto
|
||||||
|
};
|
||||||
|
//constructor de setPtsW
|
||||||
|
class UTILES_EXPORT SetPtsWBuilder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual SetPtsW *build()=0;//devuelve una nueva clase SetPtsW
|
||||||
|
};
|
||||||
|
class CartoBase;
|
||||||
|
//interface de ia
|
||||||
|
class UTILES_EXPORT DataIaCartoBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void* IaGet(int refEnt){return NULL;}
|
||||||
|
|
||||||
|
virtual void CBSet(CartoBase* cb){}
|
||||||
|
virtual void IaRemove(int refEnt){}
|
||||||
|
virtual void IaRemoveAll(){}
|
||||||
|
virtual void IaAdd(int refEnt){}
|
||||||
|
|
||||||
|
//informa del numero de filas y columnas que tiene la ia
|
||||||
|
virtual bool IaSet(int nrow, int ncolm){return true;}
|
||||||
|
virtual bool IaSetColm(int icol, char* name, BYTE type, int size){return true;}
|
||||||
|
virtual bool IaAddVal(int refEnt, int icol, int v){return true;}
|
||||||
|
virtual bool IaAddVal(int refEnt, int icol, double v){return true;}
|
||||||
|
virtual bool IaAddVal(int refEnt, int icol, __int64 v){return true;}
|
||||||
|
virtual bool IaAddVal(int refEnt, int icol, char* v){return true;}
|
||||||
|
virtual bool IaAddVal(int refEnt, int icol, void* v){return true;}
|
||||||
|
virtual bool IaFinRow(int refEnt){return true;}
|
||||||
|
virtual bool IaFinR(){return true;}
|
||||||
|
|
||||||
|
|
||||||
|
virtual bool IaGetSize( int *ncolm ){return false;}
|
||||||
|
virtual bool IaGetColm( int icol, char* name, BYTE *type, int *size, int*ndecimal ){return false;}
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, int* v ){return false;}
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, double* v ){return false;}
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, __int64* v ){return false;}
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, char** v ){return false;}
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, void** v ){return false;}
|
||||||
|
virtual bool IaFinW(){return true;}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define TYPE_FILE "CartoBase"
|
||||||
|
#define VERSION_CART_BASE 100
|
||||||
|
//falgs de entidades--------------
|
||||||
|
#define CARTOBASE_DELETED_ENTITY 0x01
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -0,0 +1,298 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "CartoBaseElements.h"
|
||||||
|
#include "CartoBase.h"
|
||||||
|
#include "CartoBaseShpManager.h"
|
||||||
|
#include "GeometryFunction.h"
|
||||||
|
#include "dir_manager.h"
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseInfoEntity::CartoBaseInfoEntity()
|
||||||
|
{
|
||||||
|
i_entity = -1;
|
||||||
|
ptr = 0;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBaseInfoEntity::isValid()
|
||||||
|
{
|
||||||
|
return ptr && i_entity >= 0 && ptr->_entities.n > i_entity;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseInfoEntity CartoBaseInfoEntity::next()
|
||||||
|
{
|
||||||
|
if(!isValid())
|
||||||
|
return CartoBaseInfoEntity();
|
||||||
|
return ptr->get(i_entity+1);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBasePoint* CartoBaseInfoEntity::pto()
|
||||||
|
{
|
||||||
|
if(!fpto)
|
||||||
|
return 0;
|
||||||
|
return fpto(this);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseLine* CartoBaseInfoEntity::line()
|
||||||
|
{
|
||||||
|
if(!fline)
|
||||||
|
return 0;
|
||||||
|
return fline(this);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseInfoEntity CartoBaseInfoEntity::prev()
|
||||||
|
{
|
||||||
|
if(!isValid())
|
||||||
|
return CartoBaseInfoEntity();
|
||||||
|
return ptr->get(i_entity-1);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseEntity* CartoBaseInfoEntity::entity()
|
||||||
|
{
|
||||||
|
if(!isValid())
|
||||||
|
return NULL;
|
||||||
|
return ptr->_entities.get(i_entity);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBasePaintedProps* CartoBaseInfoEntity::paintp()
|
||||||
|
{
|
||||||
|
CartoBaseEntity* e = CartoBaseInfoEntity::entity();
|
||||||
|
if(e)
|
||||||
|
return ptr->_paintedProps.get(e->idPaintp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoBaseInfoEntity::getNumberPtos()
|
||||||
|
{
|
||||||
|
CartoBaseLine* l = line();
|
||||||
|
if(!l)//es un punto
|
||||||
|
return 1;
|
||||||
|
return l->n;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double* CartoBaseInfoEntity::getPto(int i)
|
||||||
|
{
|
||||||
|
CartoBasePoint* aux =pto();
|
||||||
|
if(aux)
|
||||||
|
return aux[i].pts;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseColor* CartoBaseInfoEntity::color()
|
||||||
|
{
|
||||||
|
CartoBasePaintedProps* pp = paintp();
|
||||||
|
if(pp)
|
||||||
|
return ptr->_colors.get(pp->color);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBasePoint* CartoBaseInfoPto::pto(CartoBaseInfoEntity* c)
|
||||||
|
{
|
||||||
|
CartoBaseEntity* e = c->entity();
|
||||||
|
if(e)
|
||||||
|
return c->ptr->_points.get(e->id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBasePoint* CartoBaseInfoLine::pto(CartoBaseInfoEntity* c)
|
||||||
|
{
|
||||||
|
CartoBaseLine* l = c->line();
|
||||||
|
if(l)
|
||||||
|
return c->ptr->_points.get(l->ini);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseInfoEntity EntitiesArray::getEntity(int i)
|
||||||
|
{
|
||||||
|
CartoBaseInfoEntity* e = get(i);
|
||||||
|
if(e)
|
||||||
|
return *e;
|
||||||
|
return CartoBaseInfoEntity();
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
EntitiesArray* EntitiesArray::filter(EntitiesArray* dst, FilterEntities* filter)
|
||||||
|
{
|
||||||
|
|
||||||
|
for(int i =0 ; i<n; i++)
|
||||||
|
{
|
||||||
|
CartoBaseInfoEntity* e = get(i);
|
||||||
|
if(filter->IsSeletedEntity(e))
|
||||||
|
{
|
||||||
|
if(!((*dst)+(*e)))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool EntitiesArray::exportShp(char* path, int type)
|
||||||
|
{
|
||||||
|
CartoBaseShpManager shp;
|
||||||
|
char nshp[256];
|
||||||
|
Cb_file f;
|
||||||
|
Cb_file fshp;
|
||||||
|
if(!f.abre(path,2,1))
|
||||||
|
return false;
|
||||||
|
if(!fshp.abre(Cdir_manager::cambia_extension_archivo(path,nshp,"shx"),2,1))
|
||||||
|
return false;
|
||||||
|
return shp.ExportShp(&f,&fshp, this, type);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int EntitiesArray::getNumberEntities()
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int EntitiesArray::getNumberPtos()
|
||||||
|
{
|
||||||
|
int count =0;
|
||||||
|
for(int i =0; i<n; i++)
|
||||||
|
{
|
||||||
|
count+=get(i)->getNumberPtos();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double* EntitiesArray::getPto(int i)
|
||||||
|
{
|
||||||
|
int count =0;
|
||||||
|
|
||||||
|
for(int i =0; i<n; i++)
|
||||||
|
{
|
||||||
|
count=get(i)->getNumberPtos();
|
||||||
|
if(i>=count)
|
||||||
|
i -=count;
|
||||||
|
else
|
||||||
|
return get(i)->getPto(i);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoEntity* CartoBaseInfoEntity::getCopy(CartoEntity *buf)
|
||||||
|
{
|
||||||
|
CartoBaseEntity* e = entity();
|
||||||
|
CartoEntity * buff = NULL;
|
||||||
|
if(!e)
|
||||||
|
return NULL;
|
||||||
|
if(!buf)
|
||||||
|
buf = buff = CartoBaseInfoBuilder::get(e->type);
|
||||||
|
if( buf->getType()!= e->type)
|
||||||
|
return NULL;
|
||||||
|
if(!buf->set(this))
|
||||||
|
{
|
||||||
|
if(buff)
|
||||||
|
delete buff;
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double CartoBaseInfoEntity::getLong()
|
||||||
|
{
|
||||||
|
return GeometryFunction::LongLine2d(this);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
//la distancia media a una línea de longitud mayor que this,
|
||||||
|
//partiendo de this y calculando la distancia de puntos equidistantes l_avan a los puntos
|
||||||
|
//más cercanos de line2
|
||||||
|
double CartoBaseInfoEntity::disMedLines(SetPtsR *line2, double l_avan, double *desv)
|
||||||
|
{
|
||||||
|
return GeometryFunction::DisMedLines(this,line2,l_avan,desv);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
//la distancia media a una línea de longitud mayor que this,
|
||||||
|
//calculando la distancia de los puntos de this a line2
|
||||||
|
double CartoBaseInfoEntity::disMedLines(SetPtsR *line2, double *desv)
|
||||||
|
{
|
||||||
|
return GeometryFunction::DisMedLines(this,line2);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double *CartoBaseInfoEntity::GetPtoDis(double dis, double *dst, double *distTot)
|
||||||
|
{
|
||||||
|
return GeometryFunction::GetPto(this, dis, dst, distTot);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double CartoBaseInfoEntity::DisPtoLine(double*p, int* idpto, double *lamb)
|
||||||
|
{
|
||||||
|
return GeometryFunction::DisPtoLine(this,p,idpto,lamb);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double CartoBaseInfoEntity::DplineSeg(double* s1, double *s2,int *n, double *lamd1,double *lamb2)
|
||||||
|
{
|
||||||
|
return GeometryFunction::DplineSeg(this,s1, s2,n, lamd1,lamb2);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
SetPtsW *CartoBaseInfoEntity::GetNPrimePtos(SetPtsW *ldst, int nptos, double dis, BOOL avanza)
|
||||||
|
{
|
||||||
|
return GeometryFunction::GetNPrimePtos(this,ldst,nptos,dis,avanza);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double *CartoBaseInfoEntity::PtInLine(int ip, double lamb, double *pp )
|
||||||
|
{
|
||||||
|
return GeometryFunction::PtInLine( this, ip, lamb , pp );
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoBaseInfoEntity::DivLine( SetPtsW* ldst1, SetPtsW* ldst2, int ip, double lamb )
|
||||||
|
{
|
||||||
|
double dis=GeometryFunction::DisInLine(this,ip,lamb);
|
||||||
|
if(dis<0)
|
||||||
|
return false;
|
||||||
|
return GeometryFunction::DivLine(this,ldst1,ldst2,dis);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void* CartoBaseInfoEntity::getIa()
|
||||||
|
{
|
||||||
|
CartoBaseEntity* e = entity();
|
||||||
|
if(e)
|
||||||
|
return ptr->getIa(e->ref);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseLine* CartoBaseInfoLine::line(CartoBaseInfoEntity* c)
|
||||||
|
{
|
||||||
|
CartoBaseEntity* e = c->entity();
|
||||||
|
if(e)
|
||||||
|
return c->ptr->_lines.get(e->id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseInfoEntity CartoBaseInfoBuilder::get(int i, CartoBase* ptr)
|
||||||
|
{
|
||||||
|
CartoBaseInfoEntity res;
|
||||||
|
if(!ptr)
|
||||||
|
goto mal;
|
||||||
|
if(i<0 || ptr->_entities.n<= i)
|
||||||
|
goto mal;
|
||||||
|
res.ptr = ptr;
|
||||||
|
res.i_entity = i;
|
||||||
|
switch(ptr->_entities[i].type)
|
||||||
|
{
|
||||||
|
case (CartoBaseTypes::Point):
|
||||||
|
{
|
||||||
|
res.fline= 0;
|
||||||
|
res.fpto= CartoBaseInfoPto::pto;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (CartoBaseTypes::Line):
|
||||||
|
{
|
||||||
|
res.fline= CartoBaseInfoLine::line;
|
||||||
|
res.fpto= CartoBaseInfoLine::pto;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mal:
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoEntity* CartoBaseInfoBuilder::get(int type)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case (CartoBaseTypes::Point):
|
||||||
|
return new CartoPto();
|
||||||
|
case (CartoBaseTypes::Line):
|
||||||
|
return new CartoLine();
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
|
@ -0,0 +1,172 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "cartoBaseDef.h"
|
||||||
|
#include "garray.h"
|
||||||
|
#ifndef CartoBaseElements_H
|
||||||
|
#define CartoBaseElements_H
|
||||||
|
class CartoEntity;
|
||||||
|
//clases internas de cartobase----------------------------------------------
|
||||||
|
class UTILES_EXPORT CartoBaseEntity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int id; //indice a objeto
|
||||||
|
int type; //tipo de entidad
|
||||||
|
int idPaintp; //inide a propiedades
|
||||||
|
int flagsUser; //flags para uso de usuario
|
||||||
|
int flagsInt; //flags para uso interno
|
||||||
|
int ref; //referencia unica por elemento
|
||||||
|
|
||||||
|
//tamaño---------
|
||||||
|
int mima[2]; //indice a punto maximo y minimo (el elemento esta contenido entre dichos puntos)
|
||||||
|
int ia; //indice a informacion adicional
|
||||||
|
|
||||||
|
CartoBaseEntity()
|
||||||
|
{
|
||||||
|
id = -1;
|
||||||
|
idPaintp = -1;
|
||||||
|
flagsInt = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//entidad interna de putno
|
||||||
|
class UTILES_EXPORT CartoBasePoint
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
double pts[3];//coordenadas del punto
|
||||||
|
|
||||||
|
CartoBasePoint(){
|
||||||
|
pts[0]=pts[1]=pts[2]=0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//entidad interna de linea
|
||||||
|
class UTILES_EXPORT CartoBaseLine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int ini; //inidce a punto inicio
|
||||||
|
int n; //numero de puntos del lineal
|
||||||
|
CartoBaseLine()
|
||||||
|
{
|
||||||
|
n = 0;
|
||||||
|
ini = -1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//entidad interna de propiedades de pintado
|
||||||
|
class UTILES_EXPORT CartoBasePaintedProps
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int color; //indice a color
|
||||||
|
int peso; //grosor o tamaño de letra (segun entidad)
|
||||||
|
int prioridad; //prioridad de pintado
|
||||||
|
int flags; //flags internos 0x1 (visto para los clear)
|
||||||
|
CartoBasePaintedProps()
|
||||||
|
{
|
||||||
|
color = -1;
|
||||||
|
peso = 1;
|
||||||
|
flags = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//entidad interna de color
|
||||||
|
class UTILES_EXPORT CartoBaseColor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
int color;
|
||||||
|
int flags; //flags internos 0x1 (visto para los clear)
|
||||||
|
CartoBaseColor()
|
||||||
|
{
|
||||||
|
color = 0;
|
||||||
|
flags = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//entidad base de informacion
|
||||||
|
class CartoBase;
|
||||||
|
class UTILES_EXPORT CartoBaseInfoEntity: public SetPtsR
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//funciones externas
|
||||||
|
CartoBasePoint* (*fpto)(CartoBaseInfoEntity *c);
|
||||||
|
CartoBaseLine* (*fline)(CartoBaseInfoEntity *c);
|
||||||
|
int i_entity;
|
||||||
|
|
||||||
|
CartoBase* ptr;
|
||||||
|
|
||||||
|
CartoBaseInfoEntity();
|
||||||
|
|
||||||
|
virtual bool isValid(); //dice si es valido o no la entidad de informacion
|
||||||
|
virtual CartoBaseInfoEntity next(); //devuelve entidad siguiente
|
||||||
|
virtual CartoBaseInfoEntity prev(); //devuelve entidad anterior
|
||||||
|
|
||||||
|
//acceso a informacion interna
|
||||||
|
virtual CartoBasePoint* pto();
|
||||||
|
virtual CartoBaseEntity* entity();
|
||||||
|
virtual CartoBaseLine* line();
|
||||||
|
virtual CartoBasePaintedProps* paintp();
|
||||||
|
virtual CartoBaseColor* color();
|
||||||
|
virtual CartoEntity* getCopy(CartoEntity *buf=NULL);
|
||||||
|
//funciones SetPts--------------------------
|
||||||
|
virtual double* getPto(int i);
|
||||||
|
virtual int getNumberPtos();
|
||||||
|
|
||||||
|
void* getIa();
|
||||||
|
double getLong();
|
||||||
|
double disMedLines(SetPtsR *line2, double l_avan, double *desv=NULL);
|
||||||
|
double disMedLines(SetPtsR *line2, double *desv=NULL);
|
||||||
|
double DisPtoLine(double*p, int* idpto=NULL, double *lamb=NULL);
|
||||||
|
SetPtsW *GetNPrimePtos(SetPtsW *ldst, int nptos, double dis, BOOL avanza);
|
||||||
|
bool DivLine(SetPtsW* ldst1, SetPtsW* ldst2, int ip, double lamb);
|
||||||
|
double *GetPtoDis(double dis, double *dst, double *distTot);
|
||||||
|
double *PtInLine(int ip, double lamb, double *pp);
|
||||||
|
double DplineSeg(double* s1, double *s2,int *n=NULL, double *lamd1=NULL,double *lamb2=NULL);
|
||||||
|
};
|
||||||
|
//calse coleccion de entidades
|
||||||
|
class UTILES_EXPORT SetEntities
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual CartoBaseInfoEntity getEntity(int i)=0;
|
||||||
|
virtual int getNumberEntities()=0;
|
||||||
|
};
|
||||||
|
|
||||||
|
//clase de filtrado de entidades
|
||||||
|
class UTILES_EXPORT FilterEntities
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool IsSeletedEntity(CartoBaseInfoEntity *e)=0;
|
||||||
|
};
|
||||||
|
|
||||||
|
//array de entidades
|
||||||
|
class UTILES_EXPORT EntitiesArray: public Cgarray<CartoBaseInfoEntity>, public SetEntities, public SetPtsR
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual CartoBaseInfoEntity getEntity(int i);
|
||||||
|
virtual int getNumberEntities();
|
||||||
|
|
||||||
|
virtual double* getPto(int i);
|
||||||
|
virtual int getNumberPtos();
|
||||||
|
|
||||||
|
EntitiesArray* filter(EntitiesArray* dst, FilterEntities* filter);
|
||||||
|
bool exportShp(char* path, int type = CartoBaseTypes::Ndef);
|
||||||
|
};
|
||||||
|
//entidad de informacion punto
|
||||||
|
class UTILES_EXPORT CartoBaseInfoPto
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static CartoBasePoint* pto(CartoBaseInfoEntity*c);
|
||||||
|
};
|
||||||
|
//entidad de informacion linea
|
||||||
|
class UTILES_EXPORT CartoBaseInfoLine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
static CartoBasePoint* pto(CartoBaseInfoEntity*c);
|
||||||
|
static CartoBaseLine* line(CartoBaseInfoEntity*c);
|
||||||
|
};
|
||||||
|
|
||||||
|
//clase constructor de entidades info
|
||||||
|
class UTILES_EXPORT CartoBaseInfoBuilder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static CartoBaseInfoEntity get(int i, CartoBase* ptr);
|
||||||
|
static CartoEntity* get(int type);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,202 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "CartoBaseShpManager.h"
|
||||||
|
#include "Fshape.h"
|
||||||
|
//**************************************************************************
|
||||||
|
CartoBaseShpManager::CartoBaseShpManager(void)
|
||||||
|
{
|
||||||
|
cad = NULL;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
CartoBaseShpManager::~CartoBaseShpManager(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
bool CartoBaseShpManager::ExportShp(Cb_file *file, Cb_file*fshx, SetEntities *entities, int type)
|
||||||
|
{
|
||||||
|
Fshape shp;
|
||||||
|
if(type == CartoBaseTypes::Ndef)
|
||||||
|
{
|
||||||
|
if(entities->getNumberEntities()>0)
|
||||||
|
type = entities->getEntity(0).entity()->type;
|
||||||
|
else
|
||||||
|
type=CartoBaseTypes::Line;
|
||||||
|
}
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case(CartoBaseTypes::Point):
|
||||||
|
{
|
||||||
|
return ExportPts(file,fshx, entities);
|
||||||
|
}
|
||||||
|
case(CartoBaseTypes::Line):
|
||||||
|
{
|
||||||
|
return ExportLine(file,fshx, entities);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool CartoBaseShpManager::ImportShp(Cb_file *file)
|
||||||
|
{
|
||||||
|
Fshape shp;
|
||||||
|
if(!shp.leeHead(file))
|
||||||
|
return false;
|
||||||
|
switch(shp.getType())
|
||||||
|
{
|
||||||
|
case(Fshape::Rpoint):
|
||||||
|
case(Fshape::RMpoint):
|
||||||
|
return ImportPoints(&shp);
|
||||||
|
break;
|
||||||
|
case(Fshape::RPolyLine):
|
||||||
|
return Importline(&shp);
|
||||||
|
break;
|
||||||
|
case(Fshape::Rpolygon):
|
||||||
|
return ImportPoligon(&shp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool CartoBaseShpManager::Importline(Fshape *shp)
|
||||||
|
{
|
||||||
|
CartoLine lin;
|
||||||
|
lin.idPropsP = cad->addDefaultPaintedProps();
|
||||||
|
double *pt;
|
||||||
|
//piner indice de color
|
||||||
|
while(shp->LeeRecord())
|
||||||
|
{
|
||||||
|
int nn = shp->getNp();
|
||||||
|
for(int p=0; p<nn; p++)
|
||||||
|
{
|
||||||
|
lin.pts.n = 0;
|
||||||
|
int np = shp->getNPt(p);
|
||||||
|
if(np<=0)
|
||||||
|
continue;
|
||||||
|
if(!(lin.pts+=np))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lin.pts.n = np;
|
||||||
|
for(int i = 0; i<np; i++)
|
||||||
|
{
|
||||||
|
pt= shp->get(p,i);
|
||||||
|
lin.pts[i][0]=pt[0];
|
||||||
|
lin.pts[i][1]=pt[1];
|
||||||
|
lin.pts[i][2]=0;
|
||||||
|
}
|
||||||
|
if(!cad->add(lin))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool CartoBaseShpManager::ImportPoints(Fshape *shp)
|
||||||
|
{
|
||||||
|
CartoPto pto;
|
||||||
|
pto.pt[2]=0;
|
||||||
|
pto.idPropsP = cad->addDefaultPaintedProps();
|
||||||
|
|
||||||
|
//piner indice de color
|
||||||
|
while(shp->LeeRecord())
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
double *p = shp->get(i++);
|
||||||
|
while(p)
|
||||||
|
{
|
||||||
|
pto.pt[0] = p[0];
|
||||||
|
pto.pt[1] = p[1];
|
||||||
|
if(!cad->add(pto))
|
||||||
|
return false;
|
||||||
|
p = shp->get(i++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool CartoBaseShpManager::ExportPts(Cb_file *file,Cb_file *fshx, SetEntities *entities)
|
||||||
|
{
|
||||||
|
Fshape shp;
|
||||||
|
Cgarray<double> pts;
|
||||||
|
int nn = 100;
|
||||||
|
if(nn>entities->getNumberEntities())
|
||||||
|
nn = entities->getNumberEntities();
|
||||||
|
if(!(pts+=(nn*2)))
|
||||||
|
return false;//sin memoria
|
||||||
|
|
||||||
|
if(!shp.set(Fshape::Rpoint,2,file, fshx))
|
||||||
|
return false;
|
||||||
|
int j =0;
|
||||||
|
pts.n = nn*2;
|
||||||
|
for(int i = 0; i<entities->getNumberEntities(); i++)
|
||||||
|
{
|
||||||
|
if(j == pts.n)
|
||||||
|
{
|
||||||
|
if(!shp.grabaRecord(&pts))
|
||||||
|
return false;
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
CartoBaseInfoEntity ee =entities->getEntity(i);
|
||||||
|
if(ee.entity()->type != CartoBaseTypes::Point)
|
||||||
|
continue;
|
||||||
|
memcpy(&pts[j],ee.pto()->pts,sizeof(double)*2);
|
||||||
|
j+=2;
|
||||||
|
}
|
||||||
|
pts.n = j;
|
||||||
|
if(j>0 && !shp.grabaRecord(&pts))
|
||||||
|
return false;
|
||||||
|
return shp.FinGraba();
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool CartoBaseShpManager::ExportLine(Cb_file *file,Cb_file *fshx, SetEntities *entities)
|
||||||
|
{
|
||||||
|
Fshape shp;
|
||||||
|
Cgarray<double> pts;
|
||||||
|
Cgarray<int> parts;
|
||||||
|
CartoBaseLine *l;
|
||||||
|
int nn = 1;
|
||||||
|
if(nn>entities->getNumberEntities())
|
||||||
|
nn = entities->getNumberEntities();
|
||||||
|
if(!(parts+=nn))
|
||||||
|
return false;
|
||||||
|
if(!shp.set(Fshape::RPolyLine, 2,file,fshx))
|
||||||
|
return false;
|
||||||
|
int j =0;
|
||||||
|
parts.n = nn;
|
||||||
|
for(int i = 0; i<entities->getNumberEntities(); i++)
|
||||||
|
{
|
||||||
|
if(j >= parts.n)
|
||||||
|
{
|
||||||
|
if(!shp.grabaRecord(&pts, &parts))
|
||||||
|
return false;
|
||||||
|
j = 0;
|
||||||
|
pts.n =0;
|
||||||
|
}
|
||||||
|
CartoBaseInfoEntity ee =entities->getEntity(i);
|
||||||
|
if(ee.entity()->type != CartoBaseTypes::Line)
|
||||||
|
continue;
|
||||||
|
l =ee.line();
|
||||||
|
if(!l)
|
||||||
|
continue;
|
||||||
|
parts[j++] = pts.n;
|
||||||
|
|
||||||
|
if(!(pts+=(l->n*2)))
|
||||||
|
return false;
|
||||||
|
CartoBasePoint *pp = entities->getEntity(i).pto();
|
||||||
|
for(int p = 0; p<l->n; p++)
|
||||||
|
{
|
||||||
|
pts.n=pts.n+2;
|
||||||
|
memcpy(&pts[pts.n-2],pp[p].pts,sizeof(double)*2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parts.n = j;
|
||||||
|
if(j>0 && !shp.grabaRecord(&pts, &parts))
|
||||||
|
return false;
|
||||||
|
return shp.FinGraba();
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool CartoBaseShpManager::ImportPoligon(Fshape *shp)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "garray.h"
|
||||||
|
#include "CartoBase.h"
|
||||||
|
|
||||||
|
class Cb_file;
|
||||||
|
class Fshape;
|
||||||
|
//clase helper para inportacion de shp a un carto base
|
||||||
|
class UTILES_EXPORT CartoBaseShpManager
|
||||||
|
{
|
||||||
|
CartoBase* cad;
|
||||||
|
bool ImportPoints(Fshape *shp);
|
||||||
|
bool Importline(Fshape *shp);
|
||||||
|
bool ImportPoligon(Fshape *shp);
|
||||||
|
bool ExportLine(Cb_file *file, Cb_file *fshx, SetEntities *entities);
|
||||||
|
bool ExportPts(Cb_file *file, Cb_file *fshx, SetEntities *entities);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CartoBaseShpManager(void);
|
||||||
|
~CartoBaseShpManager(void);
|
||||||
|
|
||||||
|
void set(CartoBase* cb){cad = cb;}
|
||||||
|
|
||||||
|
bool ImportShp(Cb_file *file);
|
||||||
|
|
||||||
|
bool ExportShp(Cb_file *file,Cb_file *fshx, SetEntities *entities, int type = CartoBaseTypes::Ndef);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,195 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "CartoBaseElements.h"
|
||||||
|
#include "CartoElements.h"
|
||||||
|
#include "CartoBase.h"
|
||||||
|
#include "GeometryFunction.h"
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseEntity* CartoComun::get(CartoBaseEntity * dst)
|
||||||
|
{
|
||||||
|
dst->flagsUser = flagsUser;
|
||||||
|
dst->ia=ia;
|
||||||
|
dst->type = getType();
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBasePaintedProps* CartoComun::get(CartoBasePaintedProps * dst)
|
||||||
|
{
|
||||||
|
dst->peso = peso;
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoBaseColor* CartoComun::get(CartoBaseColor * dst)
|
||||||
|
{
|
||||||
|
dst->color = color;
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoComun::setInfo(CartoBaseInfoEntity * info)
|
||||||
|
{
|
||||||
|
CartoBaseEntity *e =info->entity();
|
||||||
|
CartoBaseColor *c =info->color();
|
||||||
|
CartoBasePaintedProps *p =info->paintp();
|
||||||
|
if(!e || !c || !p)
|
||||||
|
return false;
|
||||||
|
flagsUser = e->flagsUser;
|
||||||
|
color= c->color;
|
||||||
|
peso= p->peso;
|
||||||
|
id= e->id;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoEntity* CartoPto::set(CartoBaseInfoEntity *src)
|
||||||
|
{
|
||||||
|
if(!setInfo(src))
|
||||||
|
return NULL;
|
||||||
|
CartoBasePoint *p = src->pto();
|
||||||
|
if(!p)
|
||||||
|
return NULL;
|
||||||
|
memcpy(pt,p->pts,sizeof(double)*3);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double* CartoPto::getPto(int i)
|
||||||
|
{
|
||||||
|
if(i==0)
|
||||||
|
return pt;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoPto::CopyInTo(CartoBase *src)
|
||||||
|
{
|
||||||
|
CartoBaseEntity e;
|
||||||
|
CartoBasePaintedProps p;
|
||||||
|
CartoBaseColor c;
|
||||||
|
CartoBasePoint pt;
|
||||||
|
memcpy(pt.pts, &this->pt, sizeof(double)*3);
|
||||||
|
e.id = src->add(&pt);
|
||||||
|
|
||||||
|
if(idPropsP<0)
|
||||||
|
{
|
||||||
|
p.color = src->add(get(&c));
|
||||||
|
if(p.color<0)
|
||||||
|
return -1;
|
||||||
|
e.idPaintp = src->add(get(&p));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
e.idPaintp = idPropsP;
|
||||||
|
|
||||||
|
if(e.idPaintp<-1)
|
||||||
|
return -1;
|
||||||
|
if(e.id<-1)
|
||||||
|
return -1;
|
||||||
|
return src->add(get(&e));
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double* CartoLine::getPto(int i)
|
||||||
|
{
|
||||||
|
return pts[i];
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double CartoLine::getLong()
|
||||||
|
{
|
||||||
|
return GeometryFunction::LongLine2d(this);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double *CartoLine::GetPtoDis(double dis, double *dst, double *distTot)
|
||||||
|
{
|
||||||
|
return GeometryFunction::GetPto(this, dis, dst, distTot);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool CartoLine::addPto(double *p)
|
||||||
|
{
|
||||||
|
if(!(pts+=1))
|
||||||
|
return false;
|
||||||
|
pts.n++;
|
||||||
|
memcpy(pts[pts.n-1],p, sizeof(double)*3);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
CartoEntity* CartoLine::set(CartoBaseInfoEntity *src)
|
||||||
|
{
|
||||||
|
if(!setInfo(src))
|
||||||
|
return NULL;
|
||||||
|
CartoBaseLine *l = src->line();
|
||||||
|
if(!l)
|
||||||
|
return NULL;
|
||||||
|
pts.n = 0;
|
||||||
|
pts+=l->n;
|
||||||
|
pts.n = l->n;
|
||||||
|
CartoBasePoint *p = src->pto();
|
||||||
|
for(int i =0 ; i<l->n; i++)
|
||||||
|
{
|
||||||
|
memcpy(pts.ptr[i],p->pts,sizeof(double)*3);
|
||||||
|
p=&p[1];
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int CartoLine::CopyInTo(CartoBase *src)
|
||||||
|
{
|
||||||
|
if(pts.n<=0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
CartoBaseEntity e;
|
||||||
|
CartoBasePaintedProps p;
|
||||||
|
CartoBaseColor c;
|
||||||
|
CartoBasePoint pt;
|
||||||
|
CartoBaseLine l;
|
||||||
|
|
||||||
|
l.n= pts.n;
|
||||||
|
if(!(src->_lines+=pts.n))
|
||||||
|
return -1;
|
||||||
|
memcpy(pt.pts,pts[0], sizeof(double)*3);
|
||||||
|
l.ini = src->add(&pt);
|
||||||
|
|
||||||
|
for(int i = 1; i<pts.n; i++)
|
||||||
|
{
|
||||||
|
memcpy(pt.pts,pts[i], sizeof(double)*3);
|
||||||
|
src->add(&pt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(idPropsP<0)
|
||||||
|
{
|
||||||
|
p.color = src->add(get(&c));
|
||||||
|
if(p.color<0)
|
||||||
|
return -1;
|
||||||
|
e.idPaintp = src->add(get(&p));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
e.idPaintp = idPropsP;
|
||||||
|
|
||||||
|
if(e.idPaintp<-1)
|
||||||
|
return -1;
|
||||||
|
e.id = src->add(&l);
|
||||||
|
if(e.id<-1)
|
||||||
|
return -1;
|
||||||
|
return src->add(get(&e));
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void CartoLine::invert()
|
||||||
|
{
|
||||||
|
int ini =0;
|
||||||
|
int fin =pts.n-1;
|
||||||
|
double d;
|
||||||
|
while(ini<fin)
|
||||||
|
{
|
||||||
|
for(int i =0; i<3; i++)
|
||||||
|
{
|
||||||
|
d=pts[ini][i];
|
||||||
|
pts[ini][i]=pts[fin][i];
|
||||||
|
pts[fin][i] = d;
|
||||||
|
}
|
||||||
|
ini++;
|
||||||
|
fin--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
//*****************************************************************************************
|
||||||
|
//la distancia media a una línea de longitud mayor que this,
|
||||||
|
//calculando la distancia de los puntos de this a line2
|
||||||
|
double CartoEntity::disMedLines(SetPtsR *line2, double *desv)
|
||||||
|
{
|
||||||
|
return GeometryFunction::DisMedLines(this,line2,desv);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "CartoBaseDef.h"
|
||||||
|
|
||||||
|
class CartoBaseEntity;
|
||||||
|
class CartoBasePaintedProps;
|
||||||
|
class CartoBaseColor;
|
||||||
|
//clases de elmentos de cartobase
|
||||||
|
class UTILES_EXPORT CartoEntity : public SetPtsR
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual int getType()//devuelve tipo de entidad
|
||||||
|
{
|
||||||
|
return CartoBaseTypes::Ndef;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual int getnLines()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual CartoEntity* set(CartoBaseInfoEntity *src)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
virtual int CopyInTo(CartoBase *src)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
virtual double* getPto(int i){return 0;}
|
||||||
|
|
||||||
|
virtual int getNumberPtos(){return 0;}
|
||||||
|
virtual double disMedLines(SetPtsR *line2, double *desv=NULL);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class UTILES_EXPORT CartoComun: public CartoEntity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int flagsUser;
|
||||||
|
int color;
|
||||||
|
int peso;
|
||||||
|
int id;//ide de entidad
|
||||||
|
int ia;
|
||||||
|
int idPropsP;//ide de propiedades de pintado al que se va a poner
|
||||||
|
|
||||||
|
CartoComun()
|
||||||
|
{
|
||||||
|
flagsUser =0;
|
||||||
|
color = 0;
|
||||||
|
peso = 0;
|
||||||
|
id = -1;
|
||||||
|
ia=0;
|
||||||
|
idPropsP = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//auxiliary funcition
|
||||||
|
bool setInfo(CartoBaseInfoEntity * info);
|
||||||
|
|
||||||
|
CartoBaseEntity* get(CartoBaseEntity * dst);
|
||||||
|
CartoBasePaintedProps* get(CartoBasePaintedProps * dst);
|
||||||
|
CartoBaseColor* get(CartoBaseColor * dst);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class UTILES_EXPORT CartoPto: public CartoComun
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
double pt[3];
|
||||||
|
CartoPto(){};
|
||||||
|
virtual int getType()//devuelve tipo de entidad
|
||||||
|
{
|
||||||
|
return CartoBaseTypes::Point;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual CartoEntity* set(CartoBaseInfoEntity *src);
|
||||||
|
|
||||||
|
virtual int CopyInTo(CartoBase *src);
|
||||||
|
virtual double* getPto(int i);
|
||||||
|
|
||||||
|
virtual int getNumberPtos(){return 1;}
|
||||||
|
};
|
||||||
|
|
||||||
|
class UTILES_EXPORT CartoLine: public CartoComun, public SetPtsW
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Cgarray<double[3]> pts;
|
||||||
|
CartoLine(){};
|
||||||
|
|
||||||
|
virtual int getType()//devuelve tipo de entidad
|
||||||
|
{
|
||||||
|
return CartoBaseTypes::Line;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual CartoEntity* set(CartoBaseInfoEntity *src);
|
||||||
|
virtual int CopyInTo(CartoBase *src);
|
||||||
|
virtual int getNumberPtos(){return pts.n;}
|
||||||
|
virtual double* getPto(int i);
|
||||||
|
virtual bool addPto(double* p);
|
||||||
|
//funciones de geometria----------------------------------
|
||||||
|
void invert();//invierte el sentido de los pts
|
||||||
|
double getLong();
|
||||||
|
double *GetPtoDis(double dis, double *dst, double *distTot = NULL);
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,339 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "Csock_cl.h"
|
||||||
|
#include "utiles_dll.h"
|
||||||
|
#include "_error.h"
|
||||||
|
#include "utl.h"
|
||||||
|
//***********************************************************************************************
|
||||||
|
Csock_cl::Csock_cl(BOOL*sal/*=NULL*/, C_error*e/*=NULL*/ )
|
||||||
|
{
|
||||||
|
creado = false;
|
||||||
|
buf=NULL;
|
||||||
|
nb=mb=0;
|
||||||
|
time_sleep=1;
|
||||||
|
intentos=500;
|
||||||
|
//creamos log error--------------
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
|
borra_er=FALSE;
|
||||||
|
er=e;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
borra_er=TRUE;
|
||||||
|
er=new C_error();
|
||||||
|
}
|
||||||
|
//ponemos pirate---------------
|
||||||
|
if(sal)
|
||||||
|
{
|
||||||
|
pirate=sal;
|
||||||
|
borra_pirate=FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pirate=new BOOL();
|
||||||
|
borra_pirate=TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//***********************************************************************************************
|
||||||
|
Csock_cl::~Csock_cl(void)
|
||||||
|
{
|
||||||
|
if (pirate&&borra_pirate)
|
||||||
|
free(pirate);
|
||||||
|
if (buf)
|
||||||
|
free(buf);
|
||||||
|
if (borra_er && er)
|
||||||
|
delete er;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
BOOL Csock_cl::Create( UINT puerto, int tipo, long eventos ,LPCTSTR ip)
|
||||||
|
{
|
||||||
|
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||||||
|
Cutiles_dll dll;
|
||||||
|
BOOL resul=CAsyncSocket::Create(puerto, tipo,eventos,ip);
|
||||||
|
if (!resul)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSOCK_CL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
creado =true;
|
||||||
|
return resul;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
BOOL Csock_cl::conectar(char *ipdot,int puerto)
|
||||||
|
{
|
||||||
|
Cutiles_dll dll;
|
||||||
|
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||||||
|
fd_set rfds;
|
||||||
|
struct timeval tv;
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(this->m_hSocket, &rfds);
|
||||||
|
tv.tv_sec = 5;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
int err,vez;
|
||||||
|
CString cstr;
|
||||||
|
if(!creado && ! Create())
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (Connect(ipdot, puerto))
|
||||||
|
{
|
||||||
|
err = GetLastError();
|
||||||
|
if(err != WSAEWOULDBLOCK)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSOCK_CL);
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//vemos que realmente este conectado
|
||||||
|
vez = 0;
|
||||||
|
while (!*pirate)
|
||||||
|
{
|
||||||
|
int pruebaconexion = select((int)this->m_hSocket+1, NULL, &rfds, NULL, &tv);
|
||||||
|
if(pruebaconexion == 1)
|
||||||
|
break;
|
||||||
|
else if(pruebaconexion == SOCKET_ERROR && vez>20)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSOCK_CL);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
vez++;
|
||||||
|
Sleep(time_sleep);
|
||||||
|
if (vez > intentos)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"conectar:Demasiado tiempo esperando");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(*pirate)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"conectar: Solicitud de salida activado");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
BOOL Csock_cl::recibe_package(int indice)
|
||||||
|
{
|
||||||
|
nb=indice;//bytes recibidos;
|
||||||
|
int bp=0;//bytes del bloque;
|
||||||
|
|
||||||
|
//pillamos cabezera------------------------------------------------
|
||||||
|
if (!recibe((BYTE*)&cab,sizeof(Package_head_0)))
|
||||||
|
return FALSE;
|
||||||
|
//verificamos------------------------------------------------------
|
||||||
|
if(cab.version!=VERSION_PACKAGE_HEAD)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"recibe_package:Versión de paquete recibido no compatible");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
cuida_buf(cab.nb);
|
||||||
|
//miramos si es un paquete----------------------------------------
|
||||||
|
if(cab.n==1)
|
||||||
|
{
|
||||||
|
if (!recibe((BYTE*)&buf[nb],cab.nb))
|
||||||
|
return FALSE;//error al parte
|
||||||
|
nb+=cab.nb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//pillamos partes---------------------------------------------
|
||||||
|
for (int i=0; i<cab.n; i++)
|
||||||
|
{
|
||||||
|
//pillamos numero-----------------------
|
||||||
|
if (!recibe((BYTE*)&bp,sizeof(int)))
|
||||||
|
return FALSE;//error al pillar numero
|
||||||
|
//verificamos---------------------------
|
||||||
|
if (nb+bp>mb)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"recibe_package:Paquete defectuoso, tamaño muy grande");
|
||||||
|
return FALSE;//no entra en buffer
|
||||||
|
}
|
||||||
|
//pillamos parte------------------------
|
||||||
|
if (!recibe((BYTE*)&buf[nb],bp))
|
||||||
|
return FALSE;//error al parte
|
||||||
|
nb+=bp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//verificamos-----------------------------------------------------
|
||||||
|
if(cab.nb!=nb-indice)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"recibe_package:Paquete defectuoso, tamaño incorrecto");
|
||||||
|
return FALSE;//no coinciden bytes
|
||||||
|
}
|
||||||
|
//desencriptamos si hace falta------------------------------------
|
||||||
|
if (cab.flags & FLAG_PACKAGE_HEAD_0_ENCRIPT1)
|
||||||
|
{
|
||||||
|
Cutl::descifra1(&buf[indice],cab.nb);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
void Csock_cl::cuida_buf( int n )
|
||||||
|
{
|
||||||
|
if (nb+n>=mb)
|
||||||
|
{
|
||||||
|
//necesitamos memoria------------------------------------------
|
||||||
|
mb+=n;
|
||||||
|
if (buf)
|
||||||
|
buf=(BYTE*)malloc(mb);
|
||||||
|
else
|
||||||
|
buf=(BYTE*)realloc(buf,mb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
BOOL Csock_cl::envia_package( BYTE* buff, int n,int encrip )
|
||||||
|
{
|
||||||
|
int env=0;
|
||||||
|
int en=0;
|
||||||
|
//rellenamos cabecera----------------------
|
||||||
|
Package_head_0 cb;
|
||||||
|
cb.nb=n;
|
||||||
|
cb.flags=0;
|
||||||
|
if (encrip==1)
|
||||||
|
{
|
||||||
|
cb.flags=cb.flags | FLAG_PACKAGE_HEAD_0_ENCRIPT1;
|
||||||
|
Cutl::cifra1(buff,n);
|
||||||
|
}
|
||||||
|
|
||||||
|
cb.version=VERSION_PACKAGE_HEAD;
|
||||||
|
|
||||||
|
//calculamos bloques---------------------------------
|
||||||
|
cb.n=(n/MAX_LONG_PACKAGE_0)+1;
|
||||||
|
cb.nb=n;
|
||||||
|
//enviamos cabecera----------------------------------
|
||||||
|
if(!envia((BYTE *)&cb,sizeof(cb)))
|
||||||
|
{
|
||||||
|
return FALSE;//error al enviar cabecera
|
||||||
|
}
|
||||||
|
//enviamos en uno si se puede------------------------
|
||||||
|
if (cb.n==1)
|
||||||
|
{
|
||||||
|
if (!envia(buff,cb.nb))
|
||||||
|
{
|
||||||
|
return FALSE;//error al enviar paquete
|
||||||
|
}
|
||||||
|
env=cb.nb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//enviamos en bloques-----------------------------
|
||||||
|
for (int i=0; i<cb.n&&!*pirate;i++)
|
||||||
|
{
|
||||||
|
//calculamos tamaño envio
|
||||||
|
en=n-env;
|
||||||
|
if (en>MAX_LONG_PACKAGE_0)
|
||||||
|
en=MAX_LONG_PACKAGE_0;
|
||||||
|
//enviamos numero-----------------------------
|
||||||
|
if (!envia((BYTE*)&en,sizeof(int)))
|
||||||
|
{
|
||||||
|
return FALSE;//error al tamaño
|
||||||
|
}
|
||||||
|
//enviamos datos------------------------------
|
||||||
|
if (!envia(&buff[env],en))
|
||||||
|
{
|
||||||
|
return FALSE;//error al enviar datos
|
||||||
|
}
|
||||||
|
env+=en;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*pirate)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"envia_package: Solicitud de salida activado");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//verificamos----------------------------------------
|
||||||
|
return env==n;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
BOOL Csock_cl::recibe( BYTE*b, int n )
|
||||||
|
{
|
||||||
|
//int n,k,nv,err;
|
||||||
|
CString s;
|
||||||
|
int rec=0, rec_a=0,ier,nv=0;//bytes recibidos
|
||||||
|
|
||||||
|
while (!*pirate && rec<n)
|
||||||
|
{
|
||||||
|
rec_a = Receive(&b[rec],n - rec,0);
|
||||||
|
if (rec_a < 0)
|
||||||
|
{
|
||||||
|
ier = GetLastError();
|
||||||
|
if( ier != WSAEWOULDBLOCK )
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSOCK_CL);
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
nv++;
|
||||||
|
if (nv > intentos)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"Recibe: Demasiado tiempo esperando");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
Sleep(time_sleep);
|
||||||
|
}
|
||||||
|
else if (rec_a == 0)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"Recibe: Socket desconectado");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rec+=rec_a;
|
||||||
|
nv = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*pirate)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"Recibe: Solicitud de salida activado");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
BOOL Csock_cl::envia( BYTE*buff, int n)
|
||||||
|
{
|
||||||
|
//int ns,nv,err,ib;
|
||||||
|
int nv=0,env=0,env_a=0,ier;
|
||||||
|
//nv = ib = 0;
|
||||||
|
|
||||||
|
while (!*pirate && n>env)
|
||||||
|
{
|
||||||
|
//enviamos-------------------------------------------
|
||||||
|
env_a = Send(&buff[env],n-env,0);
|
||||||
|
|
||||||
|
if(env_a <= 0)
|
||||||
|
{
|
||||||
|
//analizamos el fallo----------------------------
|
||||||
|
ier = GetLastError();
|
||||||
|
if (ier != WSAEWOULDBLOCK)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSOCK_CL);
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
//toca esperar-----------------------------------
|
||||||
|
if (nv > intentos)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"Envia: Demasiado tiempo esperando");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
nv++;
|
||||||
|
Sleep(time_sleep);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
env+=env_a;
|
||||||
|
nv=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(*pirate)
|
||||||
|
{
|
||||||
|
er->pon(MODULO_CSOCK_CL,"Envia: Solicitud de salida activado");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
#if !defined(AFX_SOCK_SIMPLE_H__8491F9CB_65AF_44E1_80A3_52176804CD08__INCLUDED_)
|
||||||
|
#define AFX_SOCK_SIMPLE_H__8491F9CB_65AF_44E1_80A3_52176804CD08__INCLUDED_
|
||||||
|
|
||||||
|
#include <base_head.h>
|
||||||
|
#include "utiles_def.h"
|
||||||
|
#if _MSC_VER > 1000
|
||||||
|
#pragma once
|
||||||
|
#endif // _MSC_VER > 1000
|
||||||
|
#endif
|
||||||
|
#define MODULO_CSOCK_CL "Csock_cl"
|
||||||
|
#include <afxsock.h>
|
||||||
|
|
||||||
|
class C_error;
|
||||||
|
//socket cliente---------------------------------
|
||||||
|
class UTILES_EXPORT Csock_cl : public CAsyncSocket
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables----------------------------------
|
||||||
|
BOOL *pirate;
|
||||||
|
BOOL borra_pirate;
|
||||||
|
BYTE *buf;
|
||||||
|
int mb,nb;
|
||||||
|
Package_head_0 cab;
|
||||||
|
C_error* er;
|
||||||
|
int time_sleep;//tiempo espera
|
||||||
|
int intentos;
|
||||||
|
bool creado;
|
||||||
|
//variables aux------------------------------
|
||||||
|
private:
|
||||||
|
BOOL borra_er;
|
||||||
|
//cons---------------------------------------
|
||||||
|
public:
|
||||||
|
Csock_cl(BOOL*sal=NULL,C_error*e=NULL);
|
||||||
|
virtual ~Csock_cl(void);
|
||||||
|
|
||||||
|
//funciones----------------------------------
|
||||||
|
BOOL Create( UINT puerto=0 , int tipo=SOCK_STREAM ,
|
||||||
|
long evento=FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE ,
|
||||||
|
LPCTSTR ip=NULL );
|
||||||
|
|
||||||
|
BOOL conectar(char *ipdot,int puerto);//conecta con un puerto y ip
|
||||||
|
|
||||||
|
BOOL recibe_package(int indice);//recibe package y lo pone en buffer apartir de indice;
|
||||||
|
BOOL envia_package(BYTE* buff, int n, int encrip=0);//envia el buffer en packages si encrip=1 (hacemos encrip1)
|
||||||
|
//funciones auxiliares-----------------------
|
||||||
|
void cuida_buf(int n);//asegura en buf un espacio de n bytes;
|
||||||
|
BOOL recibe(BYTE*b, int n);//recive n bytes y lo pone en b;
|
||||||
|
BOOL envia(BYTE*buff, int n);//envia bytes sin mas;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,336 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "DataTransfer.h"
|
||||||
|
#include "Csock_cl.h"
|
||||||
|
//**********************************************************************************
|
||||||
|
DataTransfer::DataTransfer(void)
|
||||||
|
{
|
||||||
|
nb_ini =0;
|
||||||
|
n_buf =0;
|
||||||
|
sizeBuf =0;
|
||||||
|
nb_total =0;
|
||||||
|
sc =NULL;
|
||||||
|
dt =NULL;
|
||||||
|
total_p =0;
|
||||||
|
sc_p =0;
|
||||||
|
dt_p =0;
|
||||||
|
cancela = false;
|
||||||
|
mode = MODE_RECEIVE;
|
||||||
|
thbuf.data = this;
|
||||||
|
thsoc.data = this;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
DataTransfer::~DataTransfer(void)
|
||||||
|
{
|
||||||
|
cancela = true;
|
||||||
|
thbuf.join();
|
||||||
|
thsoc.join();
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
bool DataTransfer::start()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(currando() || !sc || !dt || nb_buf.n<=0 || buf.n<=0 || sizeBuf<=0)
|
||||||
|
return false;
|
||||||
|
errorSoc = 0;
|
||||||
|
errorDat =0;
|
||||||
|
nb_total =0;
|
||||||
|
total_p =0;
|
||||||
|
sc_p =0;
|
||||||
|
dt_p =0;
|
||||||
|
porcen =0;
|
||||||
|
mal = false;
|
||||||
|
cancela = false;
|
||||||
|
if(mode == MODE_SEND)
|
||||||
|
{
|
||||||
|
nb_total =dt->getNB_it();
|
||||||
|
if(!dt->setPosition_it(nb_ini) || nb_total<=0)
|
||||||
|
return false;
|
||||||
|
nb_total = nb_total-nb_ini;
|
||||||
|
total_p = (int)(nb_total*1./sizeBuf);
|
||||||
|
if(nb_total>(total_p*sizeBuf))
|
||||||
|
total_p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!thbuf.lanza("DataTransferBuf"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!thsoc.lanza("DataTransferSoc"))
|
||||||
|
{
|
||||||
|
cancela = true;
|
||||||
|
thbuf.join();
|
||||||
|
cancela = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
bool DataTransfer::currando()
|
||||||
|
{
|
||||||
|
return thsoc.isRunning() || thbuf.isRunning();
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
bool DataTransfer::isCanceled()
|
||||||
|
{
|
||||||
|
return cancela;
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
bool DataTransfer::setMode( int mod, int nbbuf /*= (1024*5)*/,int nbuf/*=2*/ )
|
||||||
|
{
|
||||||
|
mode = mod;
|
||||||
|
nb_buf.n =0;
|
||||||
|
buf.n=0;
|
||||||
|
if(!(nb_buf+=nbuf)|| !(buf+=(nbbuf*nbuf)))
|
||||||
|
return false;
|
||||||
|
nb_buf.n=nbuf;
|
||||||
|
sizeBuf = nbbuf;
|
||||||
|
buf.n =nbbuf*nbuf;
|
||||||
|
n_buf = nbuf;
|
||||||
|
memset(nb_buf.ptr,0,sizeof(int)*nbuf);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
bool DataTransfer::setData( Csock_cl* soc, IdataTransfer*datat )
|
||||||
|
{
|
||||||
|
if(!soc || !datat)
|
||||||
|
return false;
|
||||||
|
sc = soc;
|
||||||
|
dt =datat;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DataTransfer::getStatus()
|
||||||
|
{
|
||||||
|
return porcen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataTransfer::cancel()
|
||||||
|
{
|
||||||
|
cancela = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//**********************************************************************************
|
||||||
|
void ThBufDataTransfer::run()
|
||||||
|
{
|
||||||
|
if(data->mode == DataTransfer::MODE_RECEIVE)
|
||||||
|
runClear();
|
||||||
|
else
|
||||||
|
runFill();
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
void ThBufDataTransfer::runFill()
|
||||||
|
{
|
||||||
|
char *pbuf;
|
||||||
|
data->porcen =0;
|
||||||
|
ibuf =0;
|
||||||
|
while(!data->cancela && data->dt_p<data->total_p)
|
||||||
|
{
|
||||||
|
data->porcen = data->dt_p*100./data->total_p;
|
||||||
|
if(data->nb_buf[ibuf]<=0)
|
||||||
|
{
|
||||||
|
//decide numero de bites a cargar-------
|
||||||
|
__int64 nbp = (data->nb_total-data->sizeBuf*(data->dt_p));
|
||||||
|
if(nbp>data->sizeBuf)
|
||||||
|
nbp = data->sizeBuf;
|
||||||
|
//rellena buffer--------------
|
||||||
|
pbuf = &data->buf[ibuf*data->sizeBuf];
|
||||||
|
__int64 nb = data->dt->getNext_it(pbuf,nbp );
|
||||||
|
if(nb!=nbp)
|
||||||
|
{
|
||||||
|
data->errorDat =1;
|
||||||
|
data->mal = true;
|
||||||
|
data->cancela = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//actualiza indices
|
||||||
|
data->dt_p++;
|
||||||
|
data->nb_buf[ibuf] = (int)nb;
|
||||||
|
ibuf = (ibuf+1)%data->n_buf;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Sleep(0);
|
||||||
|
}
|
||||||
|
data->porcen = 100;
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
void ThBufDataTransfer::runClear()
|
||||||
|
{
|
||||||
|
char *pbuf;
|
||||||
|
ibuf =0;
|
||||||
|
data->porcen = 0;
|
||||||
|
//inicia-------------------------
|
||||||
|
//espera a que se recivan datos
|
||||||
|
while(!data->cancela && data->total_p<=0)
|
||||||
|
{
|
||||||
|
Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!data->dt->setPosition_it(data->nb_ini))
|
||||||
|
{
|
||||||
|
data->errorDat =-1;
|
||||||
|
data->mal = true;
|
||||||
|
data->cancela = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!data->cancela && data->dt_p<data->total_p)
|
||||||
|
{
|
||||||
|
data->porcen = data->dt_p*100./data->total_p;
|
||||||
|
if(data->nb_buf[ibuf]>0)
|
||||||
|
{
|
||||||
|
//decide numero de bites a cargar-------
|
||||||
|
__int64 nbp = data->nb_buf[ibuf];
|
||||||
|
|
||||||
|
//rellena buffer--------------
|
||||||
|
pbuf = &data->buf[ibuf*data->sizeBuf];
|
||||||
|
if(!data->dt->set_it(pbuf,nbp ))
|
||||||
|
{
|
||||||
|
data->errorDat =-2;
|
||||||
|
data->mal = true;
|
||||||
|
data->cancela = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//actualiza indices
|
||||||
|
data->dt_p++;
|
||||||
|
data->nb_buf[ibuf] = 0;
|
||||||
|
ibuf = (ibuf+1)%data->n_buf;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Sleep(0);
|
||||||
|
}
|
||||||
|
data->porcen =100;
|
||||||
|
}
|
||||||
|
|
||||||
|
//**********************************************************************************
|
||||||
|
void ThSockDataTransfer::run()
|
||||||
|
{
|
||||||
|
if(data->mode == DataTransfer::MODE_RECEIVE)
|
||||||
|
runReceive();
|
||||||
|
else
|
||||||
|
runSend();
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
void ThSockDataTransfer::runSend()
|
||||||
|
{
|
||||||
|
char *pbuf;
|
||||||
|
//inicia-----------------------
|
||||||
|
ibuf =0;
|
||||||
|
//envia cavecera
|
||||||
|
Head_DataTransfer cab;
|
||||||
|
cab.version = VERSION_HEAD_DATA_TRANSFER;
|
||||||
|
cab.nb_total = data->nb_total;
|
||||||
|
cab.nb_ini = data->nb_ini;
|
||||||
|
if(!data->sc->envia((BYTE*)&cab,(int) sizeof(cab)))
|
||||||
|
{
|
||||||
|
data->errorSoc =1;
|
||||||
|
data->mal = true;
|
||||||
|
data->cancela = true;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!data->cancela && data->sc_p<data->total_p)
|
||||||
|
{
|
||||||
|
if(data->nb_buf[ibuf]>0)
|
||||||
|
{
|
||||||
|
//decide numero de bites a cargar-------
|
||||||
|
__int64 nbp =data->nb_buf[ibuf];
|
||||||
|
if(nbp<data->sizeBuf)
|
||||||
|
nbp =nbp;
|
||||||
|
//rellena buffer--------------
|
||||||
|
pbuf = &data->buf[ibuf*data->sizeBuf];
|
||||||
|
if(!data->sc->envia((BYTE*)pbuf,(int) nbp))
|
||||||
|
{
|
||||||
|
data->errorSoc =2;
|
||||||
|
data->mal = true;
|
||||||
|
data->cancela = true;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->sc_p++;
|
||||||
|
data->nb_buf[ibuf] = 0;
|
||||||
|
ibuf = (ibuf+1)%data->n_buf;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Sleep(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!data->cancela && data->sc_p>=data->total_p)
|
||||||
|
{
|
||||||
|
if(!data->sc->recibe((BYTE*)&cab,(int) sizeof(cab)) || cab.version != VERSION_HEAD_DATA_TRANSFER || cab.nb_total != data->nb_total)
|
||||||
|
{
|
||||||
|
data->errorSoc =3;
|
||||||
|
data->mal = true;
|
||||||
|
data->cancela = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
void ThSockDataTransfer::runReceive()
|
||||||
|
{
|
||||||
|
char *pbuf;
|
||||||
|
//inicia-----------------------
|
||||||
|
ibuf =0;
|
||||||
|
//envia cavecera
|
||||||
|
Head_DataTransfer cab;
|
||||||
|
int nv=0;
|
||||||
|
bool res =false;
|
||||||
|
if(!data->sc->Receive((BYTE*)&cab,(int) sizeof(cab)) || cab.version != VERSION_HEAD_DATA_TRANSFER || cab.nb_total <=0)
|
||||||
|
{
|
||||||
|
data->errorSoc =-1;
|
||||||
|
data->mal = true;
|
||||||
|
|
||||||
|
data->cancela = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->nb_ini = cab.nb_ini;
|
||||||
|
data->nb_total = cab.nb_total;
|
||||||
|
int pp =(int)(data->nb_total*1./data->sizeBuf);
|
||||||
|
if(data->nb_total>(pp*data->sizeBuf))
|
||||||
|
pp++;
|
||||||
|
data->total_p = pp;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!data->cancela && data->sc_p<data->total_p)
|
||||||
|
{
|
||||||
|
if(data->nb_buf[ibuf]<=0)
|
||||||
|
{
|
||||||
|
//decide numero de bites a cargar-------
|
||||||
|
__int64 nbp =data->nb_total-((data->sc_p)*data->sizeBuf);
|
||||||
|
if(nbp>data->sizeBuf)
|
||||||
|
nbp=data->sizeBuf;
|
||||||
|
else
|
||||||
|
nbp =nbp;
|
||||||
|
//rellena buffer--------------
|
||||||
|
pbuf = &data->buf[ibuf*data->sizeBuf];
|
||||||
|
if(!data->sc->recibe((BYTE*)pbuf,(int) nbp))
|
||||||
|
{
|
||||||
|
if(data->sc->er->tipo<0)
|
||||||
|
continue;
|
||||||
|
data->errorSoc =-2;
|
||||||
|
data->mal = true;
|
||||||
|
data->cancela = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->sc_p++;
|
||||||
|
data->nb_buf[ibuf] = (int)nbp;
|
||||||
|
ibuf = (ibuf+1)%data->n_buf;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Sleep(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
cab.version = VERSION_HEAD_DATA_TRANSFER;
|
||||||
|
cab.nb_total = data->nb_total;
|
||||||
|
cab.nb_ini = data->nb_ini;
|
||||||
|
if(!data->cancela && !data->sc->envia((BYTE*)&cab,(int) sizeof(cab)))
|
||||||
|
{
|
||||||
|
data->errorSoc =-3;
|
||||||
|
data->mal = true;
|
||||||
|
data->cancela = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**********************************************************************************
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "th.h"
|
||||||
|
#include "garray.h"
|
||||||
|
//clase generica de transmision de datos por socket--------------
|
||||||
|
/*
|
||||||
|
la idea de esta clase es que para transmitir datos se usaran 2 socket, uno de envio/recepcion del socket y otro para llenar/vaciar bufferes
|
||||||
|
*/
|
||||||
|
|
||||||
|
class DataTransfer;
|
||||||
|
//thread de socket-------
|
||||||
|
class UTILES_EXPORT ThSockDataTransfer: public Cth
|
||||||
|
{
|
||||||
|
int ibuf;
|
||||||
|
void runSend();
|
||||||
|
void runReceive();
|
||||||
|
|
||||||
|
virtual void run();
|
||||||
|
public:
|
||||||
|
DataTransfer *data;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//thread de buffer-------
|
||||||
|
class UTILES_EXPORT ThBufDataTransfer: public Cth
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
int ibuf;
|
||||||
|
virtual void run();
|
||||||
|
void runFill();
|
||||||
|
void runClear();
|
||||||
|
public:
|
||||||
|
DataTransfer *data;
|
||||||
|
|
||||||
|
};
|
||||||
|
#define VERSION_HEAD_DATA_TRANSFER 100
|
||||||
|
typedef struct Head_DataTransfer
|
||||||
|
{
|
||||||
|
int version; //version informacion de usuaros
|
||||||
|
__int64 nb_total; //numero de bytes totales de los datos
|
||||||
|
__int64 nb_ini; //numero de usuarios en archivo
|
||||||
|
}Head_DataTransfer;
|
||||||
|
|
||||||
|
class Csock_cl;
|
||||||
|
class UTILES_EXPORT DataTransfer
|
||||||
|
{
|
||||||
|
friend class ThBufDataTransfer;
|
||||||
|
friend class ThSockDataTransfer;
|
||||||
|
|
||||||
|
__int64 nb_total;//numero de bytes totales de los datos
|
||||||
|
__int64 nb_ini;//byte inicial desde el cual se empieza a transmitir / guardar
|
||||||
|
Cgarray<char> buf;//buffer
|
||||||
|
Cgarray<int> nb_buf;//indica el numero de bites cargados en el buffer iesimo
|
||||||
|
|
||||||
|
Csock_cl* sc;//puntero a socket
|
||||||
|
IdataTransfer*dt;
|
||||||
|
|
||||||
|
int total_p;//total de partes en las que se dividen los datos
|
||||||
|
int sc_p;//partes recopiladas por th de socket
|
||||||
|
int dt_p;//partes recopiladas por th de bufer
|
||||||
|
int n_buf;//numero de bufferes
|
||||||
|
int sizeBuf;//tamaño de cada buffer
|
||||||
|
int mode;
|
||||||
|
|
||||||
|
int errorSoc;
|
||||||
|
int errorDat;
|
||||||
|
|
||||||
|
bool cancela;
|
||||||
|
bool mal;
|
||||||
|
double porcen;
|
||||||
|
ThSockDataTransfer thsoc;
|
||||||
|
ThBufDataTransfer thbuf;
|
||||||
|
public:
|
||||||
|
enum ModeDataTransfer{
|
||||||
|
MODE_RECEIVE,//modo recepcion
|
||||||
|
MODE_SEND//modo transmision
|
||||||
|
};
|
||||||
|
|
||||||
|
DataTransfer(void);
|
||||||
|
~DataTransfer(void);
|
||||||
|
|
||||||
|
//funciones de configuracion
|
||||||
|
bool setData(Csock_cl* soc, IdataTransfer*datat);
|
||||||
|
bool setMode(int mode, int nbbuf = (1024*50),int nbuf=2);//configura el modo y cuantos buffer y de cuantos bytes son cada uno
|
||||||
|
|
||||||
|
bool start();
|
||||||
|
|
||||||
|
double getStatus();
|
||||||
|
bool isCanceled();
|
||||||
|
bool currando();
|
||||||
|
void cancel();
|
||||||
|
void join();
|
||||||
|
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,206 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef DijkstraUtiles_h
|
||||||
|
#define DijkstraUtiles_h
|
||||||
|
#include <base_head.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "mapmatrix.h"
|
||||||
|
#ifndef MAYUSCULO
|
||||||
|
#define MAYUSCULO (double) 1.e+30
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#ifndef MINUSCULO
|
||||||
|
#define MINUSCULO (double) 1.e-20
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define EXT_ARCH_DIJ_DEFAULT "ndj"
|
||||||
|
#define NOMB_ARCH_DIJ_DEF "snodos_dj"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estructura de elemento de la cola para el cálculo de caminos óptimos por Dijkstra
|
||||||
|
*/
|
||||||
|
struct Djkt_elem_cola
|
||||||
|
{
|
||||||
|
int id; //<Id de elemento
|
||||||
|
int id_inci; //<Id del elemento desde el que se ha llegado a id
|
||||||
|
Djkt_elem_cola *sig; //<Puntero al siguiente elemento
|
||||||
|
};
|
||||||
|
#pragma pack(4)
|
||||||
|
/**
|
||||||
|
* Estructura de nodo para el cálculo de caminos óptimos por Dijkstra
|
||||||
|
*/
|
||||||
|
struct Djkt_nodo_0
|
||||||
|
{
|
||||||
|
int id_padre; //<Indice al nodo padre, o nodo hijo en el cálculo del dijsktra invertido
|
||||||
|
float dis; //<Distancia
|
||||||
|
BOOL visto; //<Indica si se ha pasado ya por el nodo
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
* Estructura de ángulos entre conjunciones adyacentes para añadir al Dijkstra el ángulo de giro
|
||||||
|
*/
|
||||||
|
typedef struct Djkt_ids_pdr
|
||||||
|
{
|
||||||
|
int id; //id padre al que tienes que ir
|
||||||
|
float dis; //distancia que vas a recorrer
|
||||||
|
}Djkt_ids_pdr;
|
||||||
|
/*
|
||||||
|
* Estructura de ángulos entre conjunciones adyacentes para añadir al Dijkstra el ángulo de giro
|
||||||
|
*/
|
||||||
|
class UTILES_EXPORT Djkt_ang_ady
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int nady;
|
||||||
|
Djkt_ids_pdr *ids_padre;
|
||||||
|
int *i_conjs;
|
||||||
|
BYTE **angs;
|
||||||
|
//*******************************************
|
||||||
|
Djkt_ang_ady();
|
||||||
|
void libera();
|
||||||
|
BOOL inicia(int n, BOOL no_angs=FALSE);
|
||||||
|
BOOL dame_ii_jj(int i, int j, int *ii_,int *jj_);
|
||||||
|
BOOL pon_ang_i_j(int i,int j, BYTE ang);
|
||||||
|
BOOL dame_ang_i_j(int i,int j, BYTE *ang, BOOL inds_abs);
|
||||||
|
BOOL pon_padre(int i_orig,int j_padre, double dis, BOOL inds_abs);
|
||||||
|
BOOL dame_padre(int i_orig,int *j_padre, double *dis, BOOL inds_abs);
|
||||||
|
BOOL inicia_ids();
|
||||||
|
void libera_ex();
|
||||||
|
BOOL guarda(HeadCostAng hd, int ic, char *path, char * ext);
|
||||||
|
BOOL lee(int ic, char *path , char * ext);
|
||||||
|
};
|
||||||
|
//*************************************************************************************
|
||||||
|
struct Djkt_nodo: public Djkt_nodo_0
|
||||||
|
{
|
||||||
|
Djkt_ang_ady ids_ady;
|
||||||
|
//Funciones
|
||||||
|
void inicia();
|
||||||
|
BOOL inicia_ex(Djkt_ang_ady *ang);
|
||||||
|
void libera( );
|
||||||
|
};
|
||||||
|
#pragma pack(16)
|
||||||
|
/**
|
||||||
|
* Estructura de cola con prioridad para el cálculo de caminos óptimos por Dijkstra
|
||||||
|
*/
|
||||||
|
struct Djkt_cola
|
||||||
|
{
|
||||||
|
int nn;
|
||||||
|
Djkt_nodo *nodos; //<Puntero a matriz de nodos
|
||||||
|
Djkt_elem_cola *elem; //<Puntero a elementos almacenados
|
||||||
|
//Funciones
|
||||||
|
void inicia(Djkt_nodo *n);
|
||||||
|
BOOL pon(int i);
|
||||||
|
BOOL pon(int i,int i_inci);
|
||||||
|
int dame();
|
||||||
|
int dame(int *id_inci);
|
||||||
|
};
|
||||||
|
//*************************************************************************************
|
||||||
|
class UTILES_EXPORT FlagsArray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Cgarray<BYTE> dat;
|
||||||
|
inline BOOL operator[](__int64 i)
|
||||||
|
{
|
||||||
|
BYTE j =(BYTE)(1<<(i%(sizeof(BYTE)*8)));
|
||||||
|
return (BOOL)((dat[(int)(i/(sizeof(BYTE)*8.))] & j) == j);
|
||||||
|
}
|
||||||
|
inline void set(__int64 i, BOOL v)
|
||||||
|
{
|
||||||
|
BYTE j;
|
||||||
|
j =(BYTE)(1<<(i%(sizeof(BYTE)*8)));
|
||||||
|
|
||||||
|
if(!v)
|
||||||
|
{
|
||||||
|
j = ~j;
|
||||||
|
dat[(int)(i/(sizeof(BYTE)*8.))] &= j;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dat[(int)(i/(sizeof(BYTE)*8.))] |= j;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline BOOL dimensiona(__int64 n)
|
||||||
|
{
|
||||||
|
dat.n = 0;
|
||||||
|
int nn = (int)(0.5+n/(sizeof(BYTE)*8.));
|
||||||
|
if(!(dat+=nn))
|
||||||
|
return FALSE;
|
||||||
|
dat.n = nn;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
inline void setAll(BOOL v)
|
||||||
|
{
|
||||||
|
BYTE j = 0;
|
||||||
|
if(v)
|
||||||
|
j =~j;
|
||||||
|
memset(dat.ptr, j, dat.n*sizeof(BYTE));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//*************************************************************************************
|
||||||
|
class UTILES_EXPORT DijkstraUtiles
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static BOOL dijkstra_ang_inv_ok(CmapMatFloat &costes, Djkt_ang_ady *angs, int n, int fin, Djkt_nodo **nodos, FlagsArray *visto_ang_);
|
||||||
|
static double ruta_dj_inv_ok(int id_ini, int *secu, Djkt_nodo *nodos, int nmax, int *n);
|
||||||
|
static double ruta_dj_inv(int id_ini, int *secu, Djkt_nodo *nodos, int nmax, int *n);
|
||||||
|
};
|
||||||
|
|
||||||
|
//*************************************************************************************
|
||||||
|
/**
|
||||||
|
* Clase de manejo de archivos de nodos djtra
|
||||||
|
* cada archivo tiene un numero de bloques o array de nodos de longitud fija "nnod"
|
||||||
|
*/
|
||||||
|
//estructura cabecera de archivo
|
||||||
|
typedef struct Head_dj_arch
|
||||||
|
{
|
||||||
|
int version; //version del archivo
|
||||||
|
int nn; //numero de nodos por bloque
|
||||||
|
int nb; //numero de bloques del dj
|
||||||
|
int max_conex; //maximo de conexiones por nodo
|
||||||
|
|
||||||
|
}Head_dj_arch;
|
||||||
|
#define VERSION_DJ_ARCHI 100
|
||||||
|
#define MAX_CONEX_DJ_ARCHI 16
|
||||||
|
|
||||||
|
class UTILES_EXPORT InfoIndice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual int get(int iamb, int iextremo) = 0;//da del ambito iamb el indice a inicio o a fin //si iextremo es o o 1
|
||||||
|
};
|
||||||
|
|
||||||
|
class UTILES_EXPORT Cdijkstra_arch
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
char extension[16];//extension de archivos
|
||||||
|
char path[MAX_PATH];//nombre sin extension
|
||||||
|
Head_dj_arch hd;//cabecera de archivo
|
||||||
|
int sizn;//tamaño en BYTES de cada nodo
|
||||||
|
BOOL salta_ids_padres;
|
||||||
|
//int flags;//0x1-->modo escritura 0x2-->modo lectura
|
||||||
|
//info de distancias ambitos
|
||||||
|
float *dis;//distancia de un nodo a otro (matriz de nnod*nnod)
|
||||||
|
int nod_amb;//nodos por ambito
|
||||||
|
int nambi;//numero de ambitos
|
||||||
|
int nnod;//numero de nodos por fila
|
||||||
|
int id_instal;//fila planta
|
||||||
|
int id_plan;//fila instal
|
||||||
|
int nod_instal;//nodo instalacion
|
||||||
|
int nod_plan;//nodo planta
|
||||||
|
int tip_ambitos;
|
||||||
|
|
||||||
|
InfoIndice* ia;//puntero a info asoc
|
||||||
|
|
||||||
|
//funciones--------------------------------------------------------------------------
|
||||||
|
Cdijkstra_arch();
|
||||||
|
~Cdijkstra_arch();
|
||||||
|
|
||||||
|
BOOL inicia(char* path_arch, BOOL nuevo=FALSE, BOOL borra = TRUE, int n_nod=0, int max_conex=MAX_CONEX_DJ_ARCHI);//si nuevo -> crea vacio
|
||||||
|
BOOL add_b(Djkt_nodo* blq, int iref, int inod, BOOL pon_inf=FALSE);//añade un bloque a el archivo
|
||||||
|
BOOL inicia_inf_amb(InfoIndice* ina, int namb,int tip_amb, int id_instal=-1, int id_plan=-1);
|
||||||
|
void pon_info_amb(Djkt_nodo* nodos, int iref,int ib);
|
||||||
|
Djkt_nodo* get_b(int iref, int ibloq, Djkt_nodo* buf=NULL);//develve el bloque ibloq-esimo
|
||||||
|
float dame_dis(int aorig,int norig, int ades, int n_des);
|
||||||
|
|
||||||
|
Djkt_nodo* dame_buf_nodos(BOOL angulos=FALSE );
|
||||||
|
void libera_buf(Djkt_nodo* buf );
|
||||||
|
BOOL graba_dis(int id);
|
||||||
|
BOOL lee_dis();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "FdataTable.h"
|
||||||
|
|
||||||
|
FdataTable::FdataTable(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FdataTable::~FdataTable(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
|
||||||
|
//clase para gestiona una tabla de datos generica
|
||||||
|
class UTILES_EXPORT FdataTable
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum DataType
|
||||||
|
{
|
||||||
|
NdefData=0,
|
||||||
|
BoolData,
|
||||||
|
IntData,
|
||||||
|
DoubleData,
|
||||||
|
StringData,
|
||||||
|
BinaryData
|
||||||
|
};
|
||||||
|
|
||||||
|
FdataTable(void);
|
||||||
|
~FdataTable(void);
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,538 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "Fdbf.h"
|
||||||
|
//*****************************************************************************************
|
||||||
|
Fdbf::Fdbf(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
Fdbf::~Fdbf(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::lee( Cb_file *file)
|
||||||
|
{
|
||||||
|
int ncol;
|
||||||
|
colm.n =0;
|
||||||
|
iniCol.n =0;
|
||||||
|
buf.n=0;
|
||||||
|
if(!file->lee(&head, sizeof(head)))
|
||||||
|
return false;
|
||||||
|
ncol = (head.nb_cab - sizeof(Hdr_dbf) - 1) / sizeof(Fld_dbf);
|
||||||
|
if(ncol<=0)
|
||||||
|
return false;
|
||||||
|
if(!(colm+=ncol))
|
||||||
|
return false;
|
||||||
|
if(!(iniCol+=ncol))
|
||||||
|
return false;
|
||||||
|
colm.n = ncol;
|
||||||
|
iniCol.n = ncol;
|
||||||
|
//pilla info de campos-----------------------
|
||||||
|
if(!file->lee(&colm[0], sizeof(Fld_dbf)*colm.n))
|
||||||
|
return false;
|
||||||
|
int aux =1;
|
||||||
|
for(int i =0; i<colm.n; i++)
|
||||||
|
{
|
||||||
|
iniCol[i]=aux;
|
||||||
|
aux+=colm[i].nb;
|
||||||
|
}
|
||||||
|
//lee reserva
|
||||||
|
if(!file->lee(&ncol, 1))
|
||||||
|
return false;
|
||||||
|
if(!(buf+=head.nb_rec))
|
||||||
|
return false;
|
||||||
|
buf.n = head.nb_rec;
|
||||||
|
f= file;
|
||||||
|
nReadRow =0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int Fdbf::leeNexRow()//devuelve 1 si ok 0 si no mas -1 si error
|
||||||
|
{
|
||||||
|
if(nReadRow>=head.nrec)
|
||||||
|
return 0;
|
||||||
|
if(!f->lee(&buf[0], head.nb_rec))
|
||||||
|
return -1;
|
||||||
|
nReadRow++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
char* Fdbf::getName(int ncol)
|
||||||
|
{
|
||||||
|
if(ncol>=colm.n)
|
||||||
|
return 0;
|
||||||
|
return colm[ncol].nombre;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
BYTE Fdbf::getType(int ncol)
|
||||||
|
{
|
||||||
|
if(ncol>=colm.n)
|
||||||
|
return 0;
|
||||||
|
return colm[ncol].tipo;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int Fdbf::getSize(int ncol)
|
||||||
|
{
|
||||||
|
if(ncol>=colm.n)
|
||||||
|
return 0;
|
||||||
|
return (int)colm[ncol].nb;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int Fdbf::getNrow()
|
||||||
|
{
|
||||||
|
return head.nrec;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int Fdbf::getNcolm()
|
||||||
|
{
|
||||||
|
return colm.n;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
char* Fdbf::get(int ncol)
|
||||||
|
{
|
||||||
|
if(ncol>=colm.n)
|
||||||
|
return 0;
|
||||||
|
//if(!f->lee(&buf[0], head.nb_rec))
|
||||||
|
// return NULL;
|
||||||
|
return &buf[iniCol[ncol]];
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::bufMem(int ncol)
|
||||||
|
{
|
||||||
|
char*d = get(ncol);
|
||||||
|
int nb = colm[ncol].nb+1;
|
||||||
|
if(buf2.m<nb)
|
||||||
|
{
|
||||||
|
buf2.n=0;
|
||||||
|
if(!(buf2+=nb))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
buf2.n = nb;
|
||||||
|
char *s=&buf2[0];
|
||||||
|
memcpy(s,d,nb-1);
|
||||||
|
buf2[nb-1] = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double Fdbf::getD(int col)
|
||||||
|
{
|
||||||
|
if(!bufMem(col))
|
||||||
|
return 0;
|
||||||
|
char *str=&buf2[0];
|
||||||
|
/*double k;
|
||||||
|
if ((*camp)[ic].tipo == 6)
|
||||||
|
{
|
||||||
|
sscanf(str,"%x",&k);
|
||||||
|
return(k);
|
||||||
|
}
|
||||||
|
else if ((*camp)[ic].tipo == 7)
|
||||||
|
{
|
||||||
|
str[2] = 0;
|
||||||
|
str[5] = 0;
|
||||||
|
k = atol(str) * 3600;
|
||||||
|
k = atol(&str[3]) * 60 + k;
|
||||||
|
k = atol(&str[6]) + k;
|
||||||
|
return(k);
|
||||||
|
}*/
|
||||||
|
return(atof(&buf2[0]));
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int Fdbf::getI(int col)
|
||||||
|
{
|
||||||
|
return (int)getD(col);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
char* Fdbf::getStr(int col)
|
||||||
|
{
|
||||||
|
if(!bufMem(col))
|
||||||
|
return 0;
|
||||||
|
char *str=&buf2[0];
|
||||||
|
char*s=&buf2[buf2.n-1];
|
||||||
|
while((*s == ' ' || *s==0) && s!=str)
|
||||||
|
{
|
||||||
|
*s = 0;
|
||||||
|
s--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
__int64 Fdbf::getI64(int col)
|
||||||
|
{
|
||||||
|
if(!bufMem(col))
|
||||||
|
return 0;
|
||||||
|
char *str=&buf2[0];
|
||||||
|
int dd,mm,aa;
|
||||||
|
dd = atol(&str[6]);
|
||||||
|
str[6] = 0;
|
||||||
|
mm = atol(&str[4]);
|
||||||
|
str[4] = 0;
|
||||||
|
aa = atol(str);
|
||||||
|
CTime tt(aa,mm,dd,0,0,0,-1);
|
||||||
|
return(tt.GetTime());
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::set(int ncol, int nRow, Cb_file *file)
|
||||||
|
{
|
||||||
|
f = file;
|
||||||
|
colm.n =0;
|
||||||
|
nReadRow =-1;
|
||||||
|
if(!(colm+=ncol))
|
||||||
|
return false;
|
||||||
|
iniCol.n =0;
|
||||||
|
if(!(iniCol+=ncol))
|
||||||
|
return false;
|
||||||
|
memset(&head,0,sizeof(Hdr_dbf));
|
||||||
|
|
||||||
|
CTime tt = CTime::GetCurrentTime();
|
||||||
|
colm.n = ncol;
|
||||||
|
iniCol.n = ncol;
|
||||||
|
head.ver =3;
|
||||||
|
head.dia=(BYTE)tt.GetDay();
|
||||||
|
head.mes=(BYTE)tt.GetMonth();
|
||||||
|
head.dia=(BYTE)(tt.GetYear() - 1900);
|
||||||
|
head.nrec=nRow;
|
||||||
|
head.nb_cab = (short) (ncol * sizeof(Fld_dbf) + 1 + sizeof(Hdr_dbf));
|
||||||
|
if(!f->escribe(&head, sizeof(head)))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::setCol(int icol, char *name, BYTE type, int size, int ndecimals)
|
||||||
|
{
|
||||||
|
if(icol<0 || icol>colm.n)
|
||||||
|
return false;
|
||||||
|
nReadRow =-1;
|
||||||
|
int i =0;
|
||||||
|
//copia de nombre segura--------
|
||||||
|
for(; i<11; i++)
|
||||||
|
{
|
||||||
|
colm[icol].nombre[i]=name[i];
|
||||||
|
if(!name[i])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
colm[icol].nombre[i] =0;
|
||||||
|
//------------------------------
|
||||||
|
colm[icol].tipo = type;
|
||||||
|
colm[icol].nb = size;
|
||||||
|
colm[icol].nd = ndecimals;
|
||||||
|
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case(DBF_TYPE_DATA_I64):
|
||||||
|
case(DBF_TYPE_DATA_STR):
|
||||||
|
case(DBF_TYPE_DATA_BIN):
|
||||||
|
case(DBF_TYPE_DATA_I):
|
||||||
|
colm[icol].nd =0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::iniciaRecords()
|
||||||
|
{
|
||||||
|
if(nReadRow>=0)
|
||||||
|
return true;
|
||||||
|
nReadRow =0;
|
||||||
|
int nb =1;
|
||||||
|
for(int i =0; i<colm.n; i++)
|
||||||
|
{
|
||||||
|
iniCol[i]=nb;
|
||||||
|
nb +=colm[i].nb;
|
||||||
|
}
|
||||||
|
buf.n =0;
|
||||||
|
if(!(buf+=nb))
|
||||||
|
return false;
|
||||||
|
buf.n =nb;
|
||||||
|
head.nb_rec = nb;
|
||||||
|
if(!f->irAini())
|
||||||
|
return false;
|
||||||
|
if(!f->escribe(&head, sizeof(head)))
|
||||||
|
return false;
|
||||||
|
//graba info------------------------
|
||||||
|
if(!f->escribe(&colm[0], sizeof(Fld_dbf)*colm.n))
|
||||||
|
return false;
|
||||||
|
//graba terminacion de head
|
||||||
|
char ff = 13;
|
||||||
|
if(! f->escribe(&ff, sizeof(ff)))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::addVal(int icol, int v)
|
||||||
|
{
|
||||||
|
char st1[64];
|
||||||
|
if(!iniciaRecords())
|
||||||
|
return false;
|
||||||
|
buf2.n =0;
|
||||||
|
|
||||||
|
if(!(buf2+=(colm[icol].nb+1)))
|
||||||
|
return false;
|
||||||
|
buf2.n =colm[icol].nb+1;
|
||||||
|
|
||||||
|
sprintf(st1,"%%0%ldd",colm[icol].nb);
|
||||||
|
sprintf(&buf2[0],st1,v);
|
||||||
|
|
||||||
|
int n = (int)strlen(&buf2[0]);
|
||||||
|
if (n > colm[icol].nb)
|
||||||
|
n = colm[icol].nb;
|
||||||
|
//alinea a la derecha
|
||||||
|
char *st = &buf[iniCol[icol]];
|
||||||
|
memset(st,0x20, colm[icol].nb);
|
||||||
|
memcpy(st+colm[icol].nb-n,&buf2[0],n);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::addVal(int icol, double v)
|
||||||
|
{
|
||||||
|
char st1[64];
|
||||||
|
if(!iniciaRecords())
|
||||||
|
return false;
|
||||||
|
buf2.n =0;
|
||||||
|
|
||||||
|
if(!(buf2+=colm[icol].nb))
|
||||||
|
return false;
|
||||||
|
buf2.n =colm[icol].nb;
|
||||||
|
|
||||||
|
sprintf(st1,"%%1.%ldlf",colm[icol].nd);
|
||||||
|
sprintf(&buf2[0],st1,v);
|
||||||
|
|
||||||
|
int n =(int) strlen(&buf2[0]);
|
||||||
|
if (n > colm[icol].nb)
|
||||||
|
n = colm[icol].nb;
|
||||||
|
//alinea a la derecha
|
||||||
|
char *st = &buf[iniCol[icol]];
|
||||||
|
memset(st,0x20, colm[icol].nb);
|
||||||
|
memcpy(st+colm[icol].nb-n,&buf2[0],n);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::addVal(int icol, __int64 v)
|
||||||
|
{
|
||||||
|
char st1[32];
|
||||||
|
CTime tt(v);
|
||||||
|
|
||||||
|
if(!iniciaRecords())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
buf2.n =0;
|
||||||
|
|
||||||
|
if(!(buf2+=colm[icol].nb))
|
||||||
|
return false;
|
||||||
|
buf2.n =colm[icol].nb;
|
||||||
|
|
||||||
|
strcpy(st1,tt.Format("%Y%m%d"));
|
||||||
|
|
||||||
|
sprintf(&buf2[0],st1,v);
|
||||||
|
|
||||||
|
int n =(int) strlen(&buf2[0]);
|
||||||
|
if (n > colm[icol].nb)
|
||||||
|
n = colm[icol].nb;
|
||||||
|
//alinea a la derecha
|
||||||
|
char *st = &buf[iniCol[icol]];
|
||||||
|
memset(st,0x20, colm[icol].nb);
|
||||||
|
memcpy(st+colm[icol].nb-n,&buf2[0],n);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::finRow()
|
||||||
|
{
|
||||||
|
//comprueba maximo
|
||||||
|
if(nReadRow>= head.nrec)
|
||||||
|
return false;
|
||||||
|
nReadRow++;
|
||||||
|
buf[0]=' ';
|
||||||
|
//graba buffer en archivo
|
||||||
|
if(!f->escribe(&buf[0], buf.n))
|
||||||
|
return false;
|
||||||
|
//si es el final graba head
|
||||||
|
if(nReadRow>= head.nrec)
|
||||||
|
{
|
||||||
|
buf[0]=26;
|
||||||
|
if(!f->escribe(&buf[0], 1))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::addVal(int icol, char* v)
|
||||||
|
{
|
||||||
|
if(!iniciaRecords())
|
||||||
|
return false;
|
||||||
|
int i =0;
|
||||||
|
char *dt=&buf[iniCol[icol]];
|
||||||
|
double maxi = colm[icol].nb;
|
||||||
|
//copia de nombre segura--------
|
||||||
|
for(; i<maxi; i++)
|
||||||
|
{
|
||||||
|
dt[i]=v[i];
|
||||||
|
if(!v[i])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dt[i] =0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool Fdbf::addVal(int icol, void* v)
|
||||||
|
{
|
||||||
|
if(!iniciaRecords())
|
||||||
|
return false;
|
||||||
|
memcpy(&buf[iniCol[icol]],v,colm[icol].nb);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
int Fdbf::findCol( char *name )
|
||||||
|
{
|
||||||
|
for(int i =0; i<colm.n;i++)
|
||||||
|
{
|
||||||
|
if(0==strcmp(colm[i].nombre,name))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool ManagerDbf::leer(char* file, ListenerDbf_W* lr)
|
||||||
|
{
|
||||||
|
Cb_file f;
|
||||||
|
if(!f.abre(file,1,0,true))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return leer(&f,lr);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool ManagerDbf::leer(Cb_file* f, ListenerDbf_W* lr)
|
||||||
|
{
|
||||||
|
Fdbf dbf;
|
||||||
|
if(!dbf.lee(f))
|
||||||
|
return false;
|
||||||
|
int nrow = dbf.getNrow();
|
||||||
|
int ncolm = dbf.getNcolm();
|
||||||
|
if(!lr->DbfSet(nrow, ncolm))
|
||||||
|
return false;
|
||||||
|
//prepara las columnas---------------
|
||||||
|
for(int i =0; i<ncolm; i++)
|
||||||
|
{
|
||||||
|
if(!lr->DbfSetColm(dbf.getName(i),dbf.getType(i),dbf.getSize(i)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//recorre las filas---------------
|
||||||
|
int error =dbf.leeNexRow();
|
||||||
|
while(error ==1)
|
||||||
|
{
|
||||||
|
//por cada fila recorre las columnas
|
||||||
|
for(int i =0; i<ncolm; i++)
|
||||||
|
{
|
||||||
|
bool res =false;
|
||||||
|
switch(dbf.getType(i))
|
||||||
|
{
|
||||||
|
case(DBF_TYPE_DATA_STR):
|
||||||
|
res =lr->DbfaddVal(i,dbf.getStr(i));
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_I64):
|
||||||
|
res =lr->DbfaddVal(i,dbf.getI64(i));
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_D):
|
||||||
|
res =lr->DbfaddVal(i,dbf.getD(i));
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_BOOL):
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_BIN):
|
||||||
|
res =lr->DbfaddVal(i,dbf.get(i));
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_I):
|
||||||
|
res =lr->DbfaddVal(i,dbf.getI(i));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!res)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!lr->DbfFinRow())
|
||||||
|
return false;
|
||||||
|
error =dbf.leeNexRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
return error == 0 && lr->DbfFinRow();
|
||||||
|
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool ManagerDbf::grabar(char* file, ListenerDbf_R* lw)
|
||||||
|
{
|
||||||
|
Cb_file f;
|
||||||
|
if(!f.abre(file,2,true))
|
||||||
|
return false;
|
||||||
|
return grabar(&f,lw);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool ManagerDbf::grabar(Cb_file* f, ListenerDbf_R* lw)
|
||||||
|
{
|
||||||
|
Fdbf dbf;
|
||||||
|
int nrow =-1;
|
||||||
|
int ncolm =-1;
|
||||||
|
char name[11];
|
||||||
|
BYTE type;
|
||||||
|
int size;
|
||||||
|
int nd;
|
||||||
|
if(!lw->DbfGet(&nrow, &ncolm) /*|| nrow<=0 || ncolm<=0*/)
|
||||||
|
return false;
|
||||||
|
if(!dbf.set(ncolm, nrow, f))
|
||||||
|
return false;
|
||||||
|
//prepara las columnas---------------
|
||||||
|
for(int i =0; i<ncolm; i++)
|
||||||
|
{
|
||||||
|
if(!lw->DbfGetColm(i,name,&type,&size,&nd))
|
||||||
|
return false;
|
||||||
|
if(!dbf.setCol(i,name,type,size,nd))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//recorre las filas---------------
|
||||||
|
char *cv;
|
||||||
|
void *vv;
|
||||||
|
double dv;
|
||||||
|
int iv;
|
||||||
|
__int64 i64v;
|
||||||
|
for(int j =0;j<nrow; j++)
|
||||||
|
{
|
||||||
|
//por cada fila recorre las columnas
|
||||||
|
for(int i =0; i<ncolm; i++)
|
||||||
|
{
|
||||||
|
bool res =false;
|
||||||
|
switch(dbf.getType(i))
|
||||||
|
{
|
||||||
|
case(DBF_TYPE_DATA_STR):
|
||||||
|
res =lw->DbfGetVal(j, i, &cv) && dbf.addVal(i,cv);
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_I64):
|
||||||
|
res =lw->DbfGetVal(j, i, &i64v) && dbf.addVal(i,i64v);
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_D):
|
||||||
|
res =lw->DbfGetVal(j, i, &dv) && dbf.addVal(i,dv);
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_BOOL):
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_BIN):
|
||||||
|
res =lw->DbfGetVal(j, i, &vv) && dbf.addVal(i,vv);
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_I):
|
||||||
|
res = lw->DbfGetVal(j, i, &iv) && dbf.addVal(i,iv);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!res)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!lw->DbfFinW())
|
||||||
|
return false;
|
||||||
|
if(!dbf.finRow())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
|
@ -0,0 +1,184 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef Fdbf_H
|
||||||
|
#define Fdbf_H
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "b_file.h"
|
||||||
|
#include "garray.h"
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
typedef struct Hdr_dbf
|
||||||
|
{
|
||||||
|
BYTE ver,year,mes,dia; // cuatro primeros bytes
|
||||||
|
long nrec; // nº de records (filas)
|
||||||
|
short nb_cab; // nº de bytes de la cabecera
|
||||||
|
short nb_rec; // nº de bytes de cada record
|
||||||
|
BYTE res[20];
|
||||||
|
} Hdr_dbf;
|
||||||
|
|
||||||
|
typedef struct Fld_dbf
|
||||||
|
{
|
||||||
|
char nombre[11]; // nombre del campo
|
||||||
|
BYTE tipo; // tipo de campo
|
||||||
|
// C caracter
|
||||||
|
// N número
|
||||||
|
// L lógico (Y/N,T/F, y mas)
|
||||||
|
// D fecha (YYYYMMDD)
|
||||||
|
// F float, double
|
||||||
|
BYTE res1[4];
|
||||||
|
BYTE nb; // nº de bytes del campo
|
||||||
|
//Nuevo elena 201709
|
||||||
|
union
|
||||||
|
{
|
||||||
|
BYTE res2[15];
|
||||||
|
struct{
|
||||||
|
|
||||||
|
|
||||||
|
BYTE nd; //nº de decimales
|
||||||
|
BYTE res2_[14];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} Fld_dbf;
|
||||||
|
|
||||||
|
#pragma pack(8)
|
||||||
|
|
||||||
|
#define DBF_TYPE_DATA_STR 'C'
|
||||||
|
#define DBF_TYPE_DATA_I64 'D'
|
||||||
|
#define DBF_TYPE_DATA_D 'F'
|
||||||
|
#define DBF_TYPE_DATA_BOOL 'L'
|
||||||
|
#define DBF_TYPE_DATA_BIN 'M'
|
||||||
|
#define DBF_TYPE_DATA_I 'N'
|
||||||
|
|
||||||
|
//clase base de dbf-------------------------------------
|
||||||
|
class UTILES_EXPORT Fdbf
|
||||||
|
{
|
||||||
|
Hdr_dbf head;
|
||||||
|
Cgarray<Fld_dbf>colm;
|
||||||
|
Cgarray<char> buf;//buffer de fila
|
||||||
|
Cgarray<char> buf2;//buffer auxi
|
||||||
|
|
||||||
|
Cgarray<int>iniCol;//indice a el bite deonde empieza la columna iesima dentro de una fila
|
||||||
|
Cb_file *f;
|
||||||
|
int nReadRow;//numero de filas leidas actualmente
|
||||||
|
public:
|
||||||
|
Fdbf(void);
|
||||||
|
~Fdbf(void);
|
||||||
|
|
||||||
|
//funciones de lectura
|
||||||
|
bool lee( Cb_file *file);
|
||||||
|
int leeNexRow();//devuelve 1 si ok 0 si no mas -1 si error
|
||||||
|
|
||||||
|
double getD(int ncol);
|
||||||
|
int getI(int ncol);
|
||||||
|
char* getStr(int ncol);
|
||||||
|
__int64 getI64(int ncol);
|
||||||
|
char* get(int ncol);//devuelve buffer tal cual
|
||||||
|
|
||||||
|
BYTE getType(int ncol);
|
||||||
|
char* getName(int ncol);
|
||||||
|
int findCol(char *name);
|
||||||
|
|
||||||
|
int getSize(int ncol);
|
||||||
|
int getNrow();
|
||||||
|
int getNcolm();
|
||||||
|
//funciones de escritura
|
||||||
|
bool set(int ncol, int nRow, Cb_file *file);
|
||||||
|
bool setCol(int icol, char *name, BYTE type, int size, int ndecimals=0);
|
||||||
|
|
||||||
|
bool addVal(int icol, int v);
|
||||||
|
bool addVal(int icol, double v);
|
||||||
|
bool addVal(int icol, __int64 v);
|
||||||
|
bool addVal(int icol, char* v);
|
||||||
|
bool addVal(int icol, void* v);
|
||||||
|
bool finRow();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool bufMem(int ncol);
|
||||||
|
bool iniciaRecords();
|
||||||
|
};
|
||||||
|
|
||||||
|
//clase lisener de lectura
|
||||||
|
class UTILES_EXPORT ListenerDbf_W
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool DbfSet(int nrow, int ncolm){return true;}
|
||||||
|
virtual bool DbfSetColm(char* name, BYTE type, int size){return true;}
|
||||||
|
virtual bool DbfaddVal(int icol, int v){return true;}
|
||||||
|
virtual bool DbfaddVal(int icol, double v){return true;}
|
||||||
|
virtual bool DbfaddVal(int icol, __int64 v){return true;}
|
||||||
|
virtual bool DbfaddVal(int icol, char* v){return true;}
|
||||||
|
virtual bool DbfaddVal(int icol, void* v){return true;}
|
||||||
|
virtual bool DbfFinRow(){return true;}
|
||||||
|
virtual bool DbfFinR(){return true;}
|
||||||
|
|
||||||
|
};
|
||||||
|
//clase lisener de escritura
|
||||||
|
class UTILES_EXPORT ListenerDbf_R
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool DbfGet(int *nrow, int *ncolm){return false;}
|
||||||
|
virtual bool DbfGetColm(int icol, char* name, BYTE *type, int *size, int*ndecimal){return false;}
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, int* v){return false;}
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, double* v){return false;}
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, __int64* v){return false;}
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, char** v){return false;}
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, void** v){return false;}
|
||||||
|
virtual bool DbfFinW(){return false;}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//clase manager dbf-------------------------
|
||||||
|
class UTILES_EXPORT ManagerDbf
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool leer(Cb_file *file, ListenerDbf_W* lr);
|
||||||
|
static bool grabar(Cb_file *file, ListenerDbf_R* lw);
|
||||||
|
|
||||||
|
static bool leer(char* file, ListenerDbf_W* lr);
|
||||||
|
static bool grabar(char* file, ListenerDbf_R* lw);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
ejemplo de uso--------------------------------
|
||||||
|
escritura---------
|
||||||
|
if(!f.abre("d:\\temp\\p2.dbf",2,true))
|
||||||
|
error =true;
|
||||||
|
if(!dbf.set(3,5,&f))
|
||||||
|
error = true;
|
||||||
|
if(!dbf.setCol(0,"id",DBF_TYPE_DATA_I,10))
|
||||||
|
error = true;
|
||||||
|
if(!dbf.setCol(1,"idf",DBF_TYPE_DATA_D,10,3))
|
||||||
|
error = true;
|
||||||
|
if(!dbf.setCol(2,"str",DBF_TYPE_DATA_STR,128))
|
||||||
|
error = true;
|
||||||
|
for(int i =0; i<5; i++)
|
||||||
|
{
|
||||||
|
if(!dbf.addVal(0,i))
|
||||||
|
error = true;
|
||||||
|
if(!dbf.addVal(1,i+(i*1./10)))
|
||||||
|
error = true;
|
||||||
|
if(!dbf.addVal(2,"holaHolita"))
|
||||||
|
error = true;
|
||||||
|
if(!dbf.finRow())
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
f.cierra();
|
||||||
|
//lectura
|
||||||
|
if(!f.abre("d:\\temp\\p2.dbf",1))
|
||||||
|
error =true;
|
||||||
|
if(!dbf.lee(&f))
|
||||||
|
error = true;
|
||||||
|
idd =dbf.leeNexRow();
|
||||||
|
while(idd ==1)
|
||||||
|
{
|
||||||
|
int ii = dbf.getI(0);
|
||||||
|
double d= dbf.getD(1);
|
||||||
|
char* ss = dbf.getStr(2);
|
||||||
|
|
||||||
|
ii++;
|
||||||
|
d++;
|
||||||
|
ss[0]=0;
|
||||||
|
idd =dbf.leeNexRow();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,648 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "Fshape.h"
|
||||||
|
#include <float.h>
|
||||||
|
//**************************************************************************
|
||||||
|
int Fshape::inv_4(int *pb)
|
||||||
|
{
|
||||||
|
char (*pc)[],(*pd)[];
|
||||||
|
int j,dw;
|
||||||
|
|
||||||
|
dw = *pb;
|
||||||
|
pc = (char (*)[]) &dw;
|
||||||
|
pd = (char (*)[]) pb;
|
||||||
|
for (j=0; j<4; j++)
|
||||||
|
(*pd)[j] = (*pc)[3-j];
|
||||||
|
|
||||||
|
return(dw);
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
Fshape::Fshape(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
Fshape::~Fshape(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool Fshape::leeHead(Cb_file *file)
|
||||||
|
{
|
||||||
|
f = file;
|
||||||
|
if(!f->lee(&head, sizeof(head)))
|
||||||
|
return false;
|
||||||
|
inv_4(&head.code);
|
||||||
|
inv_4(&head.nb);
|
||||||
|
|
||||||
|
head.nb = 2 * head.nb- sizeof(head);
|
||||||
|
switch(head.tipo)
|
||||||
|
{
|
||||||
|
case(Point):
|
||||||
|
nc = 2;
|
||||||
|
ReadType = Rpoint;
|
||||||
|
break;
|
||||||
|
case(PolyLine):
|
||||||
|
nc = 2;
|
||||||
|
ReadType = RPolyLine;
|
||||||
|
break;
|
||||||
|
case(Polygon):
|
||||||
|
nc = 2;
|
||||||
|
ReadType = Rpolygon;
|
||||||
|
break;
|
||||||
|
case(MultiPoint):
|
||||||
|
nc = 2;
|
||||||
|
ReadType = RMpoint;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case(PointZ):
|
||||||
|
nc = 4;
|
||||||
|
ReadType = Rpoint;
|
||||||
|
break;
|
||||||
|
case(PolyLineZ):
|
||||||
|
nc = 4;
|
||||||
|
ReadType = RPolyLine;
|
||||||
|
break;
|
||||||
|
case(PolygonZ):
|
||||||
|
nc = 4;
|
||||||
|
ReadType = Rpolygon;
|
||||||
|
break;
|
||||||
|
case(MultiPointZ):
|
||||||
|
nc = 4;
|
||||||
|
ReadType = RMpoint;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case(PointM):
|
||||||
|
nc = 3;
|
||||||
|
ReadType = Rpoint;
|
||||||
|
break;
|
||||||
|
case(PolyLineM):
|
||||||
|
nc = 3;
|
||||||
|
ReadType = RPolyLine;
|
||||||
|
break;
|
||||||
|
case(PolygonM):
|
||||||
|
nc = 3;
|
||||||
|
ReadType = Rpolygon;
|
||||||
|
break;
|
||||||
|
case(MultiPointM):
|
||||||
|
nc = 3;
|
||||||
|
ReadType = RMpoint;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool Fshape::LeeRecord()
|
||||||
|
{
|
||||||
|
//lee cab
|
||||||
|
int nb;
|
||||||
|
if(head.nb<=0)
|
||||||
|
return false;
|
||||||
|
if(!f->lee(&headr, sizeof(headr)))
|
||||||
|
return false;
|
||||||
|
head.nb-=sizeof(headr);
|
||||||
|
inv_4(&headr.nrec);
|
||||||
|
inv_4(&headr.nb);
|
||||||
|
//tipo incluido en cabecera
|
||||||
|
headr.nb = 2 * headr.nb-sizeof(int);
|
||||||
|
//lee contenido record;
|
||||||
|
bufRecord.n = 0;
|
||||||
|
if(!(bufRecord+= headr.nb))
|
||||||
|
return false;
|
||||||
|
bufRecord.n = headr.nb;
|
||||||
|
if(!f->lee(&bufRecord[0], bufRecord.n))
|
||||||
|
return false;
|
||||||
|
head.nb-=bufRecord.n;
|
||||||
|
numPart = 0;
|
||||||
|
nb = 0;
|
||||||
|
maxC = NULL;
|
||||||
|
mimC = NULL;
|
||||||
|
mimaM = NULL;
|
||||||
|
mimaZ = NULL;
|
||||||
|
ptosM = NULL;
|
||||||
|
ptos = NULL;
|
||||||
|
ptosZ = NULL;
|
||||||
|
|
||||||
|
switch (ReadType)
|
||||||
|
{
|
||||||
|
case Rpoint:
|
||||||
|
numPart = 0;
|
||||||
|
ptos = (double*)&bufRecord[nb];//salta el tipo
|
||||||
|
tc = (bufRecord.n-nb)/sizeof(double);
|
||||||
|
npt =tc/nc;
|
||||||
|
break;
|
||||||
|
case RMpoint:
|
||||||
|
mimC = (double*)&bufRecord[nb];
|
||||||
|
nb +=2*sizeof(double);
|
||||||
|
maxC = (double*)&bufRecord[nb];
|
||||||
|
nb +=2*sizeof(double);
|
||||||
|
npt = *(int*)&bufRecord[nb];
|
||||||
|
nb += sizeof(int);
|
||||||
|
ptos = (double*)&bufRecord[nb];//salta el tipo
|
||||||
|
nb+=sizeof(double)*2*npt;
|
||||||
|
if(nc>2)
|
||||||
|
{
|
||||||
|
if(nc<4)
|
||||||
|
{
|
||||||
|
mimaM = (double*)&bufRecord[nb];
|
||||||
|
nb+=2*sizeof(double);
|
||||||
|
ptosM = (double*)&bufRecord[nb];
|
||||||
|
nb+=npt*sizeof(double);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mimaZ = (double*)&bufRecord[nb];
|
||||||
|
nb+=2*sizeof(double);
|
||||||
|
ptosZ = (double*)&bufRecord[nb];
|
||||||
|
nb+=npt*sizeof(double);
|
||||||
|
|
||||||
|
mimaM = (double*)&bufRecord[nb];
|
||||||
|
nb+=2*sizeof(double);
|
||||||
|
ptosM = (double*)&bufRecord[nb];
|
||||||
|
nb+=npt*sizeof(double);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tc = npt*2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RPolyLine:
|
||||||
|
case Rpolygon:
|
||||||
|
mimC = (double*)&bufRecord[nb];
|
||||||
|
nb +=2*sizeof(double);
|
||||||
|
maxC = (double*)&bufRecord[nb];
|
||||||
|
nb +=2*sizeof(double);
|
||||||
|
numPart = *(int*)&bufRecord[nb];
|
||||||
|
nb += sizeof(int);
|
||||||
|
npt = *(int*)&bufRecord[nb];
|
||||||
|
nb += sizeof(int);
|
||||||
|
|
||||||
|
part = (int*)&bufRecord[nb];
|
||||||
|
nb += sizeof(int)*numPart;
|
||||||
|
ptos = (double*)&bufRecord[nb];//salta el tipo
|
||||||
|
nb+=sizeof(double)*2*npt;
|
||||||
|
if(nc>2)
|
||||||
|
{
|
||||||
|
if(nc<4)
|
||||||
|
{
|
||||||
|
mimaM = (double*)&bufRecord[nb];
|
||||||
|
nb+=2*sizeof(double);
|
||||||
|
ptosM = (double*)&bufRecord[nb];
|
||||||
|
nb+=npt*sizeof(double);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mimaZ = (double*)&bufRecord[nb];
|
||||||
|
nb+=2*sizeof(double);
|
||||||
|
ptosZ = (double*)&bufRecord[nb];
|
||||||
|
nb+=npt*sizeof(double);
|
||||||
|
|
||||||
|
mimaM = (double*)&bufRecord[nb];
|
||||||
|
nb+=2*sizeof(double);
|
||||||
|
ptosM = (double*)&bufRecord[nb];
|
||||||
|
nb+=npt*sizeof(double);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tc = npt*2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
double* Fshape::get(int ip, int i)
|
||||||
|
{
|
||||||
|
if(ip>numPart)
|
||||||
|
return NULL;
|
||||||
|
int nn = part[ip]*2+i*2;
|
||||||
|
if((nn+2)>tc)
|
||||||
|
return NULL;
|
||||||
|
return &ptos[nn];
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
double* Fshape::get( int i)
|
||||||
|
{
|
||||||
|
if(i>=npt)
|
||||||
|
return NULL;
|
||||||
|
return &ptos[i*2];
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
int Fshape::getNp()
|
||||||
|
{
|
||||||
|
return numPart;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
int Fshape::getType()
|
||||||
|
{
|
||||||
|
return ReadType;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
int Fshape::getNcoord()
|
||||||
|
{
|
||||||
|
return nc;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
int Fshape::getNPt(int ip)
|
||||||
|
{
|
||||||
|
if(ip>numPart)
|
||||||
|
return -1;
|
||||||
|
if((numPart-1)>ip)
|
||||||
|
return part[ip+1]-part[ip];
|
||||||
|
return npt - part[ip];
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
int Fshape::getNPt()
|
||||||
|
{
|
||||||
|
return npt;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool Fshape::set(int type/*FshpReadType*/,int ncoord, Cb_file *file, Cb_file *file_shx)
|
||||||
|
{
|
||||||
|
f_shx = file_shx;
|
||||||
|
memset(&head,0,sizeof(head));
|
||||||
|
head.mima[0][0] = head.mima[0][1]= DBL_MAX;
|
||||||
|
head.mima[1][0] = head.mima[1][1]= -DBL_MAX;
|
||||||
|
ReadType=type;
|
||||||
|
nc = ncoord;
|
||||||
|
head.mimam[0]=head.mimam[1]=0;
|
||||||
|
head.mimaz[0]=head.mimam[1]=0;
|
||||||
|
head.ver =1000;
|
||||||
|
head.code = 9994;
|
||||||
|
//inv_4(&head.ver);
|
||||||
|
inv_4(&head.code);
|
||||||
|
head.nb = sizeof(head);
|
||||||
|
headr.nb = 0;
|
||||||
|
headr.nrec=0;
|
||||||
|
f = file;
|
||||||
|
if(nc<2 || nc>4)
|
||||||
|
return false;
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case(Rpoint):
|
||||||
|
if(nc<=2)
|
||||||
|
head.tipo = Point;
|
||||||
|
else if(nc<=3)
|
||||||
|
head.tipo = PointM;
|
||||||
|
else
|
||||||
|
head.tipo = PointZ;
|
||||||
|
break;
|
||||||
|
case(RMpoint):
|
||||||
|
if(nc<=2)
|
||||||
|
head.tipo = MultiPoint;
|
||||||
|
else if(nc<=3)
|
||||||
|
head.tipo = MultiPointM;
|
||||||
|
else
|
||||||
|
head.tipo = MultiPointZ;
|
||||||
|
break;
|
||||||
|
case(RPolyLine):
|
||||||
|
if(nc<=2)
|
||||||
|
head.tipo = PolyLine;
|
||||||
|
else if(nc<=3)
|
||||||
|
head.tipo = PolyLineM;
|
||||||
|
else
|
||||||
|
head.tipo = PolyLineZ;
|
||||||
|
break;
|
||||||
|
case(Rpolygon):
|
||||||
|
if(nc<=2)
|
||||||
|
head.tipo = Polygon;
|
||||||
|
else if(nc<=3)
|
||||||
|
head.tipo = PolygonM;
|
||||||
|
else
|
||||||
|
head.tipo = PolygonZ;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
headr.tipo = head.tipo;
|
||||||
|
if(f_shx && !f_shx->escribe(&head, sizeof(head)))
|
||||||
|
return false;
|
||||||
|
return (f->escribe(&head, sizeof(head))==TRUE);
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool Fshape::grabaRecord(Cgarray<double> *pts)
|
||||||
|
{
|
||||||
|
int aux;
|
||||||
|
npt = pts->n/nc;
|
||||||
|
if(npt<=0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
double mimaxr[2][2];
|
||||||
|
mimaxr[0][0] = mimaxr[0][1]= DBL_MAX;
|
||||||
|
mimaxr[1][0] = mimaxr[1][1]= -DBL_MAX;
|
||||||
|
double mimaxZ[2];
|
||||||
|
double mimaxM[2];
|
||||||
|
mimaxZ[0] = mimaxM[0]= DBL_MAX;
|
||||||
|
mimaxZ[1] = mimaxM[1]= -DBL_MAX;
|
||||||
|
ptosM = NULL;
|
||||||
|
ptosZ = NULL;
|
||||||
|
int ii = 0;
|
||||||
|
switch(ReadType)
|
||||||
|
{
|
||||||
|
case(Rpoint):
|
||||||
|
{
|
||||||
|
headr.nb =sizeof(int)+sizeof(double)*nc;
|
||||||
|
headr.nb = headr.nb/2;
|
||||||
|
inv_4(&headr.nb);
|
||||||
|
for(int i=0; i<npt; i++)
|
||||||
|
{
|
||||||
|
headr.nrec++;
|
||||||
|
inv_4(&headr.nrec);
|
||||||
|
if(!f->escribe(&headr, sizeof(headr)))
|
||||||
|
return false;
|
||||||
|
inv_4(&headr.nrec);
|
||||||
|
aux = head.nb/2;
|
||||||
|
inv_4(&aux);
|
||||||
|
if(f_shx && !f_shx->escribe(&aux, sizeof(aux)))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(headr);
|
||||||
|
//graba offset
|
||||||
|
aux = headr.nb;
|
||||||
|
inv_4(&aux);
|
||||||
|
if(f_shx && !f_shx->escribe(&aux, sizeof(aux)))
|
||||||
|
return false;
|
||||||
|
ii = i*nc;
|
||||||
|
ptos = &(*pts)[ii];
|
||||||
|
//pilla minimo y maximo
|
||||||
|
if(mimaxr[0][0]>ptos[0])
|
||||||
|
mimaxr[0][0]=ptos[0];
|
||||||
|
if(mimaxr[0][1]>ptos[1])
|
||||||
|
mimaxr[0][1]=ptos[1];
|
||||||
|
if(mimaxr[1][0]<ptos[0])
|
||||||
|
mimaxr[1][0]=ptos[0];
|
||||||
|
if(mimaxr[1][1]<ptos[1])
|
||||||
|
mimaxr[1][1]=ptos[1];
|
||||||
|
if(!f->escribe(ptos, sizeof(double)*nc))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*nc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case(RMpoint):
|
||||||
|
{
|
||||||
|
headr.nb = sizeof(double)*nc*npt+sizeof(int);
|
||||||
|
headr.nb = inv_4(&headr.nb);
|
||||||
|
headr.nrec++;
|
||||||
|
headr.nrec=inv_4(&headr.nrec);
|
||||||
|
if(!f->escribe(&headr, sizeof(headr)))
|
||||||
|
return false;
|
||||||
|
headr.nrec=inv_4(&headr.nrec);
|
||||||
|
|
||||||
|
aux = head.nb/2;
|
||||||
|
inv_4(&aux);
|
||||||
|
if(f_shx && !f_shx->escribe(&aux, sizeof(aux)))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(headr);
|
||||||
|
//graba offset
|
||||||
|
aux = headr.nb;
|
||||||
|
inv_4(&aux);
|
||||||
|
if(f_shx && !f_shx->escribe(&aux, sizeof(aux)))
|
||||||
|
return false;
|
||||||
|
if(nc>3)
|
||||||
|
{
|
||||||
|
ptosZ = &(*pts)[npt*3];
|
||||||
|
ptosM = &(*pts)[npt*3];
|
||||||
|
}
|
||||||
|
else if(nc>2)
|
||||||
|
{
|
||||||
|
ptosM = &(*pts)[npt*2];
|
||||||
|
//mimam
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<npt; i++)
|
||||||
|
{
|
||||||
|
ii = i*2;
|
||||||
|
ptos = &(*pts)[ii];
|
||||||
|
//pilla minimo y maximo
|
||||||
|
if(mimaxr[0][0]>ptos[0])
|
||||||
|
mimaxr[0][0]=ptos[0];
|
||||||
|
if(mimaxr[0][1]>ptos[1])
|
||||||
|
mimaxr[0][1]=ptos[1];
|
||||||
|
if(mimaxr[1][0]<ptos[0])
|
||||||
|
mimaxr[1][0]=ptos[0];
|
||||||
|
if(mimaxr[1][1]<ptos[1])
|
||||||
|
mimaxr[1][1]=ptos[1];
|
||||||
|
if(ptosM)
|
||||||
|
{
|
||||||
|
if(mimaxM[0]>ptosM[i])
|
||||||
|
mimaxM[0]=ptosM[i];
|
||||||
|
if(mimaxM[1]<ptosM[i])
|
||||||
|
mimaxM[1]=ptosM[i];
|
||||||
|
}
|
||||||
|
if(ptosZ)
|
||||||
|
{
|
||||||
|
if(mimaxZ[0]>ptosZ[i])
|
||||||
|
mimaxZ[0]=ptosZ[i];
|
||||||
|
if(mimaxZ[1]<ptosZ[i])
|
||||||
|
mimaxZ[1]=ptosZ[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!f->escribe(mimaxr, sizeof(double)*4))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*4;
|
||||||
|
|
||||||
|
if(!f->escribe(&npt, sizeof(npt)))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(npt);
|
||||||
|
if(!f->escribe(&(*pts)[0], sizeof(double)*nc*npt))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*2*npt;
|
||||||
|
if(ptosZ)
|
||||||
|
{
|
||||||
|
if(!f->escribe(mimaxZ, sizeof(double)*2))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*2;
|
||||||
|
if(!f->escribe(ptosZ, sizeof(double)*npt))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*npt;
|
||||||
|
}
|
||||||
|
if(ptosM)
|
||||||
|
{
|
||||||
|
if(!f->escribe(mimaxM, sizeof(double)*2))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*2;
|
||||||
|
if(!f->escribe(ptosM, sizeof(double)*npt))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*npt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//pilla coordenadas maximas y minimas totales del shp
|
||||||
|
if(head.mima[0][0]>mimaxr[0][0])
|
||||||
|
head.mima[0][0]=mimaxr[0][0];
|
||||||
|
if(head.mima[0][1]>mimaxr[0][1])
|
||||||
|
head.mima[0][1]=mimaxr[0][1];
|
||||||
|
if(head.mima[1][0]<mimaxr[1][0])
|
||||||
|
head.mima[1][0]=mimaxr[1][0];
|
||||||
|
if(head.mima[1][1]<mimaxr[1][1])
|
||||||
|
head.mima[1][1]=mimaxr[1][1];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool Fshape::grabaRecord(Cgarray<double> *pts, Cgarray<int>*parts)
|
||||||
|
{
|
||||||
|
int aux;
|
||||||
|
npt = pts->n/nc;
|
||||||
|
if(npt<=0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
double mimaxr[2][2];
|
||||||
|
mimaxr[0][0] = mimaxr[0][1]= DBL_MAX;
|
||||||
|
mimaxr[1][0] = mimaxr[1][1]= -DBL_MAX;
|
||||||
|
|
||||||
|
double mimaxZ[2];
|
||||||
|
double mimaxM[2];
|
||||||
|
mimaxZ[0] = mimaxM[0]= DBL_MAX;
|
||||||
|
mimaxZ[1] = mimaxM[1]= -DBL_MAX;
|
||||||
|
ptosM = NULL;
|
||||||
|
ptosZ = NULL;
|
||||||
|
headr.tipo = head.tipo;
|
||||||
|
int ii = 0;
|
||||||
|
switch(ReadType)
|
||||||
|
{
|
||||||
|
case(RPolyLine):
|
||||||
|
case(Rpolygon):
|
||||||
|
{
|
||||||
|
headr.nrec++;
|
||||||
|
inv_4(&headr.nrec);
|
||||||
|
|
||||||
|
headr.nb = sizeof(int)+sizeof(double)*4+2*sizeof(int)+
|
||||||
|
+sizeof(int)*parts->n+sizeof(double)*2*npt;
|
||||||
|
if(nc>3)
|
||||||
|
{
|
||||||
|
ptosZ = &(*pts)[npt*3];
|
||||||
|
ptosM = &(*pts)[npt*3];
|
||||||
|
headr.nb+=2*(sizeof(double)*2+sizeof(double)*npt);
|
||||||
|
}
|
||||||
|
else if(nc>2)
|
||||||
|
{
|
||||||
|
headr.tipo = PolyLineZ;
|
||||||
|
ptosM = &(*pts)[npt*2];
|
||||||
|
headr.nb+=sizeof(double)*2+sizeof(double)*npt;
|
||||||
|
//mimam
|
||||||
|
}
|
||||||
|
headr.nb = headr.nb/2;
|
||||||
|
inv_4(&headr.nb);
|
||||||
|
if(!f->escribe(&headr, sizeof(headr)))
|
||||||
|
return false;
|
||||||
|
inv_4(&headr.nrec);
|
||||||
|
inv_4(&headr.nb);
|
||||||
|
aux = head.nb/2;
|
||||||
|
inv_4(&aux);
|
||||||
|
if(f_shx && !f_shx->escribe(&aux, sizeof(aux)))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(headr);
|
||||||
|
//graba offset
|
||||||
|
aux = headr.nb;
|
||||||
|
inv_4(&aux);
|
||||||
|
if(f_shx && !f_shx->escribe(&aux, sizeof(aux)))
|
||||||
|
return false;
|
||||||
|
for(int i=0; i<npt; i++)
|
||||||
|
{
|
||||||
|
ii = i*nc;
|
||||||
|
ptos = &(*pts)[ii];
|
||||||
|
//pilla minimo y maximo
|
||||||
|
if(mimaxr[0][0]>ptos[0])
|
||||||
|
mimaxr[0][0]=ptos[0];
|
||||||
|
if(mimaxr[0][1]>ptos[1])
|
||||||
|
mimaxr[0][1]=ptos[1];
|
||||||
|
if(mimaxr[1][0]<ptos[0])
|
||||||
|
mimaxr[1][0]=ptos[0];
|
||||||
|
if(mimaxr[1][1]<ptos[1])
|
||||||
|
mimaxr[1][1]=ptos[1];
|
||||||
|
if(ptosM)
|
||||||
|
{
|
||||||
|
if(mimaxM[0]>ptosM[i])
|
||||||
|
mimaxM[0]=ptosM[i];
|
||||||
|
if(mimaxM[1]<ptosM[i])
|
||||||
|
mimaxM[1]=ptosM[i];
|
||||||
|
}
|
||||||
|
if(ptosZ)
|
||||||
|
{
|
||||||
|
if(mimaxZ[0]>ptosZ[i])
|
||||||
|
mimaxZ[0] = ptosZ[i];
|
||||||
|
if(mimaxZ[1]<ptosZ[i])
|
||||||
|
mimaxZ[1]=ptosZ[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!f->escribe(mimaxr, sizeof(double)*4))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*4;
|
||||||
|
if(!f->escribe(&parts->n, sizeof(parts->n)))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(parts->n);
|
||||||
|
if(!f->escribe(&npt, sizeof(npt)))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(npt);
|
||||||
|
if(!f->escribe(&(*parts)[0], sizeof(int)*parts->n))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(int)*parts->n;
|
||||||
|
|
||||||
|
if(!f->escribe(&(*pts)[0], sizeof(double)*2*npt))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*2*npt;
|
||||||
|
if(ptosZ)
|
||||||
|
{
|
||||||
|
if(!f->escribe(mimaxZ, sizeof(double)*2))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*2;
|
||||||
|
if(!f->escribe(ptosZ, sizeof(double)*npt))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*npt;
|
||||||
|
}
|
||||||
|
if(ptosM)
|
||||||
|
{
|
||||||
|
if(!f->escribe(mimaxM, sizeof(double)*2))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*2;
|
||||||
|
if(!f->escribe(ptosM, sizeof(double)*npt))
|
||||||
|
return false;
|
||||||
|
head.nb+=sizeof(double)*npt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//pilla coordenadas maximas y minimas totales del shp
|
||||||
|
if(head.mima[0][0]>mimaxr[0][0])
|
||||||
|
head.mima[0][0]=mimaxr[0][0];
|
||||||
|
if(head.mima[0][1]>mimaxr[0][1])
|
||||||
|
head.mima[0][1]=mimaxr[0][1];
|
||||||
|
if(head.mima[1][0]<mimaxr[1][0])
|
||||||
|
head.mima[1][0]=mimaxr[1][0];
|
||||||
|
if(head.mima[1][1]<mimaxr[1][1])
|
||||||
|
head.mima[1][1]=mimaxr[1][1];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
bool Fshape::FinGraba()
|
||||||
|
{
|
||||||
|
if(!f->irAini())
|
||||||
|
return false;
|
||||||
|
if(f_shx && !f_shx->irAini())
|
||||||
|
return false;
|
||||||
|
head.nb = head.nb/2;
|
||||||
|
inv_4(&head.nb);
|
||||||
|
head.ver =1000;
|
||||||
|
head.code =9994;
|
||||||
|
inv_4(&head.code);
|
||||||
|
|
||||||
|
if(!f->escribe(&head, sizeof(head)))
|
||||||
|
return false;
|
||||||
|
int auxi = head.nb;
|
||||||
|
head.nb = 100+headr.nrec*2*sizeof(int);
|
||||||
|
head.nb = head.nb/2;
|
||||||
|
inv_4(&head.nb);
|
||||||
|
if(f_shx && !f_shx->escribe(&head, sizeof(head)))
|
||||||
|
return false;
|
||||||
|
if(f_shx && !f_shx->irAfin())
|
||||||
|
return false;
|
||||||
|
return (f->irAfin()== TRUE);
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
|
@ -0,0 +1,106 @@
|
||||||
|
#pragma once
|
||||||
|
//clase para leer grabar shp
|
||||||
|
#ifndef Fshape_h
|
||||||
|
#define Fshape_h
|
||||||
|
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "garray.h"
|
||||||
|
#include "b_file.h"
|
||||||
|
#pragma pack(4)
|
||||||
|
typedef struct ShpHead
|
||||||
|
{
|
||||||
|
int code;
|
||||||
|
int res[5];
|
||||||
|
int nb; // tamaño en bytes del archivo
|
||||||
|
int ver;
|
||||||
|
int tipo;
|
||||||
|
double mima[2][2];
|
||||||
|
double mimaz[2];
|
||||||
|
double mimam[2];
|
||||||
|
} ShpHead;
|
||||||
|
typedef struct ShpHeadReg
|
||||||
|
{
|
||||||
|
int nrec; // nº del recor empezando en cero (en el file empiezan en 1)
|
||||||
|
int nb; // tamaño en bytes del record
|
||||||
|
int tipo;
|
||||||
|
} Shp_reg;
|
||||||
|
|
||||||
|
#pragma pack(8)
|
||||||
|
|
||||||
|
class UTILES_EXPORT Fshape
|
||||||
|
{
|
||||||
|
Cgarray<char> bufRecord;
|
||||||
|
//datos de archivo
|
||||||
|
ShpHead head;
|
||||||
|
ShpHeadReg headr;
|
||||||
|
double* mimC; //coordenadas mima
|
||||||
|
double* maxC; //coordenadas mima
|
||||||
|
double* mimaM; //coordenadas mima
|
||||||
|
double* mimaZ; //coordenadas mima
|
||||||
|
|
||||||
|
double* ptos; //coordenadas de los puntos
|
||||||
|
double* ptosM; //coordenadas de los puntos
|
||||||
|
double* ptosZ; //coordenadas de los puntos
|
||||||
|
|
||||||
|
|
||||||
|
int ReadType;
|
||||||
|
int offserW;
|
||||||
|
int nc; // número de coordenadas que tiene cada punto
|
||||||
|
int npt;//numero total de puntos
|
||||||
|
int tc;//total de coordenadas de todos los puntos sumados
|
||||||
|
int *part;//partes del record
|
||||||
|
int numPart;//numero de partes
|
||||||
|
Cb_file *f;//puntero a archivo
|
||||||
|
Cb_file *f_shx;//puntero a archivo
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum FShapeType
|
||||||
|
{
|
||||||
|
NullShape=0,
|
||||||
|
Point=1,
|
||||||
|
PolyLine=3,
|
||||||
|
Polygon=5,
|
||||||
|
MultiPoint=8,
|
||||||
|
PointZ=11,
|
||||||
|
PolyLineZ=13,
|
||||||
|
PolygonZ=15,
|
||||||
|
MultiPointZ=18,
|
||||||
|
PointM=21,
|
||||||
|
PolyLineM=23,
|
||||||
|
PolygonM=25,
|
||||||
|
MultiPointM=28,
|
||||||
|
MultiPatch=31,
|
||||||
|
};
|
||||||
|
enum FshpReadType
|
||||||
|
{
|
||||||
|
Rpoint=0,
|
||||||
|
RMpoint,
|
||||||
|
RPolyLine,
|
||||||
|
Rpolygon,
|
||||||
|
};
|
||||||
|
|
||||||
|
Fshape(void);
|
||||||
|
~Fshape(void);
|
||||||
|
|
||||||
|
//funciones de lectura--------------------------------
|
||||||
|
bool leeHead(Cb_file *file);
|
||||||
|
bool LeeRecord();
|
||||||
|
double* get(int i);//devuelve el punto i esimo de la parte ip
|
||||||
|
double* get(int ip, int i);//devuelve el punto i esimo de la parte ip
|
||||||
|
int getNp();//devuelve el total de partes
|
||||||
|
int getNPt(int ip);//devuelve el total de puntos de la parte ip
|
||||||
|
int getNPt();//devuelve el total de puntos de la parte ip
|
||||||
|
int getType();//devuelve tipo de objetos almacenados
|
||||||
|
int getNcoord();//devuelve numero de coordenadas por punto
|
||||||
|
//funciones de escritura-------------------------------
|
||||||
|
|
||||||
|
bool set(int tipe/*FshpReadType*/,int ncoord, Cb_file *file,Cb_file *file_shx =0);
|
||||||
|
bool grabaRecord(Cgarray<double> *pts);
|
||||||
|
bool grabaRecord(Cgarray<double> *pts, Cgarray<int> *parts);
|
||||||
|
bool FinGraba();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
int inv_4(int *pb);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,457 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "GdataTable.h"
|
||||||
|
//***************************************************************************
|
||||||
|
GdataTable::GdataTable(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
GdataTable::~GdataTable(void)
|
||||||
|
{
|
||||||
|
delAll();
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
int* GdataTable::getI(int row, int col)
|
||||||
|
{
|
||||||
|
if(col>=colm.n || col<0)
|
||||||
|
return NULL;
|
||||||
|
if(colm[col].type !=Tint)
|
||||||
|
return NULL;
|
||||||
|
return &(*(Cgarray<int>*)buf[col])[row];
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
__int64* GdataTable::getI64(int row, int col)
|
||||||
|
{
|
||||||
|
if(col>=colm.n || col<0)
|
||||||
|
return NULL;
|
||||||
|
if(colm[col].type !=Tint64)
|
||||||
|
return NULL;
|
||||||
|
return &(*(Cgarray<__int64>*)buf[col])[row];
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
double* GdataTable::getD(int row, int col)
|
||||||
|
{
|
||||||
|
if(col>=colm.n || col<0)
|
||||||
|
return NULL;
|
||||||
|
if(colm[col].type !=Tdouble)
|
||||||
|
return NULL;
|
||||||
|
return &(*(Cgarray<double>*)buf[col])[row];
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool* GdataTable::getBool(int row, int col)
|
||||||
|
{
|
||||||
|
if(col>=colm.n || col<0)
|
||||||
|
return NULL;
|
||||||
|
if(colm[col].type !=Tbool)
|
||||||
|
return NULL;
|
||||||
|
return &(*(Cgarray<bool>*)buf[col])[row];
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
char* GdataTable::getS(int row, int col)
|
||||||
|
{
|
||||||
|
if(col>=colm.n || col<0)
|
||||||
|
return NULL;
|
||||||
|
if(colm[col].type !=Tstring)
|
||||||
|
return NULL;
|
||||||
|
return &(*(Cgarray<char>*)buf[col])[row*colm[col].nb];
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void* GdataTable::getBin(int row, int col)
|
||||||
|
{
|
||||||
|
if(col>=colm.n || col<0)
|
||||||
|
return NULL;
|
||||||
|
if(colm[col].type !=Tbin)
|
||||||
|
return NULL;
|
||||||
|
return (void*)&(*(Cgarray<char>*)buf[col])[row*colm[col].nb];
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void* GdataTable::get(int row, int col)
|
||||||
|
{
|
||||||
|
if(col>=colm.n || col<0)
|
||||||
|
return NULL;
|
||||||
|
switch(colm[col].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
return(void*)&(*(Cgarray<bool>*)buf[col])[row];
|
||||||
|
case(Tint):
|
||||||
|
return(void*)&(*(Cgarray<int>*)buf[col])[row];
|
||||||
|
case(Tdouble):
|
||||||
|
return(void*)&(*(Cgarray<double>*)buf[col])[row];
|
||||||
|
case(Tint64):
|
||||||
|
return(void*)&(*(Cgarray<__int64>*)buf[col])[row];
|
||||||
|
case(Tstring):
|
||||||
|
case(Tbin):
|
||||||
|
return(void*)&(*(Cgarray<char>*)buf[col])[row*colm[col].nb];
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool GdataTable::addColm(char* name, int type, int size)
|
||||||
|
{
|
||||||
|
colmName.add(name);
|
||||||
|
GdataTableColum inf;
|
||||||
|
void* c = NULL;
|
||||||
|
inf.flags=0;
|
||||||
|
inf.nb=size;
|
||||||
|
inf.type=type;
|
||||||
|
int nn =nRow();
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
c = new Cgarray<bool>();
|
||||||
|
if(!inf.nb)
|
||||||
|
inf.nb = sizeof(bool);
|
||||||
|
if(nn>0)
|
||||||
|
{
|
||||||
|
if(!((*(Cgarray<bool>*)c)+=nn))
|
||||||
|
return false;
|
||||||
|
((Cgarray<bool>*)c)->n = nn;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case(Tint):
|
||||||
|
c = new Cgarray<int>();
|
||||||
|
if(!inf.nb)
|
||||||
|
inf.nb = sizeof(long);
|
||||||
|
if(nn>0)
|
||||||
|
{
|
||||||
|
if(!((*(Cgarray<int>*)c)+=nn))
|
||||||
|
return false;
|
||||||
|
((Cgarray<int>*)c)->n = nn;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case(Tdouble):
|
||||||
|
c = new Cgarray<double>();
|
||||||
|
if(!inf.nb)
|
||||||
|
inf.nb = sizeof(double);
|
||||||
|
if(nn>0)
|
||||||
|
{
|
||||||
|
if(!((*(Cgarray<double>*)c)+=nn))
|
||||||
|
return false;
|
||||||
|
((Cgarray<double>*)c)->n = nn;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case(Tint64):
|
||||||
|
c = new Cgarray<__int64>();
|
||||||
|
if(!inf.nb)
|
||||||
|
inf.nb = sizeof(__int64);
|
||||||
|
if(nn>0)
|
||||||
|
{
|
||||||
|
if(!((*(Cgarray<__int64>*)c)+=nn))
|
||||||
|
return false;
|
||||||
|
((Cgarray<__int64>*)c)->n = nn;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case(Tstring):
|
||||||
|
case(Tbin):
|
||||||
|
c = new Cgarray<char>();
|
||||||
|
if(nn>0)
|
||||||
|
{
|
||||||
|
if(!((*(Cgarray<char>*)c)+=(nn*inf.nb)))
|
||||||
|
return false;
|
||||||
|
((Cgarray<char>*)c)->n = (nn*inf.nb);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!c)
|
||||||
|
return false;
|
||||||
|
if(!(buf+c))
|
||||||
|
return false;
|
||||||
|
if(!(colm+inf))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void GdataTable::delAll()
|
||||||
|
{
|
||||||
|
for(int i =0; i<buf.n; i++)
|
||||||
|
{
|
||||||
|
switch(colm[i].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
delete (Cgarray<bool>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tint):
|
||||||
|
delete (Cgarray<int>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tdouble):
|
||||||
|
delete (Cgarray<double>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tint64):
|
||||||
|
delete (Cgarray<__int64>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tstring):
|
||||||
|
delete (Cgarray<char>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tbin):
|
||||||
|
delete (Cgarray<char>*)buf[i];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
colm.n =0;
|
||||||
|
buf.n =0;
|
||||||
|
colmName.n_i =0;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void GdataTable::delAllRow()
|
||||||
|
{
|
||||||
|
for(int i =0; i<buf.n; i++)
|
||||||
|
{
|
||||||
|
switch(colm[i].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
((Cgarray<bool>*)buf[i])->n=0;
|
||||||
|
break;
|
||||||
|
case(Tint):
|
||||||
|
((Cgarray<int>*)buf[i])->n=0;
|
||||||
|
break;
|
||||||
|
case(Tdouble):
|
||||||
|
((Cgarray<double>*)buf[i])->n=0;
|
||||||
|
break;
|
||||||
|
case(Tint64):
|
||||||
|
((Cgarray<__int64>*)buf[i])->n=0;
|
||||||
|
break;
|
||||||
|
case(Tstring):
|
||||||
|
((Cgarray<char>*)buf[i])->n=0;
|
||||||
|
break;
|
||||||
|
case(Tbin):
|
||||||
|
((Cgarray<char>*)buf[i])->n=0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void GdataTable::removeColm(int i)
|
||||||
|
{
|
||||||
|
switch(colm[i].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
delete (Cgarray<bool>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tint):
|
||||||
|
delete (Cgarray<int>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tdouble):
|
||||||
|
delete (Cgarray<double>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tint64):
|
||||||
|
delete (Cgarray<__int64>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tstring):
|
||||||
|
delete (Cgarray<char>*)buf[i];
|
||||||
|
break;
|
||||||
|
case(Tbin):
|
||||||
|
delete (Cgarray<char>*)buf[i];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
int GdataTable::nRow()
|
||||||
|
{
|
||||||
|
int i =0;
|
||||||
|
if(colm.n<=0)
|
||||||
|
return 0;
|
||||||
|
switch(colm[i].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
return((Cgarray<bool>*)buf[i])->n;
|
||||||
|
case(Tint):
|
||||||
|
return((Cgarray<int>*)buf[i])->n;
|
||||||
|
case(Tdouble):
|
||||||
|
return((Cgarray<double>*)buf[i])->n;
|
||||||
|
case(Tint64):
|
||||||
|
return((Cgarray<__int64>*)buf[i])->n;
|
||||||
|
case(Tstring):
|
||||||
|
return((Cgarray<char>*)buf[i])->n;
|
||||||
|
case(Tbin):
|
||||||
|
return((Cgarray<char>*)buf[i])->n;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
int GdataTable::getType(int icol)
|
||||||
|
{
|
||||||
|
if(icol<0 || icol>= colm.n)
|
||||||
|
return Tndef;
|
||||||
|
return colm[icol].type;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
int GdataTable::getInd(char* colName)
|
||||||
|
{
|
||||||
|
for(int i =0; i<colm.n; i++)
|
||||||
|
{
|
||||||
|
if(!strcmp(colName,colmName.get(i)))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool GdataTable::addRow(int nrow)
|
||||||
|
{
|
||||||
|
for(int i =0; i<buf.n; i++)
|
||||||
|
{
|
||||||
|
switch(colm[i].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
if(!((*(Cgarray<bool>*)buf[i])+=nrow))
|
||||||
|
return false;
|
||||||
|
(*(Cgarray<bool>*)buf[i]).n+=nrow;
|
||||||
|
break;
|
||||||
|
case(Tint):
|
||||||
|
if(!((*(Cgarray<int>*)buf[i])+=nrow))
|
||||||
|
return false;
|
||||||
|
(*(Cgarray<int>*)buf[i]).n+=nrow;
|
||||||
|
break;
|
||||||
|
case(Tdouble):
|
||||||
|
if(!((*(Cgarray<double>*)buf[i])+=nrow))
|
||||||
|
return false;
|
||||||
|
(*(Cgarray<double>*)buf[i]).n+=nrow;
|
||||||
|
break;
|
||||||
|
case(Tint64):
|
||||||
|
if(!((*(Cgarray<__int64>*)buf[i])+=nrow))
|
||||||
|
return false;
|
||||||
|
(*(Cgarray<__int64>*)buf[i]).n+=nrow;
|
||||||
|
break;
|
||||||
|
case(Tstring):
|
||||||
|
if(!((*(Cgarray<char>*)buf[i])+=(nrow*colm[i].nb)))
|
||||||
|
return false;
|
||||||
|
(*(Cgarray<char>*)buf[i]).n+=(nrow*colm[i].nb);
|
||||||
|
break;
|
||||||
|
case(Tbin):
|
||||||
|
if(!((*(Cgarray<char>*)buf[i])+=(nrow*colm[i].nb)))
|
||||||
|
return false;
|
||||||
|
(*(Cgarray<char>*)buf[i]).n+=(nrow*colm[i].nb);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void GdataTable::removeRow(int i)
|
||||||
|
{
|
||||||
|
for(int i =0; i<buf.n; i++)
|
||||||
|
{
|
||||||
|
switch(colm[i].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
(*(Cgarray<bool>*)buf[i]).remove(i);
|
||||||
|
break;
|
||||||
|
case(Tint):
|
||||||
|
(*(Cgarray<int>*)buf[i]).remove(i);
|
||||||
|
break;
|
||||||
|
case(Tdouble):
|
||||||
|
(*(Cgarray<double>*)buf[i]).remove(i);
|
||||||
|
break;
|
||||||
|
case(Tint64):
|
||||||
|
(*(Cgarray<__int64>*)buf[i]).remove(i);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case(Tstring):
|
||||||
|
(*(Cgarray<char>*)buf[i]).remove(i, colm[i].nb);
|
||||||
|
break;
|
||||||
|
case(Tbin):
|
||||||
|
(*(Cgarray<char>*)buf[i]).remove(i, colm[i].nb);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
int GdataTable::nColm()
|
||||||
|
{
|
||||||
|
return colm.n;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
int GdataTable::getSize( int icol )
|
||||||
|
{
|
||||||
|
if(icol<0 || icol>colm.n)
|
||||||
|
return -1;
|
||||||
|
return colm[icol].nb;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
char* GdataTable::getName( int icol )
|
||||||
|
{
|
||||||
|
if(icol<0 || icol>colm.n)
|
||||||
|
return 0;
|
||||||
|
return colmName.get(icol);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool GdataTable::addMemRow( int nrow )
|
||||||
|
{
|
||||||
|
for(int i =0; i<buf.n; i++)
|
||||||
|
{
|
||||||
|
switch(colm[i].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
if(!((*(Cgarray<bool>*)buf[i])+=nrow))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case(Tint):
|
||||||
|
if(!((*(Cgarray<int>*)buf[i])+=nrow))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case(Tdouble):
|
||||||
|
if(!((*(Cgarray<double>*)buf[i])+=nrow))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case(Tint64):
|
||||||
|
if(!((*(Cgarray<__int64>*)buf[i])+=nrow))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case(Tstring):
|
||||||
|
if(!((*(Cgarray<char>*)buf[i])+=(nrow*colm[i].nb)))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case(Tbin):
|
||||||
|
if(!((*(Cgarray<char>*)buf[i])+=(nrow*colm[i].nb)))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
int GdataTable::getSizeASCII( int icol )
|
||||||
|
{
|
||||||
|
if(!colm[icol].nb)
|
||||||
|
{
|
||||||
|
switch(colm[icol].type)
|
||||||
|
{
|
||||||
|
case(Tbool):
|
||||||
|
return 1;
|
||||||
|
case(Tint):
|
||||||
|
return 4;
|
||||||
|
case(Tdouble):
|
||||||
|
return 8;
|
||||||
|
case(Tint64):
|
||||||
|
return 8;
|
||||||
|
case(Tbin):
|
||||||
|
case(Tstring):
|
||||||
|
return colm[icol].nb;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return colm[icol].nb;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef GdataTable_h
|
||||||
|
#define GdataTable_h
|
||||||
|
//tabla de datos generica
|
||||||
|
//tabla con nombre de columnas
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "garray.h"
|
||||||
|
#include "StrArray.h"
|
||||||
|
class UTILES_EXPORT GdataTableColum
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int type;//tipo de dato
|
||||||
|
int nb;//numero de bytes de informacion
|
||||||
|
int flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UTILES_EXPORT GdataTable
|
||||||
|
{
|
||||||
|
Cgarray<void*>buf; //array de Garray de datos
|
||||||
|
Cgarray<GdataTableColum>colm; //datos de columnas
|
||||||
|
StrArray colmName; //nombre de columnas
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum TypedataTable
|
||||||
|
{
|
||||||
|
Tndef=0,
|
||||||
|
Tbool,
|
||||||
|
Tint,
|
||||||
|
Tdouble,
|
||||||
|
Tint64,
|
||||||
|
Tstring,
|
||||||
|
Tbin,
|
||||||
|
Tntip
|
||||||
|
};
|
||||||
|
GdataTable(void);
|
||||||
|
~GdataTable(void);
|
||||||
|
|
||||||
|
//funciones de lectura y set------------
|
||||||
|
int getType(int icol);
|
||||||
|
int getInd(char* colName);
|
||||||
|
int nRow();
|
||||||
|
int nColm();
|
||||||
|
int getSize(int icol);
|
||||||
|
int getSizeASCII(int icol);
|
||||||
|
|
||||||
|
char* getName(int icol);
|
||||||
|
int* getI(int row, int colm);
|
||||||
|
__int64* getI64(int row, int colm);
|
||||||
|
double* getD(int row, int colm);
|
||||||
|
char* getS(int row, int colm);
|
||||||
|
void* getBin(int row, int colm);
|
||||||
|
bool* getBool(int row, int col);
|
||||||
|
|
||||||
|
void* get(int row, int colm);
|
||||||
|
//funciones de modificacion-------------
|
||||||
|
|
||||||
|
//adicionar-----------------------------
|
||||||
|
bool addColm(char* name, int type, int size=0);
|
||||||
|
bool addRow(int nrow);
|
||||||
|
bool addMemRow(int nrow);
|
||||||
|
//borrado-------------------------------
|
||||||
|
void delAllRow();//borra todas las filas
|
||||||
|
void delAll();//borra todo
|
||||||
|
|
||||||
|
void removeRow(int i);
|
||||||
|
void removeColm(int i);
|
||||||
|
|
||||||
|
//ajusta memoria
|
||||||
|
void clear();
|
||||||
|
//funciones auxiliares--------------------
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,609 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "GeometryFunction.h"
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::Dist2d(double*p1, double*p2)
|
||||||
|
{
|
||||||
|
return sqrt(Poten(p1[0]-p2[0])+Poten(p1[1]-p2[1]));
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::LongLine2d(SetPtsR *line)
|
||||||
|
{
|
||||||
|
int nn = line->getNumberPtos();
|
||||||
|
double res =0;
|
||||||
|
double *p1,*p2;
|
||||||
|
if(nn<2)
|
||||||
|
return res;
|
||||||
|
p1 = line->getPto(0);
|
||||||
|
for(int i =1; i<nn; i++)
|
||||||
|
{
|
||||||
|
p2 = line->getPto(i);
|
||||||
|
res+=Dist2d(p1,p2);
|
||||||
|
p1=p2;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
void GeometryFunction::CompMima(double dst[2][3], SetPtsR* pts)
|
||||||
|
{
|
||||||
|
dst[0][0] = dst[0][1]= DBL_MAX;
|
||||||
|
dst[1][0] = dst[1][1]= -DBL_MAX;
|
||||||
|
for( int i = pts->getNumberPtos()-1; i>0; i--)
|
||||||
|
{
|
||||||
|
double *p = pts->getPto(i);
|
||||||
|
if(dst[0][0]>p[0])
|
||||||
|
dst[0][0]=p[0];
|
||||||
|
if(dst[0][1]>p[1])
|
||||||
|
dst[0][1]=p[1];
|
||||||
|
if(dst[1][0]<p[0])
|
||||||
|
dst[1][0]=p[0];
|
||||||
|
if(dst[1][1]<p[1])
|
||||||
|
dst[1][1]=p[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
//calcula envoltura convexa
|
||||||
|
Cgarray<double[3]>* GeometryFunction::EnvConvex(SetPtsR* pts, Cgarray<double[3]>* dst)
|
||||||
|
{
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::Dpline(double* l1, double *l2, double *p, double *lamb)
|
||||||
|
{
|
||||||
|
double aux = Poten( l2[0] - l1[0] )
|
||||||
|
+ Poten( l2[1] - l1[1] );
|
||||||
|
if ( aux < 1.e-20 )
|
||||||
|
aux = 0.;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
aux = ((l2[0] - l1[0] ) * ( p[0] - l1[0] ) + ( l2[1] - l1[1] ) * ( p[1] - l1[1]))/ aux;
|
||||||
|
}
|
||||||
|
if(lamb)
|
||||||
|
*lamb = aux;
|
||||||
|
return sqrt( Poten(p[0]-l1[0]-aux*(l2[0]-l1[0]))+
|
||||||
|
Poten(p[1] - l1[1] - aux * (l2[1] - l1[1])));
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::DpSeg(double* s1, double *s2, double *p, double *lamb)
|
||||||
|
{
|
||||||
|
double aux;
|
||||||
|
double dis=Dpline(s1,s2,p,&aux);
|
||||||
|
if(aux<0)//distancia en s1
|
||||||
|
{
|
||||||
|
aux =0;
|
||||||
|
dis = Dist2d(s1, p);
|
||||||
|
}
|
||||||
|
if(aux>1)//distancia en s2
|
||||||
|
{
|
||||||
|
aux =1;
|
||||||
|
dis = Dist2d(s2, p);
|
||||||
|
}
|
||||||
|
if(lamb)
|
||||||
|
*lamb = aux;
|
||||||
|
return dis;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::DisPtoLine(SetPtsR* line, double*p, int* idpto, double *lamb)
|
||||||
|
{
|
||||||
|
int nn = line->getNumberPtos();
|
||||||
|
double dis = DBL_MAX;
|
||||||
|
int ii = -1, ip;
|
||||||
|
double l, laux, disa;
|
||||||
|
double *p1,*p2;
|
||||||
|
if(nn<2)
|
||||||
|
{
|
||||||
|
if(lamb)
|
||||||
|
*lamb = 0;
|
||||||
|
if(idpto)
|
||||||
|
*idpto=0;
|
||||||
|
return dis;
|
||||||
|
}
|
||||||
|
|
||||||
|
p1 = line->getPto(0);
|
||||||
|
ip =0;
|
||||||
|
for(int i =1; i<nn; i++)
|
||||||
|
{
|
||||||
|
p2 = line->getPto(i);
|
||||||
|
disa=DpSeg(p1,p2,p,&laux);
|
||||||
|
if(disa<dis)
|
||||||
|
{
|
||||||
|
dis = disa;
|
||||||
|
ii = ip;
|
||||||
|
l = laux;
|
||||||
|
}
|
||||||
|
p1=p2;
|
||||||
|
ip++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lamb)
|
||||||
|
*lamb = l;
|
||||||
|
if(idpto)
|
||||||
|
*idpto=ii;
|
||||||
|
return dis;
|
||||||
|
}
|
||||||
|
//devuelve el punto que esta en la polilinea a una distancia dist
|
||||||
|
double* GeometryFunction::GetPto(SetPtsR* line, double dis, double *dst, double *distTot)
|
||||||
|
{
|
||||||
|
double *p1, *p2;
|
||||||
|
double disAct;
|
||||||
|
int nn = line->getNumberPtos();
|
||||||
|
if(nn<=0)
|
||||||
|
return 0;
|
||||||
|
if(distTot&& *distTot<dis)
|
||||||
|
{
|
||||||
|
p1 = line->getPto(nn-1);
|
||||||
|
for(int i=0; i<3; i++)
|
||||||
|
dst[i]=p1[i];
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
p1 = line->getPto(0);
|
||||||
|
for(int ip =1; ip<nn; ip++)
|
||||||
|
{
|
||||||
|
p2 = line->getPto(ip);
|
||||||
|
disAct= Dist2d(p1,p2);
|
||||||
|
if(disAct>= dis && disAct>0)
|
||||||
|
{
|
||||||
|
//encontrado segmento limite de linea
|
||||||
|
double l =dis/disAct;
|
||||||
|
for(int ii=0; ii<3; ii++)
|
||||||
|
dst[ii]=p1[ii]+l*(p2[ii]-p1[ii]);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
dis-=disAct;
|
||||||
|
p1=p2;
|
||||||
|
}
|
||||||
|
for(int i=0; i<3; i++)
|
||||||
|
dst[i]=p1[i];
|
||||||
|
return dst;
|
||||||
|
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool GeometryFunction::DivLine(SetPtsR* line, SetPtsW* ldst1, SetPtsW* ldst2, double dis)
|
||||||
|
{
|
||||||
|
int nn = line->getNumberPtos();
|
||||||
|
double disAct =0;
|
||||||
|
double *p1,*p2;
|
||||||
|
double pp[3];
|
||||||
|
double l=-1;
|
||||||
|
if(nn<2)
|
||||||
|
return false;
|
||||||
|
p1 = line->getPto(0);
|
||||||
|
if(!ldst1->addPto(p1))
|
||||||
|
return false;
|
||||||
|
int i =0;
|
||||||
|
for(i =1; i<nn; i++)
|
||||||
|
{
|
||||||
|
p2 = line->getPto(i);
|
||||||
|
disAct= Dist2d(p1,p2);
|
||||||
|
if(disAct>=dis && disAct>0)
|
||||||
|
{
|
||||||
|
//encontrado segmento limite de linea
|
||||||
|
l =dis/disAct;
|
||||||
|
for(int ii=0; ii<3; ii++)
|
||||||
|
pp[ii]=p1[ii]+l*(p2[ii]-p1[ii]);
|
||||||
|
if(l>0)
|
||||||
|
{
|
||||||
|
if(!ldst1->addPto(pp))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dis-=disAct;
|
||||||
|
if(!ldst1->addPto(p2))
|
||||||
|
return false;
|
||||||
|
p1=p2;
|
||||||
|
}
|
||||||
|
if(l<0)
|
||||||
|
return false;
|
||||||
|
//rellena segunda linea
|
||||||
|
if(l<1)
|
||||||
|
{
|
||||||
|
if(!ldst2->addPto(pp))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!ldst2->addPto(p2))
|
||||||
|
return false;
|
||||||
|
i++;
|
||||||
|
for(; i<nn; i++)
|
||||||
|
{
|
||||||
|
p2 = line->getPto(i);
|
||||||
|
if(!ldst2->addPto(p2))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
bool GeometryFunction::DivLine(SetPtsR* line, SetPtsWBuilder *builder, double dist)
|
||||||
|
{
|
||||||
|
int nn = line->getNumberPtos();
|
||||||
|
double disAct =0;
|
||||||
|
double *p1,*p2;
|
||||||
|
double pp[3], pp1[3];
|
||||||
|
double l=-1;
|
||||||
|
double dis = dist;
|
||||||
|
SetPtsW *ldst;
|
||||||
|
if(nn<2)
|
||||||
|
return false;
|
||||||
|
ldst =builder->build();
|
||||||
|
p1 = line->getPto(0);
|
||||||
|
if(!ldst->addPto(p1))
|
||||||
|
return false;
|
||||||
|
int i =0;
|
||||||
|
for(i =1; i<nn; i++)
|
||||||
|
{
|
||||||
|
p2 = line->getPto(i);
|
||||||
|
disAct= Dist2d(p1,p2);
|
||||||
|
if(disAct>=dis && disAct>0)
|
||||||
|
{
|
||||||
|
for(int ii=0; ii<3; ii++)
|
||||||
|
pp1[ii]=p1[ii];
|
||||||
|
while(disAct>dis)
|
||||||
|
{
|
||||||
|
//encontrado segmento limite de linea
|
||||||
|
l =dis/disAct;
|
||||||
|
for(int ii=0; ii<3; ii++)
|
||||||
|
pp[ii]=pp1[ii]+l*(p2[ii]-pp1[ii]);
|
||||||
|
//añade punto en el que se alcanza la distancia
|
||||||
|
if(l>0)
|
||||||
|
{
|
||||||
|
if(!ldst->addPto(pp))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(i==nn-1 && l==1)
|
||||||
|
{
|
||||||
|
dis =0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//se pide otra linea
|
||||||
|
ldst =builder->build();
|
||||||
|
for(int ii=0; ii<3; ii++)
|
||||||
|
pp1[ii]=pp[ii];
|
||||||
|
if(l<1)
|
||||||
|
{
|
||||||
|
if(!ldst->addPto(pp1))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
disAct-=dis;
|
||||||
|
dis =dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dis-=disAct;
|
||||||
|
if(!ldst->addPto(p2))
|
||||||
|
return false;
|
||||||
|
p1=p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//**************************************************************************************************************************
|
||||||
|
/*
|
||||||
|
* Devuelve el ángulo entre v1 y v2
|
||||||
|
*/
|
||||||
|
double GeometryFunction::AngVect(double v1[2], double v2[2])
|
||||||
|
{
|
||||||
|
double res = sqrt(v1[0] * v1[0] + v1[1] * v1[1]) *
|
||||||
|
sqrt(v2[0] * v2[0] + v2[1] * v2[1]);
|
||||||
|
if(res==0)
|
||||||
|
return 0;
|
||||||
|
res = (v1[0] * v2[0] + v1[1] * v2[1]) / res;
|
||||||
|
if (res > 1)
|
||||||
|
res = 1;
|
||||||
|
if (res < -1)
|
||||||
|
res = -1;
|
||||||
|
return acos(res);
|
||||||
|
}
|
||||||
|
//**************************************************************************************************************************
|
||||||
|
/*
|
||||||
|
* Calcula si el punto p está a la derecha del vector definido por los dos puntos de ptos
|
||||||
|
* Se calcula el producto escalar de los dos vectores
|
||||||
|
*/
|
||||||
|
bool GeometryFunction::IsDer(SetPtsR* ptos, double *p, int ip1, int ip2)
|
||||||
|
{
|
||||||
|
double d;
|
||||||
|
double *p1, *p2;
|
||||||
|
p1=ptos->getPto(ip1);
|
||||||
|
p2=ptos->getPto(ip2);
|
||||||
|
|
||||||
|
d = (p2[0] - p1[0])*(p[1] - p1[1]) -
|
||||||
|
(p2[1] - p1[1])*(p[0] - p1[0]);
|
||||||
|
|
||||||
|
return d< 0;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
//Siempre se le debe llamar de forma que line1 sea de menor longitud que line2
|
||||||
|
//partiendo de line1 y calculando la distancia de puntos equidistantes l_avan a los puntos
|
||||||
|
//más cercanos de line2
|
||||||
|
double GeometryFunction::DisMedLines( SetPtsR* line1, SetPtsR* line2, double l_avan, double *desv/*=NULL*/)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
double l_parc, long1, dd, dd2,dis;
|
||||||
|
double pt1[3];
|
||||||
|
|
||||||
|
long1=LongLine2d(line1);
|
||||||
|
if(l_avan>long1)
|
||||||
|
l_avan=long1;
|
||||||
|
n=(int)(long1/l_avan);
|
||||||
|
l_parc=0;
|
||||||
|
dd=dd2=0;
|
||||||
|
while(l_parc<long1)
|
||||||
|
{
|
||||||
|
dis=DisPtoLine(line2, GetPto(line1,l_parc,pt1,&long1));
|
||||||
|
dd+=dis/n;
|
||||||
|
dd2+=Poten(dis)/n;
|
||||||
|
l_parc+=l_avan;
|
||||||
|
}
|
||||||
|
if(desv)
|
||||||
|
*desv=sqrt(dd2-Poten(dd));
|
||||||
|
return dd;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************************************************************************************
|
||||||
|
//Siempre se le debe llamar de forma que line1 sea de menor longitud que line2
|
||||||
|
//calculando la distancia de los puntos de line1 a line2
|
||||||
|
double GeometryFunction::DisMedLines( SetPtsR* line1, SetPtsR* line2, double *desv/*=NULL*/)
|
||||||
|
{
|
||||||
|
double dis, dd, dd2;
|
||||||
|
int i,n;
|
||||||
|
double *p;
|
||||||
|
///////////////////
|
||||||
|
|
||||||
|
i=0;
|
||||||
|
dd=dd2=0;
|
||||||
|
n=line1->getNumberPtos();
|
||||||
|
while(i<n)
|
||||||
|
{
|
||||||
|
p=line1->getPto(i);
|
||||||
|
dis = DisPtoLine(line2,p);
|
||||||
|
dd+=dis/n;
|
||||||
|
dd2+=Poten(dis)/n;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(desv)
|
||||||
|
*desv=sqrt(dd2-Poten(dd));
|
||||||
|
return dd;
|
||||||
|
}
|
||||||
|
//*************************************************************************************
|
||||||
|
/**
|
||||||
|
* Devuelve el prodcuto escalar de los vectores formados por los dos puntos 'ptos1'
|
||||||
|
* y los dos en 'ptos2'
|
||||||
|
*/
|
||||||
|
double GeometryFunction::ProdEscalar(SetPtsR* line1, SetPtsR* line2)
|
||||||
|
{
|
||||||
|
double p;
|
||||||
|
p=0;
|
||||||
|
|
||||||
|
for(int i=0;i<3; i++)
|
||||||
|
p+=(line1->getPto(1)[i]-line1->getPto(0)[i])*(line2->getPto(1)[i]-line2->getPto(0)[i]);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
SetPtsW * GeometryFunction::GetNPrimePtos( SetPtsR* line, SetPtsW *ldst, int nptos, double dist, BOOL avanza )
|
||||||
|
{
|
||||||
|
int nn = line->getNumberPtos();
|
||||||
|
double disAct =0;
|
||||||
|
double *p1,*p2;
|
||||||
|
double pp[3];
|
||||||
|
double paux1[3];
|
||||||
|
double l=-1;
|
||||||
|
double dis = dist;
|
||||||
|
int i;
|
||||||
|
if(nn<2)
|
||||||
|
return NULL;
|
||||||
|
if(avanza)
|
||||||
|
p1 = line->getPto(0);
|
||||||
|
else
|
||||||
|
p1 = line->getPto(nn-1);
|
||||||
|
|
||||||
|
if(!ldst->addPto(p1))
|
||||||
|
return NULL;
|
||||||
|
nptos--;
|
||||||
|
int ip =0;
|
||||||
|
for(ip =1; ip<nn && nptos>0; ip++)
|
||||||
|
{
|
||||||
|
if(avanza)
|
||||||
|
i = ip;
|
||||||
|
else
|
||||||
|
i = nn-1-ip;
|
||||||
|
p2 = line->getPto(i);
|
||||||
|
disAct= Dist2d(p1,p2);
|
||||||
|
if(disAct>=dis && disAct>0)
|
||||||
|
{
|
||||||
|
for(int ii=0; ii<3; ii++)
|
||||||
|
paux1[ii]=p1[ii];
|
||||||
|
while(disAct>=dis && nptos>0)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//encontrado segmento limite de linea
|
||||||
|
l =dis/disAct;
|
||||||
|
for(int ii=0; ii<3; ii++)
|
||||||
|
pp[ii]=paux1[ii]+l*(p2[ii]-paux1[ii]);
|
||||||
|
|
||||||
|
|
||||||
|
if(!ldst->addPto(pp))
|
||||||
|
return NULL;
|
||||||
|
nptos--;
|
||||||
|
for(int ii=0; ii<3; ii++)
|
||||||
|
paux1[ii]=pp[ii];
|
||||||
|
disAct -=dis;
|
||||||
|
dis =dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dis-=disAct;
|
||||||
|
p1=p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ldst;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::DisInLine( SetPtsR* linesrc, int ip, double lamb )
|
||||||
|
{
|
||||||
|
double dis=0;
|
||||||
|
double *p1, *p2, pp[3];
|
||||||
|
if(ip<0)
|
||||||
|
return -1;
|
||||||
|
p1=linesrc->getPto(0);
|
||||||
|
if(!p1)
|
||||||
|
return -1;
|
||||||
|
for(int i=1; i<=ip; i++)
|
||||||
|
{
|
||||||
|
p2 = linesrc->getPto(i);
|
||||||
|
if(!p2)
|
||||||
|
return -1;
|
||||||
|
dis+=Dist2d(p1,p2);
|
||||||
|
p1=p2;
|
||||||
|
}
|
||||||
|
p2=linesrc->getPto(ip+1);
|
||||||
|
if(!p2)
|
||||||
|
return -1;
|
||||||
|
pp[2]=0;
|
||||||
|
for(int i=0; i<2;i++)
|
||||||
|
pp[i]=p1[i]+(p2[i]-p1[i])*lamb;
|
||||||
|
|
||||||
|
dis+=Dist2d(p1,pp);
|
||||||
|
|
||||||
|
return dis;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double *GeometryFunction::PtInLine( SetPtsR* linesrc, int ip, double lamb, double *pp )
|
||||||
|
{
|
||||||
|
double *p1, *p2;
|
||||||
|
if(ip<0)
|
||||||
|
return 0;
|
||||||
|
if(!pp)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
p1=linesrc->getPto(ip);
|
||||||
|
if(!p1)
|
||||||
|
return 0;
|
||||||
|
p2=linesrc->getPto(ip+1);
|
||||||
|
if(!p2)
|
||||||
|
return 0;
|
||||||
|
pp[2]=0;
|
||||||
|
for(int i=0; i<2;i++)
|
||||||
|
pp[i]=p1[i]+(p2[i]-p1[i])*lamb;
|
||||||
|
|
||||||
|
return pp;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double* GeometryFunction::intersecLine(double* l11, double *l12, double* l21, double *l22, double *p_inters)
|
||||||
|
{
|
||||||
|
double v1[2], v2[2], a[2][2], b[2];
|
||||||
|
//calcula vectores directores-----------
|
||||||
|
for(int i =0; i<2; i++)
|
||||||
|
{
|
||||||
|
v1[i] = l12[i]-l11[i];
|
||||||
|
v2[i] = l22[i]-l21[i];
|
||||||
|
}
|
||||||
|
//calculo de matriz de coeficientes--------
|
||||||
|
a[0][0] = v1[1];
|
||||||
|
a[0][1] = -v1[0];
|
||||||
|
a[1][0] = v2[1];
|
||||||
|
a[1][1] = -v2[0];
|
||||||
|
//calculo terminos independientes-----------
|
||||||
|
b[0]=l11[0]*v1[1]-l11[1]*v1[0];
|
||||||
|
b[1]=l21[0]*v2[1]-l21[1]*v2[0];
|
||||||
|
//calculo determinante-----------------------
|
||||||
|
double det = a[0][0]*a[1][1]-a[1][0]*a[0][1];
|
||||||
|
if(det == 0)
|
||||||
|
return NULL;//lineas son paralelas
|
||||||
|
p_inters[0]= (b[0]*a[1][1]-a[0][1]*b[1])/det;
|
||||||
|
p_inters[1]= (a[0][0]*b[1]-b[0]*a[1][0])/det;
|
||||||
|
return p_inters;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::DLineSeg( double* l1, double *l2, double* s1, double *s2, double *lambl,double *lambs, bool*paralelos )
|
||||||
|
{
|
||||||
|
double p[2];
|
||||||
|
double d1, d2, lamb2;
|
||||||
|
*lambs = 0;
|
||||||
|
if(paralelos)
|
||||||
|
*paralelos = false;
|
||||||
|
d1 =Dpline(l1,l2,s1,lambl);
|
||||||
|
if(d1 <=0 || !intersecLine(l1,l2,s1,s2,p))
|
||||||
|
{
|
||||||
|
if(d1>0 && paralelos)
|
||||||
|
*paralelos = true;
|
||||||
|
return d1;
|
||||||
|
}
|
||||||
|
d2 = DpSeg(s1,s2,p, &lamb2);
|
||||||
|
if(d2<d1)
|
||||||
|
{
|
||||||
|
d1 =d2;
|
||||||
|
*lambs = lamb2;
|
||||||
|
d2 = Dist2d(l1,l2);
|
||||||
|
lamb2 = Dist2d(p,l1);
|
||||||
|
*lambl = lamb2/d2;
|
||||||
|
if(Dist2d(p,l2)>lamb2)
|
||||||
|
*lambl = -*lambl;
|
||||||
|
if(d1<=0)
|
||||||
|
return d1;
|
||||||
|
}
|
||||||
|
d2 = Dpline(l1,l2,s2, &lamb2);
|
||||||
|
if(d2<d1)
|
||||||
|
{
|
||||||
|
d1 =d2;
|
||||||
|
*lambl = lamb2;
|
||||||
|
*lambs =1;
|
||||||
|
}
|
||||||
|
return d1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::DsegSeg( double* s11, double *s12, double* s21, double *s22, double *lamd1,double *lamd2 )
|
||||||
|
{
|
||||||
|
bool paral;
|
||||||
|
double dl = DLineSeg(s11,s12,s21,s22,lamd1, lamd2, ¶l);
|
||||||
|
if(*lamd1<0 )
|
||||||
|
{
|
||||||
|
*lamd1 =0;
|
||||||
|
//if(paral)
|
||||||
|
return DpSeg(s21,s22,s11,lamd2);
|
||||||
|
/*else
|
||||||
|
return Dist2d(s21,s22,s11,lamd2);*/
|
||||||
|
}
|
||||||
|
if(*lamd1>1)
|
||||||
|
{
|
||||||
|
*lamd1 =1;
|
||||||
|
return DpSeg(s21,s22,s12,lamd2);
|
||||||
|
}
|
||||||
|
return dl;//se alcanza en la linea
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
double GeometryFunction::DplineSeg( SetPtsR* line1, double* s1, double *s2,int *n, double *lamd1,double *lamb2 )
|
||||||
|
{
|
||||||
|
double d=(double) 1.e+30, d1, l1, l2;
|
||||||
|
|
||||||
|
double *p1,*p2;
|
||||||
|
int nn = line1->getNumberPtos();
|
||||||
|
if(nn<=0)
|
||||||
|
return d;
|
||||||
|
p1 = line1->getPto(0);
|
||||||
|
for(int i =1; i<nn; i++)
|
||||||
|
{
|
||||||
|
p2 = line1->getPto(i);
|
||||||
|
d1 = DsegSeg(p1,p2,s1,s2,&l1,&l2);
|
||||||
|
if(d1<d)
|
||||||
|
{
|
||||||
|
d = d1;
|
||||||
|
if(lamd1)
|
||||||
|
*lamd1 = l1;
|
||||||
|
if(lamb2)
|
||||||
|
*lamb2 = l2;
|
||||||
|
if(n)
|
||||||
|
*n = i-1;
|
||||||
|
if(d<=0)
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
p1 = p2;
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef GeometriFunction_h
|
||||||
|
#define GeometriFunction_h
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "cartoBaseDef.h"
|
||||||
|
#include "garray.h"
|
||||||
|
|
||||||
|
class UTILES_EXPORT GeometryFunction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//distancia entre 2 ptos
|
||||||
|
static double Dist2d(double*p1, double*p2);
|
||||||
|
//longitud de la linea
|
||||||
|
static double LongLine2d(SetPtsR *line);
|
||||||
|
//distancia de un punto p a una linea infinita de puntos l1 y l2
|
||||||
|
static double Dpline(double* l1, double *l2, double *p, double *lamb = 0);
|
||||||
|
//distancia de punto p a segmento s1-s2
|
||||||
|
static double DpSeg(double* s1, double *s2, double *p, double *lamb = 0);
|
||||||
|
//interseccion entre lineas (formada por l11-l12) a otra linea (formada por l21-l22)
|
||||||
|
static double* intersecLine(double* l11, double *l12, double* l21, double *l22, double *p_inters);
|
||||||
|
//distancia entre linea (l1-l2)y segmento(s1,s2)
|
||||||
|
static double DLineSeg(double* l1, double *l2, double* s1, double *s2, double *lamdl,double *lambs, bool*paralelos );
|
||||||
|
|
||||||
|
//distancia entre linea (l1-l2)y segmento(s1,s2)
|
||||||
|
static double DsegSeg(double* s11, double *s12, double* s21, double *s22, double *lamd1,double *lamb2);
|
||||||
|
//distancia de polilinea a segmento
|
||||||
|
static double DplineSeg(SetPtsR* line1, double* s1, double *s2,int *n=NULL, double *lamd1=NULL,double *lamb2=NULL);
|
||||||
|
|
||||||
|
|
||||||
|
//calcula coordenadas minimas y maximas
|
||||||
|
static void CompMima(double dst[2][3], SetPtsR* pts);
|
||||||
|
//calcula envoltura convexa
|
||||||
|
static Cgarray<double[3]>* EnvConvex(SetPtsR* pts, Cgarray<double[3]>* dst);
|
||||||
|
//distancia de un punto a una linea
|
||||||
|
static double DisPtoLine(SetPtsR* line, double*p, int* idpto=NULL, double *lamb=NULL);
|
||||||
|
//distancia media entre dos líneas
|
||||||
|
static double DisMedLines( SetPtsR* line1, SetPtsR* line2, double *desv=NULL);
|
||||||
|
static double DisMedLines( SetPtsR* line1, SetPtsR* line2, double l_avan, double *desv=NULL);
|
||||||
|
//parte una linea en 2
|
||||||
|
static bool DivLine(SetPtsR* linesrc, SetPtsW* ldst1, SetPtsW* ldst2, double dis);
|
||||||
|
//dado el ip y el lamb da la distancia desde el principio de la linea
|
||||||
|
static double DisInLine(SetPtsR* linesrc, int ip, double lamb);
|
||||||
|
//dado el ip y el lamb da la distancia desde el punto contenido en la línea
|
||||||
|
static double *PtInLine( SetPtsR* linesrc, int ip, double lamb , double *pp );
|
||||||
|
//devuelve los nptos primeros puntos de line, equiespaciados dis
|
||||||
|
//si avanza, los coge del principio, si no, del final
|
||||||
|
static SetPtsW *GetNPrimePtos(SetPtsR* line, SetPtsW *ldst, int nptos, double dis, BOOL avanza);
|
||||||
|
|
||||||
|
//divide la linea en partes equidistantes
|
||||||
|
static bool DivLine(SetPtsR* line, SetPtsWBuilder *manager, double dis);
|
||||||
|
|
||||||
|
//devuelve el punto que esta en la polilinea a una distancia dist
|
||||||
|
static double* GetPto(SetPtsR* line, double dis, double *dst, double *distTot = NULL);
|
||||||
|
|
||||||
|
static double ang_vect_ptos(double (*ptos1)[][3], double (*ptos2)[][3]);
|
||||||
|
|
||||||
|
//devuelve el angulo que forman los 2 vectores
|
||||||
|
static double AngVect(double v1[2], double v2[2]);
|
||||||
|
//dice si el punto p esta a la derecha de la linea que forman los puntos ip1 y ip2
|
||||||
|
static bool IsDer(SetPtsR* ptos, double *p, int ip1, int ip2);
|
||||||
|
static double ProdEscalar(SetPtsR* line1, SetPtsR* line2);
|
||||||
|
|
||||||
|
//funcion auxiliar potencia
|
||||||
|
static inline double Poten(double bas, int exp = 2)
|
||||||
|
{
|
||||||
|
if(exp<=0)
|
||||||
|
return 0;
|
||||||
|
double res = bas;
|
||||||
|
while(exp>1)
|
||||||
|
{
|
||||||
|
res = res * bas;
|
||||||
|
exp--;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,294 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "IaDataTable.h"
|
||||||
|
#include "CartoBase.h"
|
||||||
|
#include "Fdbf.h"
|
||||||
|
//***************************************************************************
|
||||||
|
IaDataTable::IaDataTable(void)
|
||||||
|
{
|
||||||
|
auxnrow=-1;
|
||||||
|
auxref =-1;
|
||||||
|
auxref = auxc=-1;
|
||||||
|
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
IaDataTable::~IaDataTable(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void* IaDataTable::IaGet( int refEnt )
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void IaDataTable::CBSet( CartoBase* cb )
|
||||||
|
{
|
||||||
|
_cb = cb;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void IaDataTable::IaRemove( int refEnt )
|
||||||
|
{
|
||||||
|
int icol = RefIndex[refEnt];
|
||||||
|
if(icol<0)
|
||||||
|
return;
|
||||||
|
removeRow(RefIndex[refEnt]);
|
||||||
|
RefIndex[refEnt]=-1;
|
||||||
|
rowIndex[icol] = -1;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void IaDataTable::IaRemoveAll()
|
||||||
|
{
|
||||||
|
RefIndex.clear();
|
||||||
|
rowIndex.clear();
|
||||||
|
delAll();
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
void IaDataTable::IaAdd( int refEnt )
|
||||||
|
{
|
||||||
|
if(!addRow(1))
|
||||||
|
{
|
||||||
|
RefIndex[refEnt] = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int iRow=nRow()-1;
|
||||||
|
RefIndex[refEnt]=iRow;
|
||||||
|
rowIndex[iRow] = refEnt;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaSet( int nrow, int ncolm )
|
||||||
|
{
|
||||||
|
IaRemoveAll();
|
||||||
|
auxnrow = nrow;
|
||||||
|
auxcolm =ncolm;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaSetColm( int icol, char* name, BYTE type, int size )
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case(DBF_TYPE_DATA_STR):
|
||||||
|
t = GdataTable::Tstring;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_I64):
|
||||||
|
t = GdataTable::Tint64;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_D):
|
||||||
|
t = GdataTable::Tdouble;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_BOOL):
|
||||||
|
t = GdataTable::Tbool;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_BIN):
|
||||||
|
t = GdataTable::Tbin;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_I):
|
||||||
|
t = GdataTable::Tint;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool res = addColm(name,t,size);
|
||||||
|
if(res && auxcolm>0 && nColm()>= auxcolm)
|
||||||
|
{
|
||||||
|
res = addMemRow(auxnrow);
|
||||||
|
auxnrow =0;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaAddVal( int refEnt, int icol, int v )
|
||||||
|
{
|
||||||
|
int _nrow;
|
||||||
|
if(auxnrow>=0)
|
||||||
|
_nrow =RefIndex[refEnt];
|
||||||
|
else
|
||||||
|
_nrow = RefIndex[refEnt];
|
||||||
|
int* vv = getI(auxnrow,icol);
|
||||||
|
if(vv)
|
||||||
|
*vv = v;
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaAddVal( int refEnt, int icol, double v )
|
||||||
|
{
|
||||||
|
int _nrow;
|
||||||
|
if(auxnrow>=0)
|
||||||
|
_nrow =RefIndex[refEnt];
|
||||||
|
else
|
||||||
|
_nrow = RefIndex[refEnt];
|
||||||
|
double* vv = getD(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
*vv = v;
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaAddVal( int refEnt, int icol, __int64 v )
|
||||||
|
{
|
||||||
|
int _nrow;
|
||||||
|
if(auxnrow>=0)
|
||||||
|
_nrow =RefIndex[refEnt];
|
||||||
|
else
|
||||||
|
_nrow = RefIndex[refEnt];
|
||||||
|
__int64* vv = getI64(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
*vv = v;
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaAddVal( int refEnt, int icol, char* v )
|
||||||
|
{
|
||||||
|
int _nrow;
|
||||||
|
if(auxnrow>=0)
|
||||||
|
_nrow =RefIndex[refEnt];
|
||||||
|
else
|
||||||
|
_nrow = RefIndex[refEnt];
|
||||||
|
char* vv = getS(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
strcpy(vv,v);
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaAddVal( int refEnt, int icol, void* v )
|
||||||
|
{
|
||||||
|
int _nrow;
|
||||||
|
if(auxnrow>=0)
|
||||||
|
_nrow =RefIndex[refEnt];
|
||||||
|
else
|
||||||
|
_nrow = RefIndex[refEnt];
|
||||||
|
void* vv = getBin(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
memcpy(vv,v, getSize(icol));
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaFinRow( int refEnt )
|
||||||
|
{
|
||||||
|
auxnrow++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaFinR()
|
||||||
|
{
|
||||||
|
auxnrow=-1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaGetSize(int *ncolm )
|
||||||
|
{
|
||||||
|
*ncolm =nColm();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
#define MAX_NDECIMALS 10;
|
||||||
|
bool IaDataTable::IaGetColm( int icol, char* name, BYTE *type, int *size, int*ndecimal )
|
||||||
|
{
|
||||||
|
//pilla tipo----------------------
|
||||||
|
static BYTE t[GdataTable::Tntip]={0,DBF_TYPE_DATA_BOOL,DBF_TYPE_DATA_I, DBF_TYPE_DATA_D,DBF_TYPE_DATA_I64, DBF_TYPE_DATA_STR, DBF_TYPE_DATA_BIN } ;
|
||||||
|
*type = t[getType(icol)];
|
||||||
|
*ndecimal = MAX_NDECIMALS;
|
||||||
|
//copia segura de nombre------------------
|
||||||
|
int i =0;
|
||||||
|
char *st =getName(icol);
|
||||||
|
for(; i<10; i++)
|
||||||
|
{
|
||||||
|
if(!st[i])
|
||||||
|
break;
|
||||||
|
name[i]=st[i];
|
||||||
|
}
|
||||||
|
name[i]=0;
|
||||||
|
*size = getSizeASCII(icol);
|
||||||
|
return *size>0;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaGetVal( int refEnt, int icol, int* v )
|
||||||
|
{
|
||||||
|
int irow;
|
||||||
|
if(auxref == refEnt)
|
||||||
|
irow = auxc;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
irow = RefIndex[refEnt];
|
||||||
|
auxref = refEnt;
|
||||||
|
auxc = irow;
|
||||||
|
}
|
||||||
|
if(irow<0)
|
||||||
|
return false;
|
||||||
|
*v = *getI(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaGetVal( int refEnt, int icol, double* v )
|
||||||
|
{
|
||||||
|
int irow;
|
||||||
|
if(auxref == refEnt)
|
||||||
|
irow = auxc;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
irow = RefIndex[refEnt];
|
||||||
|
auxref = refEnt;
|
||||||
|
auxc = irow;
|
||||||
|
}
|
||||||
|
if(irow<0)
|
||||||
|
return false;
|
||||||
|
*v = *getD(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaGetVal( int refEnt, int icol, __int64* v )
|
||||||
|
{
|
||||||
|
int irow;
|
||||||
|
if(auxref == refEnt)
|
||||||
|
irow = auxc;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
irow = RefIndex[refEnt];
|
||||||
|
auxref = refEnt;
|
||||||
|
auxc = irow;
|
||||||
|
}
|
||||||
|
if(irow<0)
|
||||||
|
return false;
|
||||||
|
*v = *getI64(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaGetVal( int refEnt, int icol, char** v )
|
||||||
|
{
|
||||||
|
int irow;
|
||||||
|
if(auxref == refEnt)
|
||||||
|
irow = auxc;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
irow = RefIndex[refEnt];
|
||||||
|
auxref = refEnt;
|
||||||
|
auxc = irow;
|
||||||
|
}
|
||||||
|
if(irow<0)
|
||||||
|
return false;
|
||||||
|
*v= getS(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaGetVal( int refEnt, int icol, void** v )
|
||||||
|
{
|
||||||
|
int irow;
|
||||||
|
if(auxref == refEnt)
|
||||||
|
irow = auxc;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
irow = RefIndex[refEnt];
|
||||||
|
auxref = refEnt;
|
||||||
|
auxc = irow;
|
||||||
|
}
|
||||||
|
if(irow<0)
|
||||||
|
return false;
|
||||||
|
*v= getBin(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool IaDataTable::IaFinW()
|
||||||
|
{
|
||||||
|
auxref = auxc=-1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef IaDataTable_h
|
||||||
|
#define IaDataTable_h
|
||||||
|
#include "gdatatable.h"
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "CartoBaseDef.h"
|
||||||
|
#include <map>
|
||||||
|
class CartoBase;
|
||||||
|
//tabla de datos para albergar informacion asiciada generica (diseñada para el cartobase)
|
||||||
|
class UTILES_EXPORT IaDataTable :
|
||||||
|
public GdataTable, public DataIaCartoBase
|
||||||
|
{
|
||||||
|
std::map<int, int> RefIndex;//indexado por referencias;
|
||||||
|
std::map<int, int> rowIndex;//indexado por filas;
|
||||||
|
CartoBase* _cb;
|
||||||
|
int auxnrow,auxcolm,auxref,auxc;
|
||||||
|
public:
|
||||||
|
IaDataTable(void);
|
||||||
|
~IaDataTable(void);
|
||||||
|
|
||||||
|
virtual void* IaGet( int refEnt );
|
||||||
|
virtual void CBSet( CartoBase* cb );
|
||||||
|
virtual void IaRemove( int refEnt );
|
||||||
|
virtual void IaRemoveAll();
|
||||||
|
virtual void IaAdd( int refEnt );
|
||||||
|
virtual bool IaSet( int nrow, int ncolm );
|
||||||
|
virtual bool IaSetColm( int icol, char* name, BYTE type, int size );
|
||||||
|
virtual bool IaAddVal( int refEnt, int icol, int v );
|
||||||
|
virtual bool IaAddVal( int refEnt, int icol, double v );
|
||||||
|
virtual bool IaAddVal( int refEnt, int icol, __int64 v );
|
||||||
|
virtual bool IaAddVal( int refEnt, int icol, char* v );
|
||||||
|
virtual bool IaAddVal( int refEnt, int icol, void* v );
|
||||||
|
virtual bool IaFinRow( int refEnt );
|
||||||
|
virtual bool IaFinR();
|
||||||
|
virtual bool IaGetSize( int *ncolm );
|
||||||
|
virtual bool IaGetColm( int icol, char* name, BYTE *type, int *size, int*ndecimal );
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, int* v );
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, double* v );
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, __int64* v );
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, char** v );
|
||||||
|
virtual bool IaGetVal( int refEnt, int icol, void** v );
|
||||||
|
virtual bool IaFinW();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,229 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "ManagerDbfGdataTable.h"
|
||||||
|
#include "GdataTable.h"
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
ManagerDbfGdataTable::ManagerDbfGdataTable(void)
|
||||||
|
{
|
||||||
|
_dt = NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
ManagerDbfGdataTable::~ManagerDbfGdataTable(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfSet( int nrow, int ncolm )
|
||||||
|
{
|
||||||
|
_dt->delAll();
|
||||||
|
_nrow = nrow;
|
||||||
|
_ncolm = ncolm;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool ManagerDbfGdataTable::AddCol( char* path, char* name, BYTE type,IAddColDbf *dt, int size)
|
||||||
|
{
|
||||||
|
GdataTable tb;
|
||||||
|
|
||||||
|
if(!LeeDbf(path, &tb))
|
||||||
|
return false;
|
||||||
|
int ic=tb.getInd(name);
|
||||||
|
|
||||||
|
if(ic<0)
|
||||||
|
{
|
||||||
|
//la crea
|
||||||
|
if(!tb.addColm(name,type,size))
|
||||||
|
return false;
|
||||||
|
ic=tb.nColm()-1;
|
||||||
|
}
|
||||||
|
for(int i=0;i<tb.nRow();i++)
|
||||||
|
{
|
||||||
|
dt->setData(i, tb.get(i,ic));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!grabaDbf(path,&tb))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfSetColm( char* name, BYTE type, int size )
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case(DBF_TYPE_DATA_STR):
|
||||||
|
size++;
|
||||||
|
t = GdataTable::Tstring;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_I64):
|
||||||
|
t = GdataTable::Tint64;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_D):
|
||||||
|
t = GdataTable::Tdouble;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_BOOL):
|
||||||
|
t = GdataTable::Tbool;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_BIN):
|
||||||
|
t = GdataTable::Tbin;
|
||||||
|
break;
|
||||||
|
case(DBF_TYPE_DATA_I):
|
||||||
|
t = GdataTable::Tint;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool res = _dt->addColm(name,t,size);
|
||||||
|
if(res && _nrow>0 && _dt->nColm()>= _ncolm)
|
||||||
|
{
|
||||||
|
res = _dt->addRow(_nrow);
|
||||||
|
_nrow =0;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfaddVal( int icol, int v )
|
||||||
|
{
|
||||||
|
int* vv = _dt->getI(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
*vv = v;
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfaddVal( int icol, double v )
|
||||||
|
{
|
||||||
|
double* vv = _dt->getD(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
*vv = v;
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfaddVal( int icol, __int64 v )
|
||||||
|
{
|
||||||
|
__int64* vv = _dt->getI64(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
*vv = v;
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfaddVal( int icol, char* v )
|
||||||
|
{
|
||||||
|
char* vv = _dt->getS(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
strcpy(vv,v);
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfaddVal( int icol, void* v )
|
||||||
|
{
|
||||||
|
void* vv = _dt->getBin(_nrow,icol);
|
||||||
|
if(vv)
|
||||||
|
memcpy(vv,v,_dt->getSize(icol));
|
||||||
|
return vv!= NULL;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfFinRow()
|
||||||
|
{
|
||||||
|
_nrow++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfFinR()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfGet( int *nrow, int *ncolm )
|
||||||
|
{
|
||||||
|
*nrow = _dt->nRow();
|
||||||
|
*ncolm = _dt->nColm();
|
||||||
|
_nrow =0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
#define MAX_NDECIMALS 10;
|
||||||
|
bool ManagerDbfGdataTable::DbfGetColm(int icolm, char* name, BYTE *type, int *size, int*ndecimal )
|
||||||
|
{
|
||||||
|
//pilla tipo----------------------
|
||||||
|
static BYTE t[GdataTable::Tntip]={0,DBF_TYPE_DATA_BOOL,DBF_TYPE_DATA_I, DBF_TYPE_DATA_D,DBF_TYPE_DATA_I64, DBF_TYPE_DATA_STR, DBF_TYPE_DATA_BIN } ;
|
||||||
|
*type = t[_dt->getType(icolm)];
|
||||||
|
*ndecimal = MAX_NDECIMALS;
|
||||||
|
//copia segura de nombre------------------
|
||||||
|
int i =0;
|
||||||
|
char *st =_dt->getName(icolm);
|
||||||
|
for(; i<10; i++)
|
||||||
|
{
|
||||||
|
if(!st[i])
|
||||||
|
break;
|
||||||
|
name[i]=st[i];
|
||||||
|
}
|
||||||
|
name[i]=0;
|
||||||
|
*size = _dt->getSizeASCII(icolm);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfGetVal(int irow, int icol, int* v )
|
||||||
|
{
|
||||||
|
*v = *_dt->getI(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfGetVal(int irow, int icol, double* v )
|
||||||
|
{
|
||||||
|
*v = *_dt->getD(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfGetVal(int irow, int icol, __int64* v )
|
||||||
|
{
|
||||||
|
*v = *_dt->getI64(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfGetVal(int irow, int icol, char** v )
|
||||||
|
{
|
||||||
|
*v= _dt->getS(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfGetVal(int irow, int icol, void** v )
|
||||||
|
{
|
||||||
|
*v= _dt->getBin(irow,icol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::DbfFinW()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
||||||
|
bool ManagerDbfGdataTable::LeeDbf( char* path, GdataTable *db )
|
||||||
|
{
|
||||||
|
_dt= db;
|
||||||
|
return ManagerDbf::leer(path,this);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
bool ManagerDbfGdataTable::grabaDbf( char* path, GdataTable *db )
|
||||||
|
{
|
||||||
|
_dt= db;
|
||||||
|
return ManagerDbf::grabar(path,this);
|
||||||
|
}
|
||||||
|
//***************************************************************************
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef ManagerDbfGdataTable_H
|
||||||
|
#define ManagerDbfGdataTable_H
|
||||||
|
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "Fdbf.h"
|
||||||
|
|
||||||
|
class IAddColDbf
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void setData(int i, void *data)=0;
|
||||||
|
};
|
||||||
|
class GdataTable;
|
||||||
|
class UTILES_EXPORT ManagerDbfGdataTable: public ListenerDbf_W, public ListenerDbf_R
|
||||||
|
{
|
||||||
|
|
||||||
|
GdataTable *_dt;
|
||||||
|
int _nrow;
|
||||||
|
int _ncolm;
|
||||||
|
public:
|
||||||
|
ManagerDbfGdataTable(void);
|
||||||
|
~ManagerDbfGdataTable(void);
|
||||||
|
|
||||||
|
bool LeeDbf(char* path, GdataTable *dt);
|
||||||
|
bool grabaDbf(char* path, GdataTable *dt);
|
||||||
|
bool AddCol( char* path, char* name, BYTE type,IAddColDbf *dt, int size=0);
|
||||||
|
|
||||||
|
//funciones de herencia----------------------------------------
|
||||||
|
//LisenerDbf_R-------------------------------------------------
|
||||||
|
virtual bool DbfSet( int nrow, int ncolm );
|
||||||
|
virtual bool DbfSetColm( char* name, BYTE type, int size );
|
||||||
|
virtual bool DbfaddVal( int icol, int v );
|
||||||
|
virtual bool DbfaddVal( int icol, double v );
|
||||||
|
virtual bool DbfaddVal( int icol, __int64 v );
|
||||||
|
virtual bool DbfaddVal( int icol, char* v );
|
||||||
|
virtual bool DbfaddVal( int icol, void* v );
|
||||||
|
virtual bool DbfFinRow();
|
||||||
|
virtual bool DbfFinR();
|
||||||
|
//LisenerDbf_W----------------------------------------------------
|
||||||
|
virtual bool DbfGet( int *nrow, int *ncolm );
|
||||||
|
virtual bool DbfGetColm(int icol, char* name, BYTE *type, int *size, int*ndecimal );
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, int* v );
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, double* v );
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, __int64* v );
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, char** v );
|
||||||
|
virtual bool DbfGetVal(int irow, int icol, void** v );
|
||||||
|
virtual bool DbfFinW();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef Matrix2d_h
|
||||||
|
#define Matrix2d_H
|
||||||
|
|
||||||
|
#include "b_file.h"
|
||||||
|
#include "garray.h"
|
||||||
|
//matiz de clases genericas de 2 dimensiones
|
||||||
|
template <typename Tc>
|
||||||
|
class ComClasFunction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual Tc comp(Tc a, Tc b) = 0;
|
||||||
|
};
|
||||||
|
template <typename ClasVal>
|
||||||
|
class Matrix2d
|
||||||
|
{
|
||||||
|
Cgarray<ClasVal> dat;
|
||||||
|
int ysize;
|
||||||
|
public:
|
||||||
|
Matrix2d()
|
||||||
|
{
|
||||||
|
ysize = 0;
|
||||||
|
}
|
||||||
|
bool inline inicia(int xmax, int ymax)
|
||||||
|
{
|
||||||
|
ysize = ymax;
|
||||||
|
dat.borra();
|
||||||
|
if(!(dat+=xmax*ymax))
|
||||||
|
return false;
|
||||||
|
dat.n = xmax*ymax;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ClasVal* operator[](int x)//devuelve puntero a fila x
|
||||||
|
{
|
||||||
|
return dat.get(x*ysize);
|
||||||
|
}
|
||||||
|
|
||||||
|
//*******************************************************************************************************
|
||||||
|
|
||||||
|
inline bool graba( char* path )
|
||||||
|
{
|
||||||
|
Cb_file file;
|
||||||
|
if(!file.abre(path,2,TRUE))
|
||||||
|
return false;
|
||||||
|
if(!file.escribe(&ysize, sizeof(ysize)))
|
||||||
|
return false;
|
||||||
|
if(!dat.graba(&file))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
inline bool lee( char* path )
|
||||||
|
{
|
||||||
|
Cb_file file;
|
||||||
|
if(!file.abre(path,1,FALSE,TRUE))
|
||||||
|
return false;
|
||||||
|
if(!file.lee(&ysize, sizeof(ysize)))
|
||||||
|
return false;
|
||||||
|
if(!dat.leer(&file))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
inline void clear()
|
||||||
|
{
|
||||||
|
dat.borra();
|
||||||
|
}
|
||||||
|
inline bool fileMix( char* path, ComClasFunction<ClasVal> *ccomp )
|
||||||
|
{
|
||||||
|
if(ysize<=0)
|
||||||
|
return false;
|
||||||
|
Cgarray<ClasVal> fdat;
|
||||||
|
int yfile, xfile;
|
||||||
|
Cb_file file;
|
||||||
|
if(!file.abre(path,1,FALSE,TRUE))
|
||||||
|
return false;
|
||||||
|
//lee tamaño matriz
|
||||||
|
if(!file.lee(&yfile, sizeof(yfile)))
|
||||||
|
return false;
|
||||||
|
if(!file.lee(&xfile, sizeof(xfile)))
|
||||||
|
return false;
|
||||||
|
xfile = xfile/yfile;
|
||||||
|
//inicia buffer
|
||||||
|
if(!(fdat+=yfile))
|
||||||
|
return false;
|
||||||
|
//calcula numero de bytes a leer y margenes de matriz
|
||||||
|
int nb = sizeof(ClasVal)*yfile;
|
||||||
|
xfile = min(xfile, dat.n/ysize);
|
||||||
|
yfile = min(yfile, ysize);
|
||||||
|
for(int x = 0 ; x<xfile; x++)
|
||||||
|
{
|
||||||
|
//lee fila
|
||||||
|
if(!file.lee(fdat.ptr, nb))
|
||||||
|
return false;
|
||||||
|
//realiza el mix
|
||||||
|
for(int y = 0; y< yfile; y++)
|
||||||
|
dat.get(x*ysize)[y] = ccomp->comp(dat.get(x*ysize)[y], fdat[y]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
========================================================================
|
||||||
|
MICROSOFT FOUNDATION CLASS LIBRARY : utiles Project Overview
|
||||||
|
========================================================================
|
||||||
|
|
||||||
|
|
||||||
|
AppWizard has created this utiles DLL for you. This DLL not only
|
||||||
|
demonstrates the basics of using the Microsoft Foundation classes but
|
||||||
|
is also a starting point for writing your DLL.
|
||||||
|
|
||||||
|
This file contains a summary of what you will find in each of the files that
|
||||||
|
make up your utiles DLL.
|
||||||
|
|
||||||
|
utiles.vcproj
|
||||||
|
This is the main project file for VC++ projects generated using an Application Wizard.
|
||||||
|
It contains information about the version of Visual C++ that generated the file, and
|
||||||
|
information about the platforms, configurations, and project features selected with the
|
||||||
|
Application Wizard.
|
||||||
|
|
||||||
|
utiles.h
|
||||||
|
This is the main header file for the DLL. It declares the
|
||||||
|
CutilesApp class.
|
||||||
|
|
||||||
|
utiles.cpp
|
||||||
|
This is the main DLL source file. It contains the class CutilesApp.
|
||||||
|
|
||||||
|
utiles.rc
|
||||||
|
This is a listing of all of the Microsoft Windows resources that the
|
||||||
|
program uses. It includes the icons, bitmaps, and cursors that are stored
|
||||||
|
in the RES subdirectory. This file can be directly edited in Microsoft
|
||||||
|
Visual C++.
|
||||||
|
|
||||||
|
res\utiles.rc2
|
||||||
|
This file contains resources that are not edited by Microsoft
|
||||||
|
Visual C++. You should place all resources not editable by
|
||||||
|
the resource editor in this file.
|
||||||
|
|
||||||
|
utiles.def
|
||||||
|
This file contains information about the DLL that must be
|
||||||
|
provided to run with Microsoft Windows. It defines parameters
|
||||||
|
such as the name and description of the DLL. It also exports
|
||||||
|
functions from the DLL.
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
Other standard files:
|
||||||
|
|
||||||
|
StdAfx.h, StdAfx.cpp
|
||||||
|
These files are used to build a precompiled header (PCH) file
|
||||||
|
named utiles.pch and a precompiled types file named StdAfx.obj.
|
||||||
|
|
||||||
|
Resource.h
|
||||||
|
This is the standard header file, which defines new resource IDs.
|
||||||
|
Microsoft Visual C++ reads and updates this file.
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
Other notes:
|
||||||
|
|
||||||
|
AppWizard uses "TODO:" to indicate parts of the source code you
|
||||||
|
should add to or customize.
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -0,0 +1,167 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "StrArray.h"
|
||||||
|
//**************************************************************************
|
||||||
|
StrArray::StrArray(void)
|
||||||
|
{
|
||||||
|
m_str=m_i=n_i=n_str=0;
|
||||||
|
str=NULL;
|
||||||
|
ind=NULL;
|
||||||
|
incremento_char=4056;
|
||||||
|
incremento_str=30;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
StrArray::~StrArray(void)
|
||||||
|
{
|
||||||
|
borra();
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void StrArray::cuida_memoria( int n,int ni )
|
||||||
|
{
|
||||||
|
//miramos si entra str mas
|
||||||
|
if (n_i+ni>=m_i)
|
||||||
|
{
|
||||||
|
if (ni>incremento_str)
|
||||||
|
m_i+=ni;
|
||||||
|
else
|
||||||
|
m_i+=incremento_str;
|
||||||
|
|
||||||
|
if (ind)
|
||||||
|
{
|
||||||
|
ind=(int (*)[])realloc(ind,sizeof(int)*m_i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ind=(int (*)[])malloc(sizeof(int)*m_i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (n_str+n>=m_str)
|
||||||
|
{
|
||||||
|
if (n>incremento_char)
|
||||||
|
m_str+=n;
|
||||||
|
else
|
||||||
|
m_str+=incremento_char;
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
str=(char*)realloc(str,m_str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str=(char*)malloc(m_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void StrArray::borra()
|
||||||
|
{
|
||||||
|
m_str=m_i=n_i=n_str=0;
|
||||||
|
if (str)
|
||||||
|
free(str);
|
||||||
|
str=NULL;
|
||||||
|
if(ind)
|
||||||
|
free(ind);
|
||||||
|
ind=NULL;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
char* StrArray::get( int i )
|
||||||
|
{
|
||||||
|
if (i<0 || i>=n_i)
|
||||||
|
return NULL;
|
||||||
|
return &str[(*ind)[i]];
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
int StrArray::size()
|
||||||
|
{
|
||||||
|
return n_i;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void StrArray::add( char*c )
|
||||||
|
{
|
||||||
|
int n=(int)strlen(c)+1;
|
||||||
|
cuida_memoria(n);
|
||||||
|
(*ind)[n_i]=n_str;
|
||||||
|
n_i++;
|
||||||
|
strcpy(&str[n_str],c);
|
||||||
|
n_str+=n;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void StrArray::add( StrArray* st )
|
||||||
|
{
|
||||||
|
//pedimos memoria----------------------
|
||||||
|
cuida_memoria(st->n_str,st->n_i);
|
||||||
|
//copiamos chars-----------------------
|
||||||
|
memcmp(&str[n_str], str,st->n_str);
|
||||||
|
//ponemos indices----------------------
|
||||||
|
for (int i=0; i<st->n_i; i++)
|
||||||
|
{
|
||||||
|
(*ind)[n_i+i]=n_str+(*st->ind)[i];
|
||||||
|
}
|
||||||
|
//monemos posiciones como llenas-------
|
||||||
|
n_i=st->n_i;
|
||||||
|
n_str+=st->n_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StrArray::add( char*c, int ncharReser )
|
||||||
|
{
|
||||||
|
char ss[1];
|
||||||
|
ss[0]=0;
|
||||||
|
if(!c)
|
||||||
|
c = ss;
|
||||||
|
int n=max((int)strlen(c)+1, ncharReser);
|
||||||
|
cuida_memoria(n);
|
||||||
|
(*ind)[n_i]=n_str;
|
||||||
|
n_i++;
|
||||||
|
strcpy(&str[n_str],c);
|
||||||
|
n_str+=n;
|
||||||
|
}
|
||||||
|
|
||||||
|
//**************************************************************************
|
||||||
|
void StrArray::compacta()
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
for (int j=0; j<n_i; j++)
|
||||||
|
{
|
||||||
|
if ((*ind)[j]==i)
|
||||||
|
{
|
||||||
|
i+=(int)strlen(get(j))+1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy(&str[i],get(j));
|
||||||
|
(*ind)[j]=i;
|
||||||
|
i+=(int)strlen(&str[i])+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n_str=i;
|
||||||
|
str=(char*)realloc(str, n_str);
|
||||||
|
|
||||||
|
m_str=n_str;
|
||||||
|
ind=(int (*)[])realloc(ind, n_i*sizeof(int));
|
||||||
|
m_i=n_i;
|
||||||
|
if (!str || !ind)
|
||||||
|
{
|
||||||
|
m_i=n_i=n_str=m_str=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void StrArray::borra( int i )
|
||||||
|
{
|
||||||
|
if (i<0 || i>=n_i)
|
||||||
|
return;
|
||||||
|
if ((i+1)<n_i)
|
||||||
|
memcpy(&(*ind)[i],&(*ind)[i+1], sizeof(int)*(n_i-(i+1)));
|
||||||
|
n_i--;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
StrArray* StrArray::filtra( StrArray*buf, char *filter )
|
||||||
|
{
|
||||||
|
char *st;
|
||||||
|
for(int i =0; i<n_i; i++)
|
||||||
|
{
|
||||||
|
st = get(i);
|
||||||
|
if(strstr(st,filter))
|
||||||
|
buf->add(st);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef StrArray_h
|
||||||
|
#define StrArray_H
|
||||||
|
|
||||||
|
#include "base_head.h"
|
||||||
|
class UTILES_EXPORT StrArray
|
||||||
|
{
|
||||||
|
//variables------------------------------
|
||||||
|
int incremento_char;
|
||||||
|
int incremento_str;
|
||||||
|
public:
|
||||||
|
char *str;
|
||||||
|
int n_str;//numero de chars
|
||||||
|
int m_str;//memoria reser
|
||||||
|
int (*ind)[];
|
||||||
|
int n_i;//numero de str
|
||||||
|
int m_i;//memoria reser
|
||||||
|
//constructor----------------------------
|
||||||
|
public:
|
||||||
|
StrArray(void);
|
||||||
|
~StrArray(void);
|
||||||
|
//funciones------------------------------
|
||||||
|
char* get(int i);//da string i
|
||||||
|
void add(char*c);//mete str
|
||||||
|
void add(char*c, int ncharReser);//mete str y reserva en memoria un minimo de ncharReser;
|
||||||
|
void add( StrArray* st );//mete un array entero de caracteres
|
||||||
|
void borra(int i);//borra el elemento iesimo
|
||||||
|
int size();//da numero de str
|
||||||
|
void borra();//borra todo
|
||||||
|
void compacta();//reduce al minimo la memoria necesaria para comtener la informacion
|
||||||
|
StrArray* filtra(StrArray*buf, char *filter);
|
||||||
|
//funciones aux-------------------------
|
||||||
|
private:
|
||||||
|
void cuida_memoria(int n,int ni=1);//asegura tener memoria para un str mas
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "TaskProcess.h"
|
||||||
|
#include "Csock_cl.h"
|
||||||
|
//***********************************************************************************************
|
||||||
|
TaskProcess::TaskProcess(void)
|
||||||
|
{
|
||||||
|
sc = NULL;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
TaskProcess::~TaskProcess(void)
|
||||||
|
{
|
||||||
|
desconecta();
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
bool TaskProcess::conecta( char* url, int port )
|
||||||
|
{
|
||||||
|
sc= new Csock_cl(NULL);
|
||||||
|
if(!sc->Create())
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//conectamos------------------------------------------
|
||||||
|
if (!sc->conectar(url, port))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
void TaskProcess::desconecta()
|
||||||
|
{
|
||||||
|
if (sc)
|
||||||
|
{
|
||||||
|
sc->Close();
|
||||||
|
delete sc;
|
||||||
|
sc=NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
bool TaskProcess::initTask( char* ip, int port, __int64 timer )
|
||||||
|
{
|
||||||
|
pirate = false;
|
||||||
|
if(!conecta(ip, port))
|
||||||
|
return false;
|
||||||
|
preTask();
|
||||||
|
if(!pirate)
|
||||||
|
lanza();
|
||||||
|
__int64 t1=_time64(NULL);
|
||||||
|
__int64 t2;
|
||||||
|
while(!pirate && isRunning())
|
||||||
|
{
|
||||||
|
t2 = _time64(NULL);
|
||||||
|
if((t2-t1)>=timer)
|
||||||
|
{
|
||||||
|
inTask();
|
||||||
|
t1 = t2;
|
||||||
|
}
|
||||||
|
Sleep(min(100, (int)size_t(timer/10)));
|
||||||
|
}
|
||||||
|
join();
|
||||||
|
postTask();
|
||||||
|
desconecta();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
bool TaskProcess::envia( void * buf, int nb )
|
||||||
|
{
|
||||||
|
if (sc)
|
||||||
|
return sc->envia_package((BYTE*)buf,nb)==TRUE;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
void* TaskProcess::recibe(int *nb )
|
||||||
|
{
|
||||||
|
*nb = 0;
|
||||||
|
if (!sc)
|
||||||
|
return NULL;
|
||||||
|
if(!sc->recibe_package(0))
|
||||||
|
return NULL;
|
||||||
|
*nb =sc->nb;
|
||||||
|
|
||||||
|
return (void*)sc->buf;
|
||||||
|
}
|
||||||
|
//***********************************************************************************************
|
||||||
|
void TaskProcess::cancela()
|
||||||
|
{
|
||||||
|
pirate = true;
|
||||||
|
desconecta();
|
||||||
|
}
|
||||||
|
|
||||||
|
//***********************************************************************************************
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
#pragma once
|
||||||
|
#include <base_head.h>
|
||||||
|
#include "th.h"
|
||||||
|
#ifndef TaskProcess_h
|
||||||
|
#define TaskProcess_h
|
||||||
|
/*
|
||||||
|
Tarea delegada en otro proceso(normalmente en programa de consola)
|
||||||
|
definir en funcion override run la tarea
|
||||||
|
*/
|
||||||
|
class Csock_cl;
|
||||||
|
class UTILES_EXPORT TaskProcess: public Cth
|
||||||
|
{
|
||||||
|
Csock_cl *sc;
|
||||||
|
public:
|
||||||
|
bool pirate;//indica que hay que irse
|
||||||
|
|
||||||
|
TaskProcess(void);
|
||||||
|
~TaskProcess(void);
|
||||||
|
bool initTask(char* url, int port, __int64 timer);
|
||||||
|
bool envia(void * buf, int nb);//envia buffer al proceso principal
|
||||||
|
void* recibe(int *nb );//recibe del proceso principal nb da el numero de bytes recib
|
||||||
|
//overrides----------------------------------
|
||||||
|
void cancela();//cancela tarea;
|
||||||
|
virtual void preTask()=0;
|
||||||
|
virtual void inTask()=0;
|
||||||
|
virtual void postTask()=0;
|
||||||
|
|
||||||
|
virtual bool conecta(char* url, int port);
|
||||||
|
virtual void desconecta();
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "_app.h"
|
||||||
|
|
||||||
|
C_app *C_app::p_app=NULL;
|
||||||
|
//****************************************************
|
||||||
|
C_app::C_app(void)
|
||||||
|
{
|
||||||
|
pirate=FALSE;
|
||||||
|
nth=0;
|
||||||
|
C_app::p_app=this;
|
||||||
|
|
||||||
|
}
|
||||||
|
//****************************************************
|
||||||
|
C_app::~C_app(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//****************************************************
|
||||||
|
BOOL C_app::inicio()
|
||||||
|
{
|
||||||
|
archi.rellena_dirs_ejecucion();
|
||||||
|
if (!on_inicia())
|
||||||
|
{
|
||||||
|
CWnd *Msg = new CWnd;
|
||||||
|
Msg->MessageBox(er.msg,er.modulo);
|
||||||
|
if (log.path[0])
|
||||||
|
{
|
||||||
|
log.loguea(&er);
|
||||||
|
}
|
||||||
|
delete Msg;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
// ****************************************************
|
||||||
|
int C_app::fin()
|
||||||
|
{
|
||||||
|
pirate=true;
|
||||||
|
if (!on_cierra())
|
||||||
|
{
|
||||||
|
CWnd *Msg = new CWnd;
|
||||||
|
Msg->MessageBox(er.msg,er.modulo);
|
||||||
|
delete Msg;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
while (nth>0)
|
||||||
|
Sleep(50);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//****************************************************
|
||||||
|
void C_app::cierra()
|
||||||
|
{
|
||||||
|
//this->PostMessage(WM_CLOSE,0,0);
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
//****************************************************
|
||||||
|
BOOL C_app::on_inicia()
|
||||||
|
{
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//****************************************************
|
||||||
|
BOOL C_app::on_cierra()
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//****************************************************
|
||||||
|
void C_app::suma_th()
|
||||||
|
{
|
||||||
|
long aux;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
aux=nth;
|
||||||
|
if(aux==InterlockedExchange(&nth,aux+1))
|
||||||
|
break;
|
||||||
|
Sleep(1);
|
||||||
|
} while (TRUE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************************
|
||||||
|
void C_app::resta_th()
|
||||||
|
{
|
||||||
|
long aux;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
aux=nth;
|
||||||
|
if(aux==InterlockedExchange(&nth,aux-1))
|
||||||
|
break;
|
||||||
|
Sleep(1);
|
||||||
|
} while (TRUE);
|
||||||
|
}
|
||||||
|
//****************************************************
|
||||||
|
C_app* C_app::GetApp()
|
||||||
|
{
|
||||||
|
if(!C_app::p_app)
|
||||||
|
C_app::p_app = new C_app();
|
||||||
|
return C_app::p_app;
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************************
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include <afxwinappex.h>
|
||||||
|
#include "_error.h"
|
||||||
|
#include "dir_manager.h"
|
||||||
|
#include "_log.h"
|
||||||
|
|
||||||
|
class UTILES_EXPORT C_app //clase aplicacion----
|
||||||
|
{
|
||||||
|
static C_app *p_app;//puntero a la clase aplicacion
|
||||||
|
|
||||||
|
public:
|
||||||
|
//variables globales-----------------------
|
||||||
|
Cdir_manager archi;//manager de archivos
|
||||||
|
C_log log;//clase de trazas (log)
|
||||||
|
C_error er;//clase de manejo de errores;
|
||||||
|
//variables de thread;
|
||||||
|
BOOL pirate;//indica a los thread que hay que irse
|
||||||
|
long nth;//indica el numero de thread que hay activos
|
||||||
|
C_app(void);
|
||||||
|
virtual ~C_app(void);
|
||||||
|
//funciones y overrides------------
|
||||||
|
static C_app* GetApp();
|
||||||
|
BOOL inicio();
|
||||||
|
int fin();
|
||||||
|
void suma_th();//añade al conteo de thread +1
|
||||||
|
void resta_th();//disminulle el conteo de thread en 1
|
||||||
|
virtual BOOL on_inicia();//funcion inicia lo necesario para el programa
|
||||||
|
virtual BOOL on_cierra();//funcion que se ejecuta al final del todo antes de cerrar
|
||||||
|
|
||||||
|
virtual void cierra();//fuerza el fin de la aplicacion;
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "_error.h"
|
||||||
|
//***********************************************************
|
||||||
|
|
||||||
|
C_error::C_error(void)
|
||||||
|
{
|
||||||
|
limpia();
|
||||||
|
}
|
||||||
|
//***********************************************************
|
||||||
|
C_error::~C_error(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//***********************************************************
|
||||||
|
void C_error::pon_win( char *modulo )
|
||||||
|
{
|
||||||
|
DWORD dw;
|
||||||
|
|
||||||
|
strcpy(this->modulo,modulo);
|
||||||
|
dw = GetLastError();
|
||||||
|
|
||||||
|
if(dw==NO_ERROR)
|
||||||
|
{
|
||||||
|
tipo=NO_ERROR;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormatMessage(
|
||||||
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL,
|
||||||
|
dw,
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
(LPTSTR) &msg,
|
||||||
|
256,
|
||||||
|
NULL );
|
||||||
|
tipo=(int)dw;
|
||||||
|
}
|
||||||
|
//***********************************************************
|
||||||
|
void C_error::pon( char *mod, char *mens, int tip/*=-1*/ )
|
||||||
|
{
|
||||||
|
strcpy(this->modulo,mod);
|
||||||
|
tipo=tipo;
|
||||||
|
strcpy(msg,mens);
|
||||||
|
}
|
||||||
|
//***********************************************************
|
||||||
|
void C_error::aclara( char *mens )
|
||||||
|
{
|
||||||
|
char str[256];
|
||||||
|
sprintf(str,"%s: %s",mens,msg);
|
||||||
|
strcpy(msg,str);
|
||||||
|
}
|
||||||
|
//***********************************************************
|
||||||
|
void C_error::limpia()
|
||||||
|
{
|
||||||
|
tipo=NO_ERROR;
|
||||||
|
msg[0]=0;
|
||||||
|
modulo[0]=0;
|
||||||
|
}
|
||||||
|
//***********************************************************
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
|
||||||
|
class UTILES_EXPORT C_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables-----------------------------
|
||||||
|
char modulo[32];//parte del programa que causa el error
|
||||||
|
char msg[256];//mensaje de error
|
||||||
|
int tipo;//codigo de error
|
||||||
|
//constructor---------------------------
|
||||||
|
C_error(void);
|
||||||
|
virtual ~C_error(void);
|
||||||
|
//funciones-----------------------------
|
||||||
|
void pon(char *mod, char *mens, int tip=-1);//pone error propio
|
||||||
|
void pon_win(char *modulo);//pone error windows
|
||||||
|
void aclara(char *mens);//pone aclaracion
|
||||||
|
void limpia();//limpia error
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "_log.h"
|
||||||
|
#include "_error.h"
|
||||||
|
#include "_app.h"
|
||||||
|
//***********************************************************************
|
||||||
|
C_log::C_log(void)
|
||||||
|
{
|
||||||
|
nombre[0]=0;
|
||||||
|
path[0]=0;
|
||||||
|
archivo_log=-1;
|
||||||
|
|
||||||
|
log_ext=NULL;
|
||||||
|
l_lisener=NULL;
|
||||||
|
}
|
||||||
|
//***********************************************************************
|
||||||
|
C_log::~C_log(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//***********************************************************************
|
||||||
|
|
||||||
|
void C_log::loguea(__time64_t tiemp, char *modulo, char *fmt)
|
||||||
|
{
|
||||||
|
char nfile[256], str[2048];
|
||||||
|
int k;
|
||||||
|
char mod[31];
|
||||||
|
CTime tiempo;
|
||||||
|
OFSTRUCT sarchivo;
|
||||||
|
CString texto;
|
||||||
|
char tiem[20];
|
||||||
|
|
||||||
|
if (log_ext)
|
||||||
|
log_ext(tiemp,modulo,fmt);
|
||||||
|
if (l_lisener)
|
||||||
|
l_lisener->log_ext(tiemp,modulo,fmt);
|
||||||
|
if (!nombre[0])
|
||||||
|
return;
|
||||||
|
|
||||||
|
cerrojo.entro();
|
||||||
|
//******************************
|
||||||
|
//TODO
|
||||||
|
/*va_start(arg_ptr, fmt);
|
||||||
|
_vsnprintf(buf,4090, fmt, arg_ptr);
|
||||||
|
va_end(arg_ptr);*/
|
||||||
|
|
||||||
|
texto = fmt;
|
||||||
|
tiempo = CTime::GetCurrentTime();
|
||||||
|
// Actualizar el fichero de LOG
|
||||||
|
//EnterCriticalSection(&sincro);
|
||||||
|
if (archivo_log < 0)
|
||||||
|
{
|
||||||
|
// Abrir fichero de LOG
|
||||||
|
nb=0;
|
||||||
|
if(path[0])
|
||||||
|
sprintf (nfile, "%s\\%s_%04ld_%02ld_%02ld_h%02ld.log", path,nombre,
|
||||||
|
tiempo.GetYear(),tiempo.GetMonth(),tiempo.GetDay(),tiempo.GetHour());
|
||||||
|
else
|
||||||
|
sprintf (nfile, "%s_%04ld_%02ld_%02ld_h%02ld.log", nombre,
|
||||||
|
tiempo.GetYear(),tiempo.GetMonth(),tiempo.GetDay(),tiempo.GetHour());
|
||||||
|
archivo_log = OpenFile( nfile, &sarchivo, OF_EXIST);
|
||||||
|
if ( archivo_log != -1)
|
||||||
|
{
|
||||||
|
archivo_log = OpenFile( nfile, &sarchivo, OF_WRITE);
|
||||||
|
SetFilePointer((HANDLE) (__int64) archivo_log,0,0,FILE_END);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
archivo_log = OpenFile( nfile, &sarchivo, OF_CREATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (archivo_log >= 0)
|
||||||
|
{
|
||||||
|
k = (int) strlen(texto);
|
||||||
|
int max = 2048 - 128;
|
||||||
|
if (k > (2048 - 128))
|
||||||
|
texto.SetAt(2048 - 128,0);
|
||||||
|
|
||||||
|
int st=(int)strlen(modulo);
|
||||||
|
for (int i=0; i<30; i++)
|
||||||
|
{
|
||||||
|
if (i<st)
|
||||||
|
mod[i]=*(modulo+i);
|
||||||
|
else
|
||||||
|
mod[i]=' ';
|
||||||
|
}
|
||||||
|
mod[30]='\0';
|
||||||
|
|
||||||
|
strftime(tiem, 20, "%Y-%m-%d %H:%M:%S", localtime(&tiemp));
|
||||||
|
sprintf_s(str,2048, "%s %-12s %s\r\n",
|
||||||
|
(char *) LPCTSTR (tiem),
|
||||||
|
(char *) LPCTSTR (mod),
|
||||||
|
(char *) LPCTSTR (texto));
|
||||||
|
nb+=(int)strlen(str);
|
||||||
|
_lwrite(archivo_log,str,(int)strlen(str));
|
||||||
|
|
||||||
|
if (nb>52428800)//mallor de 50 megas
|
||||||
|
{
|
||||||
|
strcpy(str,"Cierre de archivo, se creara uno nuevo para logear\r\n");
|
||||||
|
_lwrite(archivo_log,str,(int)strlen(str));
|
||||||
|
k = GetFileSize ((HANDLE) (__int64) archivo_log, NULL);
|
||||||
|
if (k > 200)
|
||||||
|
{
|
||||||
|
_lclose(archivo_log);
|
||||||
|
archivo_log = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
path[0]=0;
|
||||||
|
cerrojo.salgo();
|
||||||
|
}
|
||||||
|
//***********************************************************************
|
||||||
|
void C_log::loguea( char *modulo, char *fmt )
|
||||||
|
{
|
||||||
|
loguea(_time64(NULL),modulo,fmt);
|
||||||
|
}
|
||||||
|
//***********************************************************************
|
||||||
|
void C_log::loguea( C_error *er )
|
||||||
|
{
|
||||||
|
loguea(_time64(NULL),er->modulo,er->msg);
|
||||||
|
}
|
||||||
|
//***********************************************************************
|
||||||
|
void C_log::log( char *modulo, char *fmt,... )
|
||||||
|
{
|
||||||
|
if (C_app::GetApp())
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
int k;
|
||||||
|
va_list arg_ptr;
|
||||||
|
va_start(arg_ptr, fmt);
|
||||||
|
k = _vsnprintf(buf, 1020, fmt, arg_ptr);
|
||||||
|
va_end(arg_ptr);
|
||||||
|
if (k<0)
|
||||||
|
strcpy(&buf[1020], "...");
|
||||||
|
C_app::GetApp()->log.loguea(modulo, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//***********************************************************************
|
||||||
|
void C_log::log( C_error *er )
|
||||||
|
{
|
||||||
|
if (C_app::GetApp())
|
||||||
|
{
|
||||||
|
C_app::GetApp()->log.loguea(_time64(NULL),er->modulo,er->msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//***********************************************************************
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "lock.h"
|
||||||
|
#include <string>
|
||||||
|
typedef struct Msg_evento_log
|
||||||
|
{
|
||||||
|
int id_e;
|
||||||
|
char nivel[64];
|
||||||
|
char mensage[256];
|
||||||
|
__time64_t tiempo;
|
||||||
|
}Msg_evento_log;
|
||||||
|
class C_error;
|
||||||
|
class UTILES_EXPORT C_escucha_log//clase para escuchar eventos de log
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void log_ext(__time64_t tiemp, char *modulo, char *fmt)=0;
|
||||||
|
};
|
||||||
|
class UTILES_EXPORT C_log//clase para logear eventos
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variavles-----------------------------------------
|
||||||
|
HFILE archivo_log;
|
||||||
|
int nb;
|
||||||
|
Clock cerrojo;
|
||||||
|
C_escucha_log *l_lisener;//puntero a escucha actual
|
||||||
|
//BOOL log_consola;
|
||||||
|
char nombre[32];
|
||||||
|
char path[256];
|
||||||
|
|
||||||
|
void (*log_ext)(__time64_t tiemp, char *modulo, char *fmt);//funcion de log externa
|
||||||
|
C_log(void);
|
||||||
|
~C_log(void);
|
||||||
|
//funcion-------------------------------------------
|
||||||
|
void loguea(__time64_t tiemp, char *modulo, char *fmt);//añade un suceso
|
||||||
|
void loguea(char *modulo, char *fmt);//añade suceso actual
|
||||||
|
void loguea(C_error *er);//añade el error como suceso
|
||||||
|
static void log(char *modulo, char *fmt,...);//funcion estatica para loguear
|
||||||
|
static void log( C_error *er );
|
||||||
|
//static void log(std::string &mod, std::string &msg);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "_proceso.h"
|
||||||
|
|
||||||
|
C_proceso::C_proceso(void)
|
||||||
|
{
|
||||||
|
strcpy(nombre, "Proceso sin nombre");
|
||||||
|
m_thread=NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
C_proceso::~C_proceso(void)
|
||||||
|
{
|
||||||
|
join();
|
||||||
|
}
|
||||||
|
//**********************************************************************************************
|
||||||
|
void C_proceso::run()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//**********************************************************************************************
|
||||||
|
BOOL C_proceso::lanza( char *nombre/*=NULL*/ )
|
||||||
|
{
|
||||||
|
if (nombre)
|
||||||
|
strcpy(this->nombre,nombre);
|
||||||
|
m_thread = AfxBeginThread(main_c_proceso, this, THREAD_PRIORITY_NORMAL, 1024, CREATE_SUSPENDED);
|
||||||
|
m_thread->m_bAutoDelete=FALSE;
|
||||||
|
#ifdef _DEBUG
|
||||||
|
SetThreadName(m_thread->m_nThreadID,this->nombre);
|
||||||
|
#endif
|
||||||
|
m_thread->ResumeThread();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**********************************************************************************************
|
||||||
|
void C_proceso::join()
|
||||||
|
{
|
||||||
|
if (m_thread == NULL)
|
||||||
|
return;
|
||||||
|
WaitForSingleObject(m_thread->m_hThread,INFINITE);
|
||||||
|
delete m_thread;
|
||||||
|
m_thread = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//**********************************************************************************************
|
||||||
|
UINT main_c_proceso( LPVOID pp )
|
||||||
|
{
|
||||||
|
C_proceso *p=(C_proceso*)pp;
|
||||||
|
p->run();
|
||||||
|
AfxEndThread(0,FALSE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//**********************************************************************************************
|
||||||
|
UTILES_EXPORT void SetThreadName( DWORD dwThreadID, char* threadName)
|
||||||
|
{
|
||||||
|
THREADNAME_INFO info;
|
||||||
|
info.dwType = 0x1000;
|
||||||
|
info.szName = threadName;
|
||||||
|
info.dwThreadID = dwThreadID;
|
||||||
|
info.dwFlags = 0;
|
||||||
|
|
||||||
|
__try
|
||||||
|
{
|
||||||
|
RaiseException( MS_VC_EXCEPTION_PROCESO_UTILES, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
|
||||||
|
}
|
||||||
|
__except(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//**********************************************************************************************
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
|
||||||
|
const DWORD MS_VC_EXCEPTION_PROCESO_UTILES=0x406D1388;
|
||||||
|
|
||||||
|
#pragma pack(push,8)
|
||||||
|
typedef struct tagTHREADNAME_INFO
|
||||||
|
{
|
||||||
|
DWORD dwType; // Must be 0x1000.
|
||||||
|
LPCSTR szName; // Pointer to name (in user addr space).
|
||||||
|
DWORD dwThreadID; // Thread ID (-1=caller thread).
|
||||||
|
DWORD dwFlags; // Reserved for future use, must be zero.
|
||||||
|
} THREADNAME_INFO;
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
class UTILES_EXPORT C_proceso//proceso base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
C_proceso(void);
|
||||||
|
char nombre[32];
|
||||||
|
CWinThread * m_thread;
|
||||||
|
virtual ~C_proceso(void);
|
||||||
|
BOOL lanza(char *nombre=NULL);//lanzar thread
|
||||||
|
virtual void run();//funcion que hace el thread
|
||||||
|
void join();//espera al thread
|
||||||
|
};
|
||||||
|
UINT main_c_proceso(LPVOID pp);
|
||||||
|
UTILES_EXPORT void SetThreadName( DWORD dwThreadID, char* threadName);
|
||||||
|
|
@ -0,0 +1,797 @@
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "_zip.h"
|
||||||
|
#include "igt_error.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
//*****************************************************************************************************
|
||||||
|
Cigt_zip::Cigt_zip(void)
|
||||||
|
{
|
||||||
|
nivel_compresion=6;
|
||||||
|
uf=NULL;
|
||||||
|
zf=NULL;
|
||||||
|
igt_err=new Cigt_error();
|
||||||
|
borrar_error=TRUE;
|
||||||
|
nombre_zip[0]='\0';
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
Cigt_zip::Cigt_zip(Cigt_error *err)
|
||||||
|
{
|
||||||
|
nombre_zip[0]='\0';
|
||||||
|
nivel_compresion=6;
|
||||||
|
uf=NULL;
|
||||||
|
zf=NULL;
|
||||||
|
borrar_error=FALSE;
|
||||||
|
igt_err=err;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
Cigt_zip::~Cigt_zip(void)
|
||||||
|
{
|
||||||
|
cierra_zip();
|
||||||
|
if (borrar_error&&igt_err)
|
||||||
|
{
|
||||||
|
delete igt_err;
|
||||||
|
}
|
||||||
|
igt_err=NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
int Cigt_zip::isLargeFile(char* filename )
|
||||||
|
{
|
||||||
|
int largeFile = 0;
|
||||||
|
ZPOS64_T pos = 0;
|
||||||
|
FILE* pFile = fopen64(filename, "rb");
|
||||||
|
|
||||||
|
if(pFile != NULL)
|
||||||
|
{
|
||||||
|
int n = fseeko64(pFile, 0, SEEK_END);
|
||||||
|
|
||||||
|
pos = ftello64(pFile);
|
||||||
|
if(pos >= 0xffffffff)
|
||||||
|
largeFile = 1;
|
||||||
|
|
||||||
|
fclose(pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
return largeFile;
|
||||||
|
}
|
||||||
|
//**************************************************************************************************************
|
||||||
|
BOOL Cigt_zip::abre_zip( char *filename, int parametro )
|
||||||
|
{
|
||||||
|
int esc;
|
||||||
|
zlib_filefunc64_def ffunc;
|
||||||
|
fill_win32_filefunc64A(&ffunc);
|
||||||
|
if (parametro==READ)
|
||||||
|
{
|
||||||
|
cierra_zip_uf();
|
||||||
|
uf = new unzFile();
|
||||||
|
*uf = unzOpen2_64(filename,&ffunc);
|
||||||
|
if (uf==NULL)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
strcpy(nombre_zip,filename);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if (parametro==OWERWRITE)
|
||||||
|
{
|
||||||
|
esc=0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
esc=2;
|
||||||
|
cierra_zip_zf();
|
||||||
|
zf= new zipFile();
|
||||||
|
*zf = zipOpen2_64(filename,esc,NULL,&ffunc);//
|
||||||
|
if (zf == NULL)//
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
strcpy(nombre_zip,filename);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************
|
||||||
|
BOOL Cigt_zip::addfile(char *newfile, char *dir_in_zip )
|
||||||
|
{
|
||||||
|
FILE *fin;
|
||||||
|
int err=0,size_read=0;
|
||||||
|
int zip64=0;
|
||||||
|
zip_fileinfo zi;
|
||||||
|
unsigned long crcFile=0;
|
||||||
|
char *password=NULL;
|
||||||
|
int size_buf = WRITEBUFFERSIZE;
|
||||||
|
if (!zf)
|
||||||
|
{
|
||||||
|
igt_err->pon_error("Cigt_zip","puntero del handle nulo",-1);
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
void *buf = (void*)malloc(size_buf);
|
||||||
|
|
||||||
|
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
||||||
|
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
|
||||||
|
zi.dosDate = 0;
|
||||||
|
zi.internal_fa = 0;
|
||||||
|
zi.external_fa = 0;
|
||||||
|
filetime(newfile,&zi.tmz_date,(long*)&zi.dosDate);
|
||||||
|
err = getFileCrc(newfile,buf,size_buf,&crcFile);//preparamos crc
|
||||||
|
zip64 = isLargeFile(newfile);
|
||||||
|
err = zipOpenNewFileInZip3_64(*zf,dir_in_zip,&zi,
|
||||||
|
NULL,0,NULL,0,NULL /* comment*/,
|
||||||
|
8,nivel_compresion,0,
|
||||||
|
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
||||||
|
password,crcFile, zip64);//preparamos el zip
|
||||||
|
if (err != ZIP_OK)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fin = fopen64(newfile,"rb");//abre el archivo a meter en zip
|
||||||
|
if (fin==NULL)
|
||||||
|
{
|
||||||
|
err=ZIP_ERRNO;
|
||||||
|
//printf("error in opening %s for reading\n",newfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (err == ZIP_OK)
|
||||||
|
{
|
||||||
|
do// bucle para escribir el archivo en zip
|
||||||
|
{
|
||||||
|
err = ZIP_OK;
|
||||||
|
size_read = (int)fread(buf,1,size_buf,fin);//leemos parte
|
||||||
|
if (size_read < size_buf)
|
||||||
|
if (feof(fin)==0)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
err = ZIP_ERRNO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size_read>0)
|
||||||
|
{
|
||||||
|
err = zipWriteInFileInZip (*zf,buf,size_read);
|
||||||
|
if (err<0)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
err = ZIP_ERRNO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while ((err == ZIP_OK) && (size_read>0));
|
||||||
|
}
|
||||||
|
if (fin)
|
||||||
|
fclose(fin);//cierra el archivo metido
|
||||||
|
if (buf)
|
||||||
|
{
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
if (err<0)//si errores
|
||||||
|
return FALSE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::cierra_zip_zf()
|
||||||
|
{
|
||||||
|
int errclose= ZIP_OK;
|
||||||
|
if(zf)
|
||||||
|
{
|
||||||
|
errclose = zipClose(*zf,NULL);
|
||||||
|
if (errclose != ZIP_OK)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
zf=NULL;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
/* calculate the CRC32 of a file,
|
||||||
|
because to encrypt a file, we need known the CRC32 of the file before */
|
||||||
|
int Cigt_zip::getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
|
||||||
|
{
|
||||||
|
unsigned long calculate_crc=0;
|
||||||
|
int err=ZIP_OK;
|
||||||
|
FILE * fin = fopen64(filenameinzip,"rb");
|
||||||
|
unsigned long size_read = 0;
|
||||||
|
unsigned long total_read = 0;
|
||||||
|
if (fin==NULL)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
err = ZIP_ERRNO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == ZIP_OK)
|
||||||
|
do
|
||||||
|
{
|
||||||
|
err = ZIP_OK;
|
||||||
|
size_read = (int)fread(buf,1,size_buf,fin);
|
||||||
|
if (size_read < size_buf)
|
||||||
|
if (feof(fin)==0)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
err = ZIP_ERRNO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size_read>0)
|
||||||
|
calculate_crc = crc32(calculate_crc,(Bytef*)buf,size_read);
|
||||||
|
total_read += size_read;
|
||||||
|
|
||||||
|
} while ((err == ZIP_OK) && (size_read>0));
|
||||||
|
|
||||||
|
if (fin)
|
||||||
|
fclose(fin);
|
||||||
|
|
||||||
|
*result_crc=calculate_crc;
|
||||||
|
//printf("file %s crc %lx\n", filenameinzip, calculate_crc);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
int Cigt_zip::filetime( char *f, tm_zip *tmzip, long *dt_ )
|
||||||
|
{
|
||||||
|
uLong *dt=(uLong *)dt_;
|
||||||
|
int ret = 0;
|
||||||
|
{
|
||||||
|
FILETIME ftLocal;
|
||||||
|
HANDLE hFind;
|
||||||
|
WIN32_FIND_DATAA ff32;
|
||||||
|
hFind = FindFirstFileA(f,&ff32);
|
||||||
|
if (hFind != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
|
||||||
|
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
|
||||||
|
FindClose(hFind);
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::cierra_zip()
|
||||||
|
{
|
||||||
|
BOOL resul;
|
||||||
|
resul=cierra_zip_uf();
|
||||||
|
return cierra_zip_zf() && resul;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::descomprimir(char *file, char *fileout,BYTE **bufex,int *nb )
|
||||||
|
{
|
||||||
|
FILE *fout=NULL;
|
||||||
|
int err = UNZ_OK;
|
||||||
|
int mb;
|
||||||
|
BYTE (*bufsal)[];
|
||||||
|
bufsal=NULL;
|
||||||
|
int size_buf=0;
|
||||||
|
const char* password=NULL;
|
||||||
|
//zlib_filefunc64_def ffunc;
|
||||||
|
void *buf;
|
||||||
|
unz_file_info64 file_info;
|
||||||
|
char path_inzip[256];
|
||||||
|
if (!uf)
|
||||||
|
{
|
||||||
|
igt_err->pon_error("Cigt_zip","Error al descomprimir: puntero del handle uf nulo",-1);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//int ret_value = do_extract_onefile(uf, file, 0, 0, "\0");
|
||||||
|
if (unzLocateFile(uf,file,CASESENSITIVITY)!=UNZ_OK)//comprueba que esta el archivo en el zip
|
||||||
|
{
|
||||||
|
char str[250];
|
||||||
|
sprintf(str,"Cigt_zip","Error al descomprimir: el archivo %s no se encuentra en el zip",file);
|
||||||
|
igt_err->pon_error("Cigt_zip",str,-1);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
err = unzGetCurrentFileInfo64(uf,&file_info,path_inzip,sizeof(path_inzip),NULL,0,NULL,0);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_buf = WRITEBUFFERSIZE;
|
||||||
|
buf = (void*)malloc(size_buf);
|
||||||
|
if (buf==NULL)
|
||||||
|
{
|
||||||
|
char str[256];
|
||||||
|
sprintf(str,"Cigt_zip","Error al descomprimir: no se puede reservar memoria para buf de %ld bytes",size_buf);
|
||||||
|
igt_err->pon_error("Cigt_zip",str,-1);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
err = unzOpenCurrentFilePassword(uf,password);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (fileout)
|
||||||
|
fout=fopen64(fileout,"wb");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*nb=0;
|
||||||
|
mb=WRITEBUFFERSIZE*5;
|
||||||
|
bufsal = (BYTE (*)[])malloc(mb);
|
||||||
|
}
|
||||||
|
/* some zipfile don't contain directory alone before file */
|
||||||
|
if (fout!=NULL||!fileout)
|
||||||
|
{
|
||||||
|
do//bucle para escribir archivo
|
||||||
|
{
|
||||||
|
err = unzReadCurrentFile(uf,buf,size_buf);
|
||||||
|
if (err<0)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (err>0)
|
||||||
|
if(fileout)
|
||||||
|
{
|
||||||
|
if (fwrite(buf,err,1,fout)!=1)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
err=UNZ_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((*nb+err)>=mb)
|
||||||
|
{
|
||||||
|
mb+=WRITEBUFFERSIZE*5;
|
||||||
|
bufsal=(BYTE(*)[])realloc(bufsal,mb);
|
||||||
|
}
|
||||||
|
memcpy(&(*bufsal)[*nb],buf,err);
|
||||||
|
*nb+=err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (err>0);
|
||||||
|
}
|
||||||
|
if (fout)
|
||||||
|
fclose(fout);
|
||||||
|
free(buf);
|
||||||
|
if (err==UNZ_OK)
|
||||||
|
{
|
||||||
|
if (fileout)
|
||||||
|
{
|
||||||
|
change_file_date(fileout,file_info.dosDate,
|
||||||
|
file_info.tmu_date);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*bufex=(BYTE*)bufsal;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if (bufsal)
|
||||||
|
{
|
||||||
|
free(bufsal);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::descomprimir()
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
Zip_struct (*contenido)[];
|
||||||
|
contenido= (Zip_struct(*)[])listar(&n);
|
||||||
|
if (n<=0)
|
||||||
|
return FALSE;
|
||||||
|
for (int i=0; i<n;i++)
|
||||||
|
{
|
||||||
|
if (!descomprimir2file((*contenido)[i].nombre))
|
||||||
|
{
|
||||||
|
free(contenido);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(contenido);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
void Cigt_zip::change_file_date(const char *filename,uLong dosdate,tm_unz tmu_date)
|
||||||
|
{
|
||||||
|
HANDLE hFile;
|
||||||
|
FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
|
||||||
|
|
||||||
|
hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
|
||||||
|
0,NULL,OPEN_EXISTING,0,NULL);
|
||||||
|
GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
|
||||||
|
DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
|
||||||
|
LocalFileTimeToFileTime(&ftLocal,&ftm);
|
||||||
|
SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
|
||||||
|
CloseHandle(hFile);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::descomprimir2file( char *file,char *fileout )
|
||||||
|
{
|
||||||
|
if (fileout)
|
||||||
|
return descomprimir(file,fileout,NULL,NULL);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::descomprimir2file( char *file )
|
||||||
|
{
|
||||||
|
char fileout[256];
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
strcpy(fileout,nombre_zip);
|
||||||
|
for (i=strlen(fileout);i>=0;i--)
|
||||||
|
{
|
||||||
|
if(fileout[i]=='\\')
|
||||||
|
{
|
||||||
|
fileout[i]='\\';
|
||||||
|
i++;
|
||||||
|
fileout[i]='\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i<0)
|
||||||
|
i=0;
|
||||||
|
for(j=0; *(file+j); j++)
|
||||||
|
{
|
||||||
|
if (*(file+j)=='\\')
|
||||||
|
{
|
||||||
|
*(fileout+j+i)='\0';
|
||||||
|
if(!crea_dir(fileout))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*(fileout+j+i)=*(file+j);
|
||||||
|
}
|
||||||
|
*(fileout+j+i)='\0';
|
||||||
|
return descomprimir2file(file,fileout);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::descomprimir2buff(char *file,BYTE **buf,int *nb )
|
||||||
|
{
|
||||||
|
return descomprimir(file,NULL,buf,nb);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
Zip_struct* Cigt_zip::listar(int* n)
|
||||||
|
{
|
||||||
|
int err = UNZ_OK;
|
||||||
|
//zlib_filefunc64_def ffunc;
|
||||||
|
unz_file_info64 file_info;
|
||||||
|
uLong i;
|
||||||
|
unz_global_info64 gi;
|
||||||
|
//char path_inzip[256];
|
||||||
|
*n=0;
|
||||||
|
Zip_struct (*salida)[];
|
||||||
|
salida=NULL;
|
||||||
|
|
||||||
|
err = unzGetGlobalInfo64(uf,&gi);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
}
|
||||||
|
if (gi.number_entry<=0)
|
||||||
|
{
|
||||||
|
igt_err->pon_error("Cigt_zip","Error en listar: en número de archivos del zip es <=0");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
salida=(Zip_struct(*)[])malloc(sizeof(Zip_struct)*gi.number_entry);
|
||||||
|
*n=gi.number_entry;
|
||||||
|
for (i=0;i<gi.number_entry;i++)
|
||||||
|
{
|
||||||
|
err = unzGetCurrentFileInfo64(uf,&file_info,(*salida)[i].nombre,sizeof((*salida)[i].nombre),NULL,0,NULL,0);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (file_info.uncompressed_size>0)
|
||||||
|
{
|
||||||
|
(*salida)[i].ratio = (int)((file_info.compressed_size*100)/file_info.uncompressed_size);
|
||||||
|
(*salida)[i].size_descom=(int)file_info.uncompressed_size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*salida)[i].ratio = 0;
|
||||||
|
(*salida)[i].size_descom=0;
|
||||||
|
}
|
||||||
|
/* display a '*' if the file is crypted */
|
||||||
|
if ((file_info.flag & 1) != 0)
|
||||||
|
(*salida)[i].encript=TRUE;
|
||||||
|
else
|
||||||
|
(*salida)[i].encript=FALSE;
|
||||||
|
|
||||||
|
(*salida)[i].compresion=file_info.compression_method;
|
||||||
|
(*salida)[i].size=file_info.compressed_size;
|
||||||
|
|
||||||
|
if ((i+1)<gi.number_entry)
|
||||||
|
{
|
||||||
|
err = unzGoToNextFile(uf);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (Zip_struct *)salida;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::cierra_zip_uf()
|
||||||
|
{
|
||||||
|
int err=UNZ_OK;
|
||||||
|
if (uf)
|
||||||
|
{
|
||||||
|
err = unzCloseCurrentFile (uf);
|
||||||
|
if (err!=UNZ_OK)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
uf=NULL;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::crea_dir( char *dir )
|
||||||
|
{
|
||||||
|
int k;
|
||||||
|
int err=mkdir(dir);
|
||||||
|
if (err<0)
|
||||||
|
{
|
||||||
|
k=errno;
|
||||||
|
if(k!=EEXIST)
|
||||||
|
{
|
||||||
|
igt_err->pon_error("Cigt_zip","Error al crear carpeta: carpeta no encontrada",k);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL Cigt_zip::abre_zip_temp()
|
||||||
|
{
|
||||||
|
char szTempFileName[256];
|
||||||
|
char lpTempPathBuffer[256];
|
||||||
|
//char chBuffer[512];
|
||||||
|
//LPCTSTR errMsg;
|
||||||
|
DWORD dwRetVal = 0;
|
||||||
|
// Gets the temp path env string (no guarantee it's a valid path).
|
||||||
|
dwRetVal = GetTempPath(MAX_PATH, // length of the buffer
|
||||||
|
lpTempPathBuffer); // buffer for path
|
||||||
|
if (dwRetVal > MAX_PATH || (dwRetVal == 0))
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates a temporary file name.
|
||||||
|
dwRetVal = GetTempFileName(lpTempPathBuffer, // directory for tmp files
|
||||||
|
"DEMO", // temp file name prefix
|
||||||
|
0, // create unique name
|
||||||
|
szTempFileName); // buffer for name
|
||||||
|
if (dwRetVal == 0)
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("Cigt_zip",igt_err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return abre_zip(szTempFileName,OWERWRITE);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL lista_file_dir( char *dir,Cstr_array *lista_file, Cigt_error *err)
|
||||||
|
{
|
||||||
|
return lista_file_dir(dir,NULL,lista_file,err);
|
||||||
|
/*
|
||||||
|
BOOL poner_error;
|
||||||
|
char str[256];
|
||||||
|
//int k;
|
||||||
|
WIN32_FIND_DATA filedat;
|
||||||
|
HANDLE hfile;
|
||||||
|
if (err)
|
||||||
|
poner_error=TRUE;
|
||||||
|
else
|
||||||
|
poner_error=FALSE;
|
||||||
|
if (!lista_file)
|
||||||
|
{
|
||||||
|
err->pon_error("lista_file_dir","Puntero de lista_file nulo",-1);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(str,dir);
|
||||||
|
if (str[strlen(str)-1] != '\\')
|
||||||
|
strcat(str,"\\");
|
||||||
|
strcat(str,"*.*");
|
||||||
|
hfile = FindFirstFile(str,&filedat);
|
||||||
|
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)//existe dir
|
||||||
|
{
|
||||||
|
// existe el dir
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ((strcmp(filedat.cFileName,".") != 0) &&
|
||||||
|
(strcmp(filedat.cFileName,"..") != 0))
|
||||||
|
{
|
||||||
|
strcpy(str,dir);
|
||||||
|
if (str[strlen(str)-1] != '\\')
|
||||||
|
strcat(str,"\\");
|
||||||
|
strcat(str,filedat.cFileName);
|
||||||
|
if (filedat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
if(!lista_file_dir( str, lista_file, err))
|
||||||
|
{
|
||||||
|
FindClose(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lista_file->pon_str(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (FindNextFile(hfile,&filedat));
|
||||||
|
FindClose(hfile);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (poner_error)
|
||||||
|
Igt_error::pon_winerror("lista_file_dir",err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL lista_file_dir( char *dir,char *omite,Cstr_array *lista_file,Cigt_error *err )
|
||||||
|
{
|
||||||
|
BOOL poner_error;
|
||||||
|
char str[256];
|
||||||
|
//int k;
|
||||||
|
WIN32_FIND_DATA filedat;
|
||||||
|
HANDLE hfile;
|
||||||
|
if (err)
|
||||||
|
poner_error=TRUE;
|
||||||
|
else
|
||||||
|
poner_error=FALSE;
|
||||||
|
if (!lista_file)
|
||||||
|
{
|
||||||
|
err->pon_error("lista_file_dir","Puntero de lista_file nulo",-1);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(str,dir);
|
||||||
|
if (str[strlen(str)-1] != '\\')
|
||||||
|
strcat(str,"\\");
|
||||||
|
strcat(str,"*.*");
|
||||||
|
hfile = FindFirstFile(str,&filedat);
|
||||||
|
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)//existe dir
|
||||||
|
{
|
||||||
|
// existe el dir
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ((strcmp(filedat.cFileName,".") != 0) &&
|
||||||
|
(strcmp(filedat.cFileName,"..") != 0))
|
||||||
|
{
|
||||||
|
if (!omite||strcmp(omite,filedat.cFileName)!=0)
|
||||||
|
{
|
||||||
|
strcpy(str,dir);
|
||||||
|
if (str[strlen(str)-1] != '\\')
|
||||||
|
strcat(str,"\\");
|
||||||
|
strcat(str,filedat.cFileName);
|
||||||
|
if (filedat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
if(!lista_file_dir( str,NULL, lista_file, err))
|
||||||
|
{
|
||||||
|
FindClose(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lista_file->pon_str(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (FindNextFile(hfile,&filedat));
|
||||||
|
FindClose(hfile);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (poner_error)
|
||||||
|
Cigt_error::pon_winerror("lista_file_dir",err);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL es_dir(char *dir)
|
||||||
|
{
|
||||||
|
WIN32_FIND_DATA filedat;
|
||||||
|
HANDLE hfile;
|
||||||
|
hfile = FindFirstFile(dir,&filedat);
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)//existe dir
|
||||||
|
{
|
||||||
|
if (filedat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
FindClose(hfile);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
FindClose(hfile);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
BOOL del_File(char *file,Cigt_error *err)
|
||||||
|
{
|
||||||
|
//borra archivos y carpetas
|
||||||
|
BOOL poner_error;
|
||||||
|
char str[256];
|
||||||
|
int n_aux;
|
||||||
|
//int k;
|
||||||
|
WIN32_FIND_DATA filedat;
|
||||||
|
HANDLE hfile;
|
||||||
|
if (err)
|
||||||
|
poner_error=TRUE;
|
||||||
|
else
|
||||||
|
poner_error=FALSE;
|
||||||
|
n_aux=strlen(file);
|
||||||
|
|
||||||
|
if (n_aux<3)
|
||||||
|
{
|
||||||
|
if (poner_error)
|
||||||
|
{
|
||||||
|
sprintf(str,"Error al borrar archivo: %s. Borrar este archivo puede ser peligroso");
|
||||||
|
err->pon_error("del_File",str,-1);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
strcpy(str,file);
|
||||||
|
if (str[strlen(str)-1] != '\\')
|
||||||
|
strcat(str,"\\");
|
||||||
|
strcat(str,"*.*");
|
||||||
|
hfile = FindFirstFile(str,&filedat);
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
// existe el dir
|
||||||
|
// borralo y usalo
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ((strcmp(filedat.cFileName,".") != 0) &&
|
||||||
|
(strcmp(filedat.cFileName,"..") != 0))
|
||||||
|
{
|
||||||
|
strcpy(str,file);
|
||||||
|
if (str[strlen(str)-1] != '\\')
|
||||||
|
strcat(str,"\\");
|
||||||
|
strcat(str,filedat.cFileName);
|
||||||
|
if (filedat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
if(!del_File(str,err))
|
||||||
|
{
|
||||||
|
FindClose(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetFileAttributes(str,FILE_ATTRIBUTE_NORMAL);
|
||||||
|
if (!DeleteFile(str))
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("del_File",err);
|
||||||
|
FindClose(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (FindNextFile(hfile,&filedat));
|
||||||
|
FindClose(hfile);
|
||||||
|
if (!RemoveDirectory(file))
|
||||||
|
{
|
||||||
|
Cigt_error::pon_winerror("del_File",err);
|
||||||
|
FindClose(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
#pragma once
|
||||||
|
#define USEWIN32IOAPI
|
||||||
|
|
||||||
|
/*
|
||||||
|
#ifndef _WIN32
|
||||||
|
#ifndef __USE_FILE_OFFSET64
|
||||||
|
#define __USE_FILE_OFFSET64
|
||||||
|
#endif
|
||||||
|
#ifndef __USE_LARGEFILE64
|
||||||
|
#define __USE_LARGEFILE64
|
||||||
|
#endif
|
||||||
|
#ifndef _LARGEFILE64_SOURCE
|
||||||
|
#define _LARGEFILE64_SOURCE
|
||||||
|
#endif
|
||||||
|
#ifndef _FILE_OFFSET_BIT
|
||||||
|
#define _FILE_OFFSET_BIT 64
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
#include "zconf.h"
|
||||||
|
#include "zip.h"
|
||||||
|
#include "unzip.h"
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define USEWIN32IOAPI
|
||||||
|
#include "iowin32.h"
|
||||||
|
#endif
|
||||||
|
#define WRITEBUFFERSIZE (8192)
|
||||||
|
#define MAXFILENAME (256)
|
||||||
|
#define CASESENSITIVITY (0)
|
||||||
|
|
||||||
|
typedef struct Zip_struct
|
||||||
|
{
|
||||||
|
char nombre[256];
|
||||||
|
int size;
|
||||||
|
int size_descom;
|
||||||
|
int ratio;
|
||||||
|
int compresion;
|
||||||
|
BOOL encript;
|
||||||
|
}Zip_struct;
|
||||||
|
class Cigt_error;
|
||||||
|
class C_zip
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
READ,
|
||||||
|
WRITE,
|
||||||
|
OWERWRITE
|
||||||
|
};
|
||||||
|
Cigt_error *igt_err;
|
||||||
|
char nombre_zip[256];
|
||||||
|
zipFile *zf;
|
||||||
|
unzFile *uf;
|
||||||
|
Cigt_zip(void);
|
||||||
|
Cigt_zip(Cigt_error *err);
|
||||||
|
~Cigt_zip(void);
|
||||||
|
BOOL borrar_error;
|
||||||
|
|
||||||
|
int nivel_compresion;//nivel de compresion
|
||||||
|
BOOL abre_zip(char *filename,int parametro);//abre zip y deja el handle en zf
|
||||||
|
BOOL addfile(char *newfile,char *dir_in_zip);//introduce el archivo newfile con dir dentro del zip dir_in_zip
|
||||||
|
BOOL descomprimir2file(char *file,char *fileout);//descomprime el archivo file y lo pone en archivo fileout
|
||||||
|
BOOL descomprimir2file(char *file);//Descomprime el archivo file y lo pone en la ruta relativa del zip
|
||||||
|
BOOL descomprimir2buff(char *file,BYTE **buf,int *nb );//Descomprime el archivo file y lo carga en buf
|
||||||
|
BOOL descomprimir();//Descomprime el zip entero y lo pone en la ruta relativa del zip;
|
||||||
|
Zip_struct* listar(int* n);//devuelve una estructura con informacion del contenido del zip,sinedo n el numero de archivos en el zip
|
||||||
|
BOOL cierra_zip();//Cierra handle
|
||||||
|
BOOL abre_zip_temp();//Crea un archivo vacio en la carpeta temporal de windows (el Path del archivo se puede obtener de la variable nombre_zip)
|
||||||
|
private:
|
||||||
|
BOOL crea_dir(char *dir);
|
||||||
|
BOOL descomprimir(char *file,char *fileout,BYTE **bufex,int *n);//descomprime del archivo filezip el archivo file y lo pone en dirout o en el bufex si dirout==NULL
|
||||||
|
BOOL cierra_zip_zf();//cierra el handle escritura
|
||||||
|
BOOL cierra_zip_uf();//cierra handle lectura
|
||||||
|
//funciones auxiliares
|
||||||
|
int isLargeFile(char* filename);
|
||||||
|
int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc);
|
||||||
|
int filetime(char *f, tm_zip *tmzip, long *dt_);
|
||||||
|
void change_file_date(const char *filename,uLong dosdate,tm_unz tmu_date);
|
||||||
|
};
|
||||||
|
BOOL lista_file_dir(char *dir,Cstr_array *lista_file,Cigt_error *err);//Lista todos los archivos que contiene la carpeta dir
|
||||||
|
BOOL lista_file_dir(char *dir,char *omite, Cstr_array *lista_file,Cigt_error *err);//Lista todos los archivos que contiene la carpeta dir omitiendo "omite"
|
||||||
|
BOOL es_dir(char *dir);//Comprueba si dir es una carpeta
|
||||||
|
BOOL del_File(char *file,Cigt_error *err);//Borra todos los archivos que contiene la carpeta dir
|
||||||
|
|
@ -0,0 +1,190 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "ascii_file.h"
|
||||||
|
#include "_error.h"
|
||||||
|
#define MODULO_ASCII_FILE "Cascii_file"
|
||||||
|
//*************************************************************************************************
|
||||||
|
Cascii_file::Cascii_file(C_error* err)
|
||||||
|
{
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
b_er=FALSE;
|
||||||
|
er=err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
er= new C_error();
|
||||||
|
b_er=TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
Cascii_file::~Cascii_file(void)
|
||||||
|
{
|
||||||
|
if(b_er && er)
|
||||||
|
{
|
||||||
|
delete er;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
BOOL Cascii_file::lee( char* path)
|
||||||
|
{
|
||||||
|
char *buf=NULL;
|
||||||
|
char *s1;
|
||||||
|
char *s2;
|
||||||
|
borra();
|
||||||
|
HANDLE hfile=INVALID_HANDLE_VALUE;
|
||||||
|
DWORD dw,nb;
|
||||||
|
//abrimos archivo---------------------
|
||||||
|
|
||||||
|
hfile = CreateFile(path, GENERIC_READ, 0, NULL,
|
||||||
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_ASCII_FILE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nb=SetFilePointer(hfile,0,NULL,FILE_END);
|
||||||
|
if(nb==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_ASCII_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
buf=(char *)malloc(nb+2);
|
||||||
|
|
||||||
|
dw=SetFilePointer(hfile,0,NULL,FILE_BEGIN);
|
||||||
|
if(dw==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_ASCII_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
if (!ReadFile(hfile, (LPSTR) buf ,nb,&dw,NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_ASCII_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
buf[nb]=0;
|
||||||
|
buf[nb+1]=0;//aseguramos el final de la cadena;
|
||||||
|
s1=buf;
|
||||||
|
//procesamos-----------------------------------------------
|
||||||
|
while (*s1)
|
||||||
|
{
|
||||||
|
s2=busca_salto_linea(s1);
|
||||||
|
if (*s2)
|
||||||
|
{
|
||||||
|
*s2=0;
|
||||||
|
s2++;
|
||||||
|
while(*s2=='\r' ||*s2=='\n')
|
||||||
|
s2=s2+1;
|
||||||
|
}
|
||||||
|
if (strlen(s1)>0)
|
||||||
|
{
|
||||||
|
lineas.add(s1);
|
||||||
|
}
|
||||||
|
s1=s2;
|
||||||
|
}
|
||||||
|
free(buf);
|
||||||
|
return TRUE;
|
||||||
|
salgo:
|
||||||
|
if (hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
CloseHandle(hfile);
|
||||||
|
if (buf)
|
||||||
|
free(buf);
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
BOOL Cascii_file::guarda( char* path, BOOL ret_carro )
|
||||||
|
{
|
||||||
|
HANDLE hfile=INVALID_HANDLE_VALUE;
|
||||||
|
DWORD dw;
|
||||||
|
char* str;
|
||||||
|
int n= lineas.size();
|
||||||
|
char salto='\n';
|
||||||
|
char ret='\r';
|
||||||
|
/*
|
||||||
|
er->pon(MODULO_INI_FILE,"guarda: Función no implementada");
|
||||||
|
return FALSE;*/
|
||||||
|
//abrimos archivo-------------------------------
|
||||||
|
hfile=CreateFile(path,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
0, // exclusive access
|
||||||
|
NULL, // no security
|
||||||
|
CREATE_ALWAYS,
|
||||||
|
0, // no overlapped I/O
|
||||||
|
NULL); // null template
|
||||||
|
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_ASCII_FILE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//guardamos---------------------------------
|
||||||
|
for (int i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
str=lineas.get(i);
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
if(!WriteFile(hfile, str, sizeof(str), &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_ASCII_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
if (ret_carro)
|
||||||
|
{
|
||||||
|
if(!WriteFile(hfile, &ret, 1, &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_ASCII_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!WriteFile(hfile, &salto, 1, &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_ASCII_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//cerramos----------------------------------
|
||||||
|
if(hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
salgo:
|
||||||
|
if(hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
int Cascii_file::get()
|
||||||
|
{
|
||||||
|
return lineas.size();
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
char* Cascii_file::get( int i )
|
||||||
|
{
|
||||||
|
return lineas.get(i);
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
void Cascii_file::borra()
|
||||||
|
{
|
||||||
|
lineas.borra();
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
void Cascii_file::add( char* l )
|
||||||
|
{
|
||||||
|
lineas.add(l);
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
char* Cascii_file::busca_salto_linea( char* st )
|
||||||
|
{
|
||||||
|
char *s=st;
|
||||||
|
while(*s && *s!='\r' && *s!='\n' )
|
||||||
|
s=s+1;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "StrArray.h"
|
||||||
|
class C_error;
|
||||||
|
class UTILES_EXPORT Cascii_file
|
||||||
|
{
|
||||||
|
//variables------------------------------------------------
|
||||||
|
private:
|
||||||
|
StrArray lineas;
|
||||||
|
C_error *er;
|
||||||
|
BOOL b_er;
|
||||||
|
public:
|
||||||
|
Cascii_file(C_error* err=NULL);
|
||||||
|
~Cascii_file(void);
|
||||||
|
|
||||||
|
//funciones------------------------------------------------
|
||||||
|
|
||||||
|
BOOL lee(char* path);//lee un archivo
|
||||||
|
BOOL guarda(char* path,BOOL ret_carro=TRUE);//guarda un archivo
|
||||||
|
int get();//dice el numero de lineas
|
||||||
|
char* get(int i);//da la linea i-esima
|
||||||
|
void borra();//borra todo
|
||||||
|
void add(char* l);//añade linea
|
||||||
|
|
||||||
|
private:
|
||||||
|
char* busca_salto_linea(char*st);
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "b_file.h"
|
||||||
|
//******************************************************************************************************************
|
||||||
|
Cb_file::Cb_file(void)
|
||||||
|
{
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
er=NULL;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
Cb_file::~Cb_file(void)
|
||||||
|
{
|
||||||
|
cierra();
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
BOOL Cb_file::abre( char* path,int modo,BOOL sobre_escri , BOOL shared)
|
||||||
|
{
|
||||||
|
int fl;
|
||||||
|
int fl1;
|
||||||
|
int fl2=0;
|
||||||
|
if(shared)
|
||||||
|
fl2=FILE_SHARE_READ;
|
||||||
|
if (modo==1)
|
||||||
|
{
|
||||||
|
fl=GENERIC_READ;
|
||||||
|
fl1=OPEN_EXISTING;
|
||||||
|
}
|
||||||
|
else if (modo==2)
|
||||||
|
{
|
||||||
|
fl=GENERIC_WRITE;
|
||||||
|
if (sobre_escri)
|
||||||
|
fl1=CREATE_ALWAYS;
|
||||||
|
else
|
||||||
|
fl1=OPEN_ALWAYS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fl=GENERIC_READ | GENERIC_WRITE;
|
||||||
|
fl1=OPEN_ALWAYS;
|
||||||
|
if (sobre_escri)
|
||||||
|
fl1=CREATE_ALWAYS;
|
||||||
|
else
|
||||||
|
fl1=OPEN_ALWAYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
hfile = CreateFile(path, fl, fl2, NULL,
|
||||||
|
fl1, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
if (er)
|
||||||
|
er->pon_win("Cb_file");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
QWORD Cb_file::size()
|
||||||
|
{
|
||||||
|
if (!irAini())
|
||||||
|
return 0;
|
||||||
|
if (!irAfin())
|
||||||
|
return 0;
|
||||||
|
return dw;
|
||||||
|
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
|
@ -0,0 +1,175 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "_error.h"
|
||||||
|
#include "utiles_def.h"
|
||||||
|
class UTILES_EXPORT Cb_file: public IdataTransfer//manejo de archivos binarios
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
HANDLE hfile;//hanled del archivo
|
||||||
|
LARGE_INTEGER li;//se usa para dividir enteros de 64
|
||||||
|
DWORD dw;//bites movidos y respuestas al escribir
|
||||||
|
public:
|
||||||
|
C_error *er;
|
||||||
|
|
||||||
|
Cb_file(void);
|
||||||
|
~Cb_file(void);
|
||||||
|
//******************************************************************************************************************
|
||||||
|
//funciones--------------------------------------------------------------------
|
||||||
|
//******************************************************************************************************************
|
||||||
|
inline BOOL abierto()
|
||||||
|
{
|
||||||
|
return hfile != INVALID_HANDLE_VALUE;
|
||||||
|
};
|
||||||
|
//******************************************************************************************************************
|
||||||
|
BOOL abre(char* path,int modo, BOOL sobre_escri=FALSE, BOOL shared=FALSE);//modo 1 lectura modo 2 escritura modo 3 ambos
|
||||||
|
//******************************************************************************************************************
|
||||||
|
inline void cierra()//cierra archivo;
|
||||||
|
{
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
QWORD size();//te devuelve el tamaño del archivo en bytes
|
||||||
|
//******************************************************************************************************************
|
||||||
|
inline BOOL lee(void* buf,int nb)//lee un numero de bites y lo pone en buf
|
||||||
|
{
|
||||||
|
if (!ReadFile(hfile, (LPSTR) buf ,nb,&dw,NULL))
|
||||||
|
{
|
||||||
|
if (er)
|
||||||
|
er->pon_win("Cb_file");
|
||||||
|
//cierra---------------------
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
//---------------------------
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
inline BOOL escribe(void* buf,int nb)//escribe numero de bites
|
||||||
|
{
|
||||||
|
if (!WriteFile(hfile, (LPSTR) buf ,nb,&dw,NULL))
|
||||||
|
{
|
||||||
|
if (er)
|
||||||
|
er->pon_win("Cb_file");
|
||||||
|
//cierra---------------------
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
//---------------------------
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
inline BOOL irAfin()//va a la posicion del final del archivo
|
||||||
|
{
|
||||||
|
dw=SetFilePointer(hfile,0,NULL,FILE_END);
|
||||||
|
if(dw==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
if (er)
|
||||||
|
er->pon_win("Cb_file");
|
||||||
|
//cierra---------------------
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
//---------------------------
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
BOOL irAini(int nb=0)//va al inicio del archivo + nb bytes;
|
||||||
|
{
|
||||||
|
|
||||||
|
dw=SetFilePointer(hfile,nb,NULL,FILE_BEGIN);
|
||||||
|
if(dw==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
if (er)
|
||||||
|
er->pon_win("Cb_file");
|
||||||
|
//cierra---------------------
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
//---------------------------
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
BOOL irA(int nb=0)//salta nbites;
|
||||||
|
{
|
||||||
|
|
||||||
|
dw=SetFilePointer(hfile,nb,NULL,FILE_CURRENT);
|
||||||
|
if(dw==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
if (er)
|
||||||
|
er->pon_win("Cb_file");
|
||||||
|
//cierra---------------------
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
//---------------------------
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
inline BOOL irAini( QWORD nb)//entero de 64 bytes
|
||||||
|
{
|
||||||
|
li.QuadPart = nb;
|
||||||
|
dw=SetFilePointer(hfile,li.LowPart,&li.HighPart,FILE_BEGIN);
|
||||||
|
if(dw==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
if (er)
|
||||||
|
er->pon_win("Cb_file");
|
||||||
|
//cierra---------------------
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
//---------------------------
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual __int64 getNB_it()
|
||||||
|
{
|
||||||
|
return size();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual __int64 getNext_it( void* buf,__int64 nb )
|
||||||
|
{
|
||||||
|
if(lee(buf,(int)nb))
|
||||||
|
return nb;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool setPosition_it( __int64 nb )
|
||||||
|
{
|
||||||
|
return irAini((int)nb) ==TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool set_it( void* buf, __int64 nb )
|
||||||
|
{
|
||||||
|
return escribe(buf,(int)nb) == TRUE;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef UTILES_EXPORT
|
||||||
|
#ifdef _WINDLL
|
||||||
|
#define UTILES_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define UTILES_EXPORT __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#define UINT16_MAX 0xffff
|
||||||
|
#ifdef _WIN64
|
||||||
|
typedef __int64 ssize_t;
|
||||||
|
#else
|
||||||
|
typedef _w64 int ssize_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma warning(disable:4996)
|
||||||
|
|
@ -0,0 +1,428 @@
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "bmp_control.h"
|
||||||
|
//#include <gdiplus.h>
|
||||||
|
#include <gdiplus.h>
|
||||||
|
#include <mbstring.h>
|
||||||
|
|
||||||
|
#define ALINEAMIENTO_DWORDEX(x) ((x+4)&~4)
|
||||||
|
#define ALINEAMIENTO_DWORD(x) ((x+3)&~3)
|
||||||
|
#define WIDTHBYTES(i) ((i+31)/32*4)
|
||||||
|
//**************************************************************************************
|
||||||
|
Cbmp_control::Cbmp_control(int cx, int cy)
|
||||||
|
{
|
||||||
|
ancho=cx; alto=cy;
|
||||||
|
bmp_info=(BITMAPINFO*)new char[sizeof(BITMAPINFOHEADER)];
|
||||||
|
bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
||||||
|
bmp_info->bmiHeader.biWidth=cx;
|
||||||
|
bmp_info->bmiHeader.biHeight=cy;
|
||||||
|
bmp_info->bmiHeader.biPlanes=1;
|
||||||
|
|
||||||
|
bmp_info->bmiHeader.biBitCount=16;
|
||||||
|
bmp_info->bmiHeader.biCompression=0;
|
||||||
|
bmp_info->bmiHeader.biSizeImage=0;
|
||||||
|
bmp_info->bmiHeader.biXPelsPerMeter=0;
|
||||||
|
bmp_info->bmiHeader.biYPelsPerMeter=0;
|
||||||
|
bmp_info->bmiHeader.biClrUsed=0;
|
||||||
|
bmp_info->bmiHeader.biClrImportant=0;
|
||||||
|
|
||||||
|
bmp_info->bmiHeader.biCompression=BI_RGB;
|
||||||
|
bmp_info->bmiHeader.biBitCount=32;
|
||||||
|
bits=NULL;
|
||||||
|
m_cdc=NULL;
|
||||||
|
|
||||||
|
crea();
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
Cbmp_control::~Cbmp_control()
|
||||||
|
{
|
||||||
|
destruye();
|
||||||
|
delete bmp_info;
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::destruye()
|
||||||
|
{
|
||||||
|
if (bits!=NULL)
|
||||||
|
{
|
||||||
|
::SelectObject(m_hdc, m_old_bitmap);
|
||||||
|
::DeleteObject(m_bitmap);
|
||||||
|
::DeleteDC(m_hdc);
|
||||||
|
delete m_cdc;
|
||||||
|
m_cdc=NULL;
|
||||||
|
bits=NULL;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::crea(BOOL limpiar, char ch)
|
||||||
|
{
|
||||||
|
destruye();
|
||||||
|
|
||||||
|
HDC sdc=::GetDC(NULL);
|
||||||
|
m_hdc=::CreateCompatibleDC(sdc);
|
||||||
|
::ReleaseDC(0,sdc);
|
||||||
|
LPVOID lp;
|
||||||
|
bmp_info->bmiHeader.biSizeImage = ((256 * (bmp_info->bmiHeader.biBitCount / 8) + 3) & -4) * 192;
|
||||||
|
m_bitmap=::CreateDIBSection(m_hdc,bmp_info,DIB_PAL_COLORS,&lp,NULL,NULL);
|
||||||
|
DWORD dw = GetLastError();
|
||||||
|
bits=(BYTE*)lp;
|
||||||
|
|
||||||
|
if (bits==NULL)
|
||||||
|
{
|
||||||
|
//ASSERT(FALSE);
|
||||||
|
//AfxMessageBox(TEXT("sin memoria!"));
|
||||||
|
::DeleteDC(m_hdc);
|
||||||
|
m_hdc = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_old_bitmap=(HBITMAP)::SelectObject(m_hdc, m_bitmap);
|
||||||
|
m_cdc=new CDC();
|
||||||
|
m_cdc->Attach(m_hdc);
|
||||||
|
if (limpiar)
|
||||||
|
rellena_bits(ch);
|
||||||
|
m_iniciado=FALSE;
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
/*
|
||||||
|
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
|
||||||
|
{
|
||||||
|
UINT num = 0; // number of image encoders
|
||||||
|
UINT size = 0; // size of the image encoder array in bytes
|
||||||
|
|
||||||
|
Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;
|
||||||
|
|
||||||
|
Gdiplus::GetImageEncodersSize(&num, &size);
|
||||||
|
if(size == 0)
|
||||||
|
return -1; // Failure
|
||||||
|
|
||||||
|
pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
|
||||||
|
if(pImageCodecInfo == NULL)
|
||||||
|
return -1; // Failure
|
||||||
|
|
||||||
|
Gdiplus::GetImageEncoders(num, size, pImageCodecInfo);
|
||||||
|
|
||||||
|
for(UINT j = 0; j < num; ++j)
|
||||||
|
{
|
||||||
|
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
|
||||||
|
{
|
||||||
|
*pClsid = pImageCodecInfo[j].Clsid;
|
||||||
|
free(pImageCodecInfo);
|
||||||
|
return j; // Success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pImageCodecInfo);
|
||||||
|
return -1; // Failure
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL Cbmp_control::guardar_bmp(char *path)
|
||||||
|
{
|
||||||
|
|
||||||
|
Gdiplus::Bitmap *gr=Gdiplus::Bitmap::FromHBITMAP(m_bitmap,NULL);
|
||||||
|
|
||||||
|
// Save the altered image.
|
||||||
|
CLSID pngClsid;
|
||||||
|
GetEncoderClsid(L"image/bmp", &pngClsid);
|
||||||
|
gr->Save(L"c:\\temp\\ola.bmp",&pngClsid,NULL);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
};*/
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::redimensiona(int cx, int cy, BOOL limpiar, char ch)
|
||||||
|
{
|
||||||
|
if (cx!=ancho || cy!=alto)
|
||||||
|
{
|
||||||
|
ancho=cx; alto=cy;
|
||||||
|
bmp_info->bmiHeader.biWidth=cx;
|
||||||
|
bmp_info->bmiHeader.biHeight=cy;
|
||||||
|
crea(limpiar, ch);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (limpiar)
|
||||||
|
rellena_bits(ch);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::rellena_bits(char ch)
|
||||||
|
{
|
||||||
|
int aaa=WIDTHBYTES(ancho*24);
|
||||||
|
int fdf=ALINEAMIENTO_DWORD(ancho*4);
|
||||||
|
if (bits!=NULL)
|
||||||
|
memset(bits, ch, alto*fdf);
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::pon_bits(LPVOID src, int count)
|
||||||
|
{
|
||||||
|
/*ASSERT(count<=alto*ALINEAMIENTO_DWORD(ancho));
|
||||||
|
LPVOID lp=(LPVOID)bits;
|
||||||
|
count>>=2;
|
||||||
|
_asm
|
||||||
|
{
|
||||||
|
push ds;
|
||||||
|
pop es;
|
||||||
|
mov edi, dword ptr [lp];
|
||||||
|
mov esi, dword ptr [src];
|
||||||
|
cld;
|
||||||
|
mov ecx, count;
|
||||||
|
rep movsd;
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
if (count>Height*DWordAlign(Width)) return;
|
||||||
|
memcpy((LPVOID)Dib, src, count);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
HDC Cbmp_control::dame_hdc()
|
||||||
|
{
|
||||||
|
if (bits!=NULL) return m_hdc; else return 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
CDC* Cbmp_control::dame_cdc()
|
||||||
|
{
|
||||||
|
if (bits!=NULL)
|
||||||
|
return m_cdc;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::pinta_dib( HDC dc, CRect r )
|
||||||
|
{
|
||||||
|
if (bits!=NULL)
|
||||||
|
{
|
||||||
|
SetDIBitsToDevice(dc,r.left,r.top,r.Width(),
|
||||||
|
r.Height(),r.left,bmp_info->bmiHeader.biHeight-r.bottom ,0 ,bmp_info->bmiHeader.biHeight , bits,
|
||||||
|
bmp_info,DIB_RGB_COLORS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::escribe_pixel(int x, int y, BYTE valor)
|
||||||
|
{
|
||||||
|
if (bits==NULL)
|
||||||
|
return;
|
||||||
|
if (x<0 || y<0 || x>=ancho || y>=alto)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//m_bits[(m_alto-y-1)*WIDTHBYTES((m_ancho)+x)]=valor;
|
||||||
|
//m_bits[(m_alto-y-1)*WIDTHBYTES(ALINEAMIENTO_DWORD(m_ancho))+200]=valor;//WIDTHBYTES(4*((m_ancho)+(x)))]=valor;
|
||||||
|
|
||||||
|
|
||||||
|
//m_bits[367+ALINEAMIENTO_DWORD(x)]=valor;//WIDTHBYTES(4*((m_ancho)+(x)))]=valor;
|
||||||
|
int ff=ALINEAMIENTO_DWORD(ancho*4);
|
||||||
|
int fff=WIDTHBYTES(ancho)*8;
|
||||||
|
bits[(alto-y-1)*(ff)+x*4+0]=valor;
|
||||||
|
bits[(alto-y-1)*(ff)+x*4+1]=valor;
|
||||||
|
bits[(alto-y-1)*(ff)+x*4+2]=valor;
|
||||||
|
bits[(alto-y-1)*(ff)+x*4+3]=255;
|
||||||
|
//m_bits[sizeof(BITMAPINFOHEADER)+(m_alto-y-1)*(fff)+120]=valor;
|
||||||
|
//m_bits[(m_alto-y-1)*(ALINEAMIENTO_DWORD(m_ancho))+200]=valor;//
|
||||||
|
//m_bits[(m_alto-y-1)*(ALINEAMIENTO_DWORD(m_ancho))+200]=valor;//
|
||||||
|
//m_bits[ (y * m_ancho * 4) + (x * 4) + 0 ]=valor;
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::colorea_pixel(int x, int y, BYTE valor)
|
||||||
|
{
|
||||||
|
int res=WIDTHBYTES(ancho*24);
|
||||||
|
if (bits==NULL)
|
||||||
|
return;
|
||||||
|
if (x<0 || y<0 || x>=ancho || y>=alto)
|
||||||
|
return;
|
||||||
|
//int index=(m_alto-y-1)*ALINEAMIENTO_DWORD(m_ancho)+x;
|
||||||
|
//int index=(m_alto-y-1)*(m_ancho)+x;
|
||||||
|
bits[(alto-y-1) + 20]=valor;
|
||||||
|
bits[(alto-y-1) + 21]=valor;
|
||||||
|
//m_bits[(m_alto-y-1)*(ALINEAMIENTO_DWORD(m_ancho))+x+1]=valor+25;
|
||||||
|
//m_bits[(m_alto-y-1)*(ALINEAMIENTO_DWORD(m_ancho))+x+2]=valor+180;
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::pinta_cruz(int x, int y, int ancho, BYTE color)
|
||||||
|
{
|
||||||
|
if (bits==NULL)
|
||||||
|
return;
|
||||||
|
int i;
|
||||||
|
for (i=y-ancho; i<=y+ancho; i++)
|
||||||
|
escribe_pixel(x, i, color);
|
||||||
|
for (i=x-ancho; i<=x+ancho; i++)
|
||||||
|
escribe_pixel(i, y, color);
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
void Cbmp_control::mueve_datos(int cx, int cy)
|
||||||
|
{
|
||||||
|
if (bits==NULL)
|
||||||
|
return;
|
||||||
|
LPVOID lp1, lp2;
|
||||||
|
if (cx!=0)
|
||||||
|
{ // mueve datos en x
|
||||||
|
if (abs(cx)<ancho)
|
||||||
|
{
|
||||||
|
for (int i=0; i<alto; i++)
|
||||||
|
{
|
||||||
|
lp1=(LPVOID)((BYTE*)bits+i*ALINEAMIENTO_DWORD(ancho));
|
||||||
|
lp2=(LPVOID)((BYTE*)bits+i*ALINEAMIENTO_DWORD(ancho)+abs(cx));
|
||||||
|
if (cx<0)
|
||||||
|
memcpy(lp2, lp1, ancho-abs(cx));
|
||||||
|
else
|
||||||
|
memcpy(lp1, lp2, ancho-abs(cx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cy!=0)
|
||||||
|
{ // mueve datos en y
|
||||||
|
if (abs(cy)<alto)
|
||||||
|
{
|
||||||
|
if (cy<0)
|
||||||
|
{ // mueve datos hacia abajo
|
||||||
|
for (int i=0; i<alto-abs(cy); i++)
|
||||||
|
{
|
||||||
|
lp2=(LPVOID)((BYTE*)bits+i*ALINEAMIENTO_DWORD(ancho));
|
||||||
|
lp1=(LPVOID)((BYTE*)bits+(i+abs(cy))*ALINEAMIENTO_DWORD(ancho));
|
||||||
|
memcpy(lp2, lp1, ancho);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i=0; i<alto-abs(cy); i++)
|
||||||
|
{
|
||||||
|
lp2=(LPVOID)((BYTE*)bits+(alto-i-1)*ALINEAMIENTO_DWORD(ancho));
|
||||||
|
lp1=(LPVOID)((BYTE*)bits+(alto-i-abs(cy)-1)*ALINEAMIENTO_DWORD(ancho));
|
||||||
|
memcpy(lp2, lp1, ancho);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
BOOL Cbmp_control::w2dib( CWnd *w, CRect *rec, DWORD flags)
|
||||||
|
{
|
||||||
|
CRect r;
|
||||||
|
if (bits==NULL)
|
||||||
|
return FALSE;
|
||||||
|
if(!rec)
|
||||||
|
{
|
||||||
|
w->GetClientRect(&r);
|
||||||
|
rec=&r;
|
||||||
|
}
|
||||||
|
redimensiona(rec->Width(),rec->Height());
|
||||||
|
if(!::BitBlt(m_hdc, 0, 0, ancho, alto, w->GetDC()->m_hDC, rec->left, rec->top, SRCCOPY))
|
||||||
|
return FALSE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
BOOL Cbmp_control::dib2file( char *path )
|
||||||
|
{
|
||||||
|
|
||||||
|
if (bits==NULL)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL result = FALSE;
|
||||||
|
PICTDESC pd;
|
||||||
|
|
||||||
|
pd.cbSizeofstruct = sizeof(PICTDESC);
|
||||||
|
pd.picType = PICTYPE_BITMAP;
|
||||||
|
pd.bmp.hbitmap = m_bitmap;
|
||||||
|
pd.bmp.hpal = 0;
|
||||||
|
|
||||||
|
LPPICTURE picture;
|
||||||
|
HRESULT res = OleCreatePictureIndirect(&pd, IID_IPicture, false,
|
||||||
|
reinterpret_cast<void**>(&picture));
|
||||||
|
|
||||||
|
if (!SUCCEEDED(res))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
LPSTREAM stream;
|
||||||
|
res = CreateStreamOnHGlobal(0, true, &stream);
|
||||||
|
|
||||||
|
if (!SUCCEEDED(res))
|
||||||
|
{
|
||||||
|
picture->Release();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
LONG bytes_streamed;
|
||||||
|
res = picture->SaveAsFile(stream, true, &bytes_streamed);
|
||||||
|
|
||||||
|
HANDLE file = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ, 0,
|
||||||
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
|
||||||
|
if (!SUCCEEDED(res) || !file)
|
||||||
|
{
|
||||||
|
stream->Release();
|
||||||
|
picture->Release();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
HGLOBAL mem = 0;
|
||||||
|
GetHGlobalFromStream(stream, &mem);
|
||||||
|
LPVOID data = GlobalLock(mem);
|
||||||
|
|
||||||
|
DWORD bytes_written;
|
||||||
|
|
||||||
|
result = !!WriteFile(file, data, bytes_streamed, &bytes_written, 0);
|
||||||
|
result &= (bytes_written == static_cast<DWORD>(bytes_streamed));
|
||||||
|
|
||||||
|
GlobalUnlock(mem);
|
||||||
|
CloseHandle(file);
|
||||||
|
|
||||||
|
stream->Release();
|
||||||
|
picture->Release();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Free memory.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*BITMAPINFO bi;
|
||||||
|
ZeroMemory(&bi, sizeof(BITMAPINFO));
|
||||||
|
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
bi.bmiHeader.biWidth = ancho;
|
||||||
|
bi.bmiHeader.biHeight = alto;
|
||||||
|
bi.bmiHeader.biPlanes = 1;
|
||||||
|
bi.bmiHeader.biBitCount = 24;*/
|
||||||
|
|
||||||
|
/*BITMAPFILEHEADER bh;
|
||||||
|
ZeroMemory(&bh, sizeof(BITMAPFILEHEADER));
|
||||||
|
bh.bfType = 0x4d42; //bitmap
|
||||||
|
bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
||||||
|
bh.bfSize = bh.bfOffBits + ((alto*ancho)*3);
|
||||||
|
|
||||||
|
CFile file;
|
||||||
|
if(!file.Open(path, CFile::modeCreate | CFile::modeWrite))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
file.Write(&bh, sizeof(BITMAPFILEHEADER));
|
||||||
|
file.Write(&(bmp_info->bmiHeader), sizeof(BITMAPINFOHEADER));
|
||||||
|
file.Write(bits, 3 * alto*ancho);
|
||||||
|
file.Close();*/
|
||||||
|
//return TRUE;
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
BOOL Cbmp_control::w2file(CWnd *w,char* path, CRect *rec)
|
||||||
|
{
|
||||||
|
CRect r;
|
||||||
|
if (!rec)
|
||||||
|
{
|
||||||
|
w->GetClientRect(&r);
|
||||||
|
rec=&r;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cbmp_control cnt(rec->Width(),rec->Height());
|
||||||
|
cnt.pon_iniciado(TRUE);
|
||||||
|
return cnt.w2dib(w,rec) && cnt.dib2file(path);
|
||||||
|
|
||||||
|
}
|
||||||
|
//**************************************************************************************
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
//bmp para pintar graficos antes de pintarlos en pantalla
|
||||||
|
//asi se evita el parpadeo
|
||||||
|
class UTILES_EXPORT Cbmp_control//falta revisar
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables-------------------------------------
|
||||||
|
BYTE* bits;//bits del bmp
|
||||||
|
int ancho;//ancho en pixel del bmp
|
||||||
|
int alto;//alto en pixel del bmp
|
||||||
|
BITMAPINFO* bmp_info;
|
||||||
|
HDC m_hdc;
|
||||||
|
CDC *m_cdc;
|
||||||
|
HBITMAP m_bitmap, m_old_bitmap;
|
||||||
|
BOOL m_iniciado;
|
||||||
|
//c y de------------------------------------------
|
||||||
|
Cbmp_control(int cx, int cy);
|
||||||
|
~Cbmp_control();
|
||||||
|
//funciones---------------------------------------
|
||||||
|
void pinta_dib(HDC dc, CRect r);//pinta lo dibujado en el bmp en el hdc pasado
|
||||||
|
BOOL dib2file(char *path);//guarda el bmp en un archivo
|
||||||
|
BOOL w2dib( CWnd *w, CRect *rec=NULL, DWORD flags=PRF_CLIENT);//copia la pantalla al bmp
|
||||||
|
void redimensiona(int cx, int cy, BOOL limpiar=TRUE, char ch=0);//redimensiona el bmp
|
||||||
|
void crea(BOOL limpiar=TRUE, char ch=0);//crea bmp
|
||||||
|
void destruye();//destrulle bmp
|
||||||
|
|
||||||
|
HDC dame_hdc();//da el hanled para pintar
|
||||||
|
CDC* dame_cdc();
|
||||||
|
|
||||||
|
static BOOL w2file(CWnd *w,char* path, CRect *rec=NULL);//pasa lo contenido en la ventana a un archivo de imagen
|
||||||
|
|
||||||
|
BYTE* dame_bits(){return bits;};
|
||||||
|
int dame_ancho(){return ancho;};
|
||||||
|
int dame_alto(){return alto;};
|
||||||
|
|
||||||
|
|
||||||
|
//BOOL guardar_bmp(char *path);
|
||||||
|
void escribe_pixel(int x, int y, BYTE valor);
|
||||||
|
void colorea_pixel(int x, int y, BYTE valor);
|
||||||
|
void pinta_cruz(int x, int y, int ancho, BYTE color);
|
||||||
|
|
||||||
|
void rellena_bits(char ch=0);
|
||||||
|
void pon_bits(LPVOID src, int count);
|
||||||
|
|
||||||
|
void mueve_datos(int cx, int cy);
|
||||||
|
BOOL esta_iniciado(){return m_iniciado;};
|
||||||
|
void pon_iniciado(BOOL flag){m_iniciado=flag;};
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/*void CCatchScreenDlg::SaveScreenToFile(LPCTSTR szFileName)
|
||||||
|
{
|
||||||
|
HDC hScrDC = ::GetDC(NULL);
|
||||||
|
HDC hMemDC = NULL;
|
||||||
|
|
||||||
|
BYTE *lpBitmapBits = NULL;
|
||||||
|
|
||||||
|
int nWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||||
|
int nHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
|
||||||
|
hMemDC = ::CreateCompatibleDC(hScrDC);
|
||||||
|
|
||||||
|
BITMAPINFO bi;
|
||||||
|
ZeroMemory(&bi, sizeof(BITMAPINFO));
|
||||||
|
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
bi.bmiHeader.biWidth = nWidth;
|
||||||
|
bi.bmiHeader.biHeight = nHeight;
|
||||||
|
bi.bmiHeader.biPlanes = 1;
|
||||||
|
bi.bmiHeader.biBitCount = 24;
|
||||||
|
|
||||||
|
HBITMAP bitmap = ::CreateDIBSection(hMemDC, &bi, DIB_RGB_COLORS, (LPVOID*)&lpBitmapBits, NULL, 0);
|
||||||
|
HGDIOBJ oldbmp = ::SelectObject(hMemDC, bitmap);
|
||||||
|
|
||||||
|
::BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY);
|
||||||
|
|
||||||
|
BITMAPFILEHEADER bh;
|
||||||
|
ZeroMemory(&bh, sizeof(BITMAPFILEHEADER));
|
||||||
|
bh.bfType = 0x4d42; //bitmap
|
||||||
|
bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
||||||
|
bh.bfSize = bh.bfOffBits + ((nWidth*nHeight)*3);
|
||||||
|
|
||||||
|
CFile file;
|
||||||
|
if(file.Open(szFileName, CFile::modeCreate | CFile::modeWrite))
|
||||||
|
{
|
||||||
|
file.Write(&bh, sizeof(BITMAPFILEHEADER));
|
||||||
|
file.Write(&(bi.bmiHeader), sizeof(BITMAPINFOHEADER));
|
||||||
|
file.Write(lpBitmapBits, 3 * nWidth * nHeight);
|
||||||
|
file.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
::SelectObject(hMemDC, oldbmp);
|
||||||
|
::DeleteObject(bitmap);
|
||||||
|
::DeleteObject(hMemDC);
|
||||||
|
::ReleaseDC(NULL, hScrDC);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "cola_asincrona.h"
|
||||||
|
//**************************************************************************
|
||||||
|
Ccola_asincrona::Ccola_asincrona(void)
|
||||||
|
{
|
||||||
|
strcpy(nombre, "Cola asincrona sin nombre");
|
||||||
|
time_sleep=20;
|
||||||
|
m_thread=NULL;
|
||||||
|
timers=NULL;
|
||||||
|
pirate=FALSE;
|
||||||
|
n_timers=max_timers=0;
|
||||||
|
ultima_tarea=FALSE;
|
||||||
|
tipo_u_tarea=0;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
Ccola_asincrona::~Ccola_asincrona(void)
|
||||||
|
{
|
||||||
|
termina();
|
||||||
|
if (timers)
|
||||||
|
{
|
||||||
|
free(timers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void Ccola_asincrona::procesa(int tipo, BYTE* e )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void Ccola_asincrona::inicia( int size,int cap )
|
||||||
|
{
|
||||||
|
tareas.inicia(cap,size+sizeof(int));
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
BOOL Ccola_asincrona::add(int tipo,BYTE*e )
|
||||||
|
{
|
||||||
|
return tareas.add(tipo,e);
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void Ccola_asincrona::rum()
|
||||||
|
{
|
||||||
|
BYTE *tarea;
|
||||||
|
BYTE *contenido;
|
||||||
|
int *tipo;
|
||||||
|
Timers_cola_asincrona *tim;
|
||||||
|
while(!pirate)
|
||||||
|
{
|
||||||
|
//miramos si hay tarea--------------------------
|
||||||
|
t=_time64(NULL);
|
||||||
|
for (int i=0; i<n_timers; i++)
|
||||||
|
{
|
||||||
|
tim=&timers[i];
|
||||||
|
if (tim->t+tim->ultimo<=t)
|
||||||
|
{
|
||||||
|
tim->ultimo=t;
|
||||||
|
procesa(tim->tipo,NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tarea=tareas.get();
|
||||||
|
if (tarea)
|
||||||
|
{
|
||||||
|
tipo=(int*)tarea;
|
||||||
|
contenido=&tarea[sizeof(int)];
|
||||||
|
procesa(*tipo,contenido);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
|
||||||
|
Sleep(time_sleep);
|
||||||
|
}
|
||||||
|
if (ultima_tarea)
|
||||||
|
procesa(tipo_u_tarea,NULL);
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void Ccola_asincrona::cuida()
|
||||||
|
{
|
||||||
|
if (max_timers<=n_timers+1)
|
||||||
|
{
|
||||||
|
max_timers+=10;
|
||||||
|
if (timers)
|
||||||
|
{
|
||||||
|
timers=(Timers_cola_asincrona*)realloc(timers,max_timers*sizeof(Timers_cola_asincrona));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
timers=(Timers_cola_asincrona*)malloc(max_timers*sizeof(Timers_cola_asincrona));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void Ccola_asincrona::on_timer( int t,int tipo )
|
||||||
|
{
|
||||||
|
cuida();
|
||||||
|
Timers_cola_asincrona *tim=&timers[n_timers];
|
||||||
|
//Timers_cola_asincrona *tim=&timers[n_timers*sizeof(Timers_cola_asincrona)];
|
||||||
|
|
||||||
|
tim->t=t;
|
||||||
|
tim->tipo=tipo;
|
||||||
|
tim->ultimo= _time64(NULL);
|
||||||
|
n_timers++;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void Ccola_asincrona::termina()
|
||||||
|
{
|
||||||
|
pirate=TRUE;
|
||||||
|
join();
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
void Ccola_asincrona::add_fin( int tipo )
|
||||||
|
{
|
||||||
|
ultima_tarea=TRUE;
|
||||||
|
tipo_u_tarea=tipo;
|
||||||
|
}
|
||||||
|
//**************************************************************************
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
#pragma once
|
||||||
|
#include "_proceso.h"
|
||||||
|
#include "static_cola.h"
|
||||||
|
#include "base_head.h"
|
||||||
|
typedef struct Timers_cola_asincrona
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
__int64 ultimo;
|
||||||
|
int tipo;
|
||||||
|
}Timers_cola_asincrona;
|
||||||
|
|
||||||
|
class UTILES_EXPORT Ccola_asincrona :public C_proceso
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
Cstatic_cola tareas;
|
||||||
|
__int64 t;
|
||||||
|
int n_timers;
|
||||||
|
int max_timers;
|
||||||
|
Timers_cola_asincrona* timers;
|
||||||
|
BOOL ultima_tarea;//indica si hay que hacer ultima tarea antes de desconectar
|
||||||
|
BOOL tipo_u_tarea;//tipo de ultima tarea
|
||||||
|
public:
|
||||||
|
BOOL pirate;
|
||||||
|
int time_sleep;
|
||||||
|
|
||||||
|
|
||||||
|
Ccola_asincrona(void);
|
||||||
|
~Ccola_asincrona(void);
|
||||||
|
//funciones
|
||||||
|
void inicia(int size,int cap=200);//prepara cola con elementos de tamaño size y capacidad de la coloa de cap
|
||||||
|
BOOL add(int tipo,BYTE*e);//pone una tarea nueva
|
||||||
|
void on_timer(int t,int tipo);//pone una tarea cada t milesimas de segundo (solo el tipo)
|
||||||
|
virtual void rum();
|
||||||
|
void termina();//finaliza thred cola asincrona (espera)
|
||||||
|
void add_fin(int tipo);//pone ultima tarea(antes de finalizar)
|
||||||
|
//override
|
||||||
|
void virtual procesa(int tipo, BYTE* e);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void cuida();//pide memoria para timers
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,175 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "control_usu_con.h"
|
||||||
|
#include "_error.h"
|
||||||
|
#include "b_file.h"
|
||||||
|
//*****************************************************************
|
||||||
|
Ccontrol_usu_con::Ccontrol_usu_con(void)
|
||||||
|
{
|
||||||
|
na=nb=0;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
Ccontrol_usu_con::~Ccontrol_usu_con(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
int Ccontrol_usu_con::lee( char* path, C_error *er )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
BOOL Ccontrol_usu_con::guarda( char*path ,C_error *er )
|
||||||
|
{
|
||||||
|
/*Head_usuario_conex_0 head;
|
||||||
|
Cb_file file;
|
||||||
|
if(!file.abre(path,2,TRUE))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
int Ccontrol_usu_con::add( Usuario_conx_0 *user )
|
||||||
|
{
|
||||||
|
int ind;
|
||||||
|
cerrojo.entro();
|
||||||
|
//revisa si repe------------------------
|
||||||
|
if (get(user->nombre))
|
||||||
|
{
|
||||||
|
cerrojo.salgo();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//lo pone en lista----------------------
|
||||||
|
ind=pon(user);
|
||||||
|
cerrojo.salgo();
|
||||||
|
return ind;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
Usuario_conx_0* Ccontrol_usu_con::conecta( char*nombre, char* key,int*err )
|
||||||
|
{
|
||||||
|
Usuario_conx_0 *u, *user=(Usuario_conx_0*)malloc(sizeof(Usuario_conx_0));
|
||||||
|
*err=0;
|
||||||
|
cerrojo.entro();
|
||||||
|
u=get(nombre);
|
||||||
|
if (!u)
|
||||||
|
{
|
||||||
|
*err=1;
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
if (u->flags & FLAG_USUARIO_CONEXION_BLOQ)
|
||||||
|
{
|
||||||
|
*err=3;
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
else if ((u->flags & FLAG_USUARIO_CONEXION_EN_USO) && (u->flags & FLAG_USUARIO_CONEXION_INDI))
|
||||||
|
{
|
||||||
|
*err=4;
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
else if (strcmp(u->clave,key))
|
||||||
|
{
|
||||||
|
*err=2;
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
u->flags=u->flags | FLAG_USUARIO_CONEXION_EN_USO;
|
||||||
|
u->ncon++;
|
||||||
|
na++;
|
||||||
|
memcpy(user,u,sizeof(Usuario_conx_0));
|
||||||
|
cerrojo .salgo();
|
||||||
|
return user;
|
||||||
|
va_mal:
|
||||||
|
cerrojo .salgo();
|
||||||
|
free(user);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
BOOL Ccontrol_usu_con::desconecta( Usuario_conx_0 *user )
|
||||||
|
{
|
||||||
|
Usuario_conx_0 *u;
|
||||||
|
int af,an;
|
||||||
|
cerrojo.entro();
|
||||||
|
if (user->id>=us.n)
|
||||||
|
{
|
||||||
|
cerrojo.salgo();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
u=&us[user->id];
|
||||||
|
af=u->flags;
|
||||||
|
an=u->ncon-1;
|
||||||
|
*u=*user;
|
||||||
|
u->ncon=an;
|
||||||
|
if (an)
|
||||||
|
u->flags=af;
|
||||||
|
else
|
||||||
|
u->flags=af & ~FLAG_USUARIO_CONEXION_EN_USO;
|
||||||
|
na--;
|
||||||
|
cerrojo.salgo();
|
||||||
|
free(user);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
BOOL Ccontrol_usu_con::borra( Usuario_conx_0 *user )
|
||||||
|
{
|
||||||
|
cerrojo.entro();
|
||||||
|
if (user->id>=us.n)
|
||||||
|
{
|
||||||
|
cerrojo.salgo();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
us[user->id].flags=us[user->id].flags & FLAG_USUARIO_CONEXION_VACIO;
|
||||||
|
nb++;
|
||||||
|
cerrojo.salgo();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
int Ccontrol_usu_con::esta( char *nombre )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
BYTE* Ccontrol_usu_con::get_copy( int*nu,int modo/*=0 */ )
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
void Ccontrol_usu_con::verifica()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
int Ccontrol_usu_con::pon(Usuario_conx_0 *u)
|
||||||
|
{
|
||||||
|
if (nb && us.n)
|
||||||
|
{
|
||||||
|
//hay vacios
|
||||||
|
for (int i=0; i<us.n; i++)
|
||||||
|
{
|
||||||
|
if (us[i].flags & FLAG_USUARIO_CONEXION_VACIO)
|
||||||
|
{
|
||||||
|
nb--;
|
||||||
|
memcpy(&us[i],u,sizeof(Usuario_conx_0));
|
||||||
|
us[i].id=i;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
us+*u;
|
||||||
|
us[us.n-1].id=us.n-1;
|
||||||
|
return us.n-1;
|
||||||
|
}
|
||||||
|
//********************************************************************
|
||||||
|
Usuario_conx_0* Ccontrol_usu_con::get( char* nombre )
|
||||||
|
{
|
||||||
|
if (us.n<=0)
|
||||||
|
return NULL;
|
||||||
|
for (int i=0; i<us.n; i++)
|
||||||
|
{
|
||||||
|
if (us[i].flags & FLAG_USUARIO_CONEXION_VACIO)
|
||||||
|
continue;
|
||||||
|
if (strcmp(nombre, us[i].nombre)==0)
|
||||||
|
return &us[i];
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*****************************************************************
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
#pragma once
|
||||||
|
#include "garray.h"
|
||||||
|
#include "utiles_def.h"
|
||||||
|
#include "lock.h"
|
||||||
|
class C_error;
|
||||||
|
//proporciona un control de usuarios (entra en usuarios etc...)
|
||||||
|
class Ccontrol_usu_con
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables-----------------------------------------
|
||||||
|
Cgarray<Usuario_conx_0>us;//array de usuarios
|
||||||
|
Clock cerrojo;//interlock para protejer el array de usuarios
|
||||||
|
int nb;//numero de usuarios borrados;
|
||||||
|
int na;//numero de usuarios conectados;
|
||||||
|
//c y d---------------------------------------------
|
||||||
|
Ccontrol_usu_con(void);
|
||||||
|
~Ccontrol_usu_con(void);
|
||||||
|
//funciones-----------------------------------------
|
||||||
|
int lee(char* path, C_error *er);//carga usuarios de archivo y dice los que ha añadido
|
||||||
|
BOOL guarda(char*path ,C_error *er);//guarda los usuarios en un archivo
|
||||||
|
int pon(Usuario_conx_0 *u);//pone info del cliente en una posicion vacia de la lista (proteje antes usar)
|
||||||
|
Usuario_conx_0* get( char* nombre );
|
||||||
|
//funciones concurrente----------
|
||||||
|
int add(Usuario_conx_0 *user);//añade user CONCURRENTE
|
||||||
|
Usuario_conx_0* conecta(char*nombre, char* key,int*err);//pone como conectado un usuario CONCURRENTE
|
||||||
|
//err=1 usuariono existe,2 key incorrecta, 3 esta bloqueado, 4 usuario en uso
|
||||||
|
BOOL desconecta(Usuario_conx_0 *user);//desconecta un usuario CONCURRENTE
|
||||||
|
BOOL borra(Usuario_conx_0 *user);//borra usuario CONCURRENTE
|
||||||
|
int esta(char *nombre); //da el indice del usuario)(si esta)
|
||||||
|
BYTE* get_copy( int*nu,int modo=0 );//da una copia de los usuarios actuales
|
||||||
|
void verifica();//mira estado de lista y comprime si es necesario CONCURRENTE
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,309 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "csv_file.h"
|
||||||
|
#include "_error.h"
|
||||||
|
//*********************************************************************************************************
|
||||||
|
Ccsv_file::Ccsv_file( C_error* err/*=NULL*/ )
|
||||||
|
{
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
b_er=FALSE;
|
||||||
|
er=err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
er= new C_error();
|
||||||
|
b_er=TRUE;
|
||||||
|
}
|
||||||
|
filas.z=sizeof(Fila_csv_file);
|
||||||
|
filas.incremento=100;
|
||||||
|
incre_col=100;
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
Ccsv_file::~Ccsv_file(void)
|
||||||
|
{
|
||||||
|
if(b_er && er)
|
||||||
|
delete er;
|
||||||
|
borra();
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
Fila_csv_file* Ccsv_file::get_f( int i )
|
||||||
|
{
|
||||||
|
return (Fila_csv_file*)filas.get(i);
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
char* Ccsv_file::get( int fila,int col )
|
||||||
|
{
|
||||||
|
Fila_csv_file*f;
|
||||||
|
Columna_csv_file *c;
|
||||||
|
f=get_f(fila);
|
||||||
|
if (!f)
|
||||||
|
return NULL;
|
||||||
|
c=f->get(col);
|
||||||
|
if (!c)
|
||||||
|
return NULL;
|
||||||
|
return str.get(c->itex);
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
int Ccsv_file::n_col( int fil )
|
||||||
|
{
|
||||||
|
Fila_csv_file*f;
|
||||||
|
f=get_f(fil);
|
||||||
|
if (!f)
|
||||||
|
return -1;
|
||||||
|
return f->colum->n;
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
int Ccsv_file::n()
|
||||||
|
{
|
||||||
|
return filas.n;
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
int Ccsv_file::add()
|
||||||
|
{
|
||||||
|
Fila_csv_file*f;
|
||||||
|
filas.reserva();
|
||||||
|
filas.n++;
|
||||||
|
f=get_f(filas.n-1);
|
||||||
|
f->inicia(incre_col);
|
||||||
|
f->flags=0;
|
||||||
|
return filas.n-1;
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
int Ccsv_file::add( int fila, char *valor )
|
||||||
|
{
|
||||||
|
Fila_csv_file*f;
|
||||||
|
Columna_csv_file *c;
|
||||||
|
f=get_f(fila);
|
||||||
|
if (!f)
|
||||||
|
return -1;
|
||||||
|
c=f->add_coun();
|
||||||
|
str.add(valor);
|
||||||
|
c->itex=str.size()-1;
|
||||||
|
return f->colum->n-1;
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
int Ccsv_file::add( int fila, int valor )
|
||||||
|
{
|
||||||
|
char s[64];
|
||||||
|
sprintf(s,"%ld",valor);
|
||||||
|
return add(fila,s);
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
int Ccsv_file::add( int fila, double valor )
|
||||||
|
{
|
||||||
|
char s[128];
|
||||||
|
sprintf(s,"%ld",valor);
|
||||||
|
return add(fila,s);
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
BOOL Ccsv_file::set( int fila, int col, char* value )
|
||||||
|
{
|
||||||
|
Fila_csv_file*f;
|
||||||
|
Columna_csv_file *c;
|
||||||
|
f=get_f(fila);
|
||||||
|
if (!f)
|
||||||
|
return FALSE;
|
||||||
|
c= f->get(col);
|
||||||
|
if(!c)
|
||||||
|
return FALSE;
|
||||||
|
c->itex=str.size();
|
||||||
|
str.add(value);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
BOOL Ccsv_file::set( int fila, int col, int value )
|
||||||
|
{
|
||||||
|
char s[64];
|
||||||
|
sprintf(s,"%ld",value);
|
||||||
|
return set(fila,col,s);
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
BOOL Ccsv_file::set( int fila, int col, double value )
|
||||||
|
{
|
||||||
|
char s[128];
|
||||||
|
sprintf(s,"%ld",value);
|
||||||
|
return set(fila,col,s);
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
void Ccsv_file::borra()
|
||||||
|
{
|
||||||
|
Fila_csv_file*f;
|
||||||
|
for(int i=0; i<filas.n;i++)
|
||||||
|
{
|
||||||
|
f=get_f(i);
|
||||||
|
f->del();
|
||||||
|
}
|
||||||
|
filas.borra();
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
BOOL Ccsv_file::lee( char *path,char separa )
|
||||||
|
{
|
||||||
|
char *buf=NULL;
|
||||||
|
char *s1;
|
||||||
|
char *s2;
|
||||||
|
char *s3;
|
||||||
|
int fi;
|
||||||
|
borra();
|
||||||
|
HANDLE hfile=INVALID_HANDLE_VALUE;
|
||||||
|
DWORD dw,nb;
|
||||||
|
//abrimos archivo---------------------
|
||||||
|
|
||||||
|
hfile = CreateFile(path, GENERIC_READ, 0, NULL,
|
||||||
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nb=SetFilePointer(hfile,0,NULL,FILE_END);
|
||||||
|
if(nb==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
buf=(char *)malloc(nb+2);
|
||||||
|
|
||||||
|
dw=SetFilePointer(hfile,0,NULL,FILE_BEGIN);
|
||||||
|
if(dw==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
if (!ReadFile(hfile, (LPSTR) buf ,nb,&dw,NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=INVALID_HANDLE_VALUE;
|
||||||
|
buf[nb]=0;
|
||||||
|
buf[nb+1]=0;//aseguramos el final de la cadena;
|
||||||
|
s1=buf;
|
||||||
|
//procesamos--------------------------------------------------
|
||||||
|
while (*s1)
|
||||||
|
{
|
||||||
|
s2=busca_salto_linea(s1);
|
||||||
|
if (*s2)
|
||||||
|
{
|
||||||
|
*s2=0;
|
||||||
|
s2++;
|
||||||
|
while(*s2=='\r' ||*s2=='\n')
|
||||||
|
s2=s2+1;
|
||||||
|
}
|
||||||
|
//añadimos fila------------------------------------------
|
||||||
|
fi=add();
|
||||||
|
s3=s1;
|
||||||
|
while(*s3)
|
||||||
|
{
|
||||||
|
if (*s3==separa)
|
||||||
|
{
|
||||||
|
*s3=0;
|
||||||
|
//añadimos columna----------------------------------
|
||||||
|
add(fi,s1);
|
||||||
|
s1=s3+1;
|
||||||
|
}
|
||||||
|
s3=s3+1;
|
||||||
|
}
|
||||||
|
s1=s2;
|
||||||
|
}
|
||||||
|
free(buf);
|
||||||
|
return TRUE;
|
||||||
|
salgo:
|
||||||
|
if (hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
CloseHandle(hfile);
|
||||||
|
if (buf)
|
||||||
|
free(buf);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
BOOL Ccsv_file::guarda( char *path, char separa, BOOL ret_carro )
|
||||||
|
{
|
||||||
|
HANDLE hfile=INVALID_HANDLE_VALUE;
|
||||||
|
DWORD dw;
|
||||||
|
char salto='\n';
|
||||||
|
char ret_ca='\r';
|
||||||
|
Fila_csv_file*f;
|
||||||
|
Columna_csv_file *c;
|
||||||
|
char*st;
|
||||||
|
|
||||||
|
/*
|
||||||
|
er->pon(MODULO_INI_FILE,"guarda: Función no implementada");
|
||||||
|
return FALSE;*/
|
||||||
|
//abrimos archivo-------------------------------
|
||||||
|
hfile=CreateFile(path,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
0, // exclusive access
|
||||||
|
NULL, // no security
|
||||||
|
CREATE_ALWAYS,
|
||||||
|
0, // no overlapped I/O
|
||||||
|
NULL); // null template
|
||||||
|
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//guardamos---------------------------------
|
||||||
|
for (int i=0; i<filas.n; i++)
|
||||||
|
{
|
||||||
|
f=get_f(i);
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
//guardamos columnas----------------
|
||||||
|
for (int j=0; j<f->colum->n;j++)
|
||||||
|
{
|
||||||
|
c=f->get(j);
|
||||||
|
st=str.get(c->itex);
|
||||||
|
if (j!=0)
|
||||||
|
{
|
||||||
|
//ponemos separacion--------
|
||||||
|
if(!WriteFile(hfile, &separa, 1, &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!WriteFile(hfile, st, sizeof(st), &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret_carro)
|
||||||
|
{
|
||||||
|
if(!WriteFile(hfile, &ret_ca, 1, &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!WriteFile(hfile, &salto, 1, &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_CSV_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//cerramos----------------------------------
|
||||||
|
if(hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
salgo:
|
||||||
|
if(hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*********************************************************************************************************
|
||||||
|
char* Ccsv_file::busca_salto_linea( char* st )
|
||||||
|
{
|
||||||
|
char *s=st;
|
||||||
|
while(*s && *s!='\r' && *s!='\n' )
|
||||||
|
s=s+1;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
//*************************************************************************************************
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "static_array.h"
|
||||||
|
#include "StrArray.h"
|
||||||
|
#define MODULO_CSV_FILE "Ccsv_file"
|
||||||
|
typedef struct Columna_csv_file
|
||||||
|
{
|
||||||
|
int flags;//flags
|
||||||
|
int itex;//indice a texto
|
||||||
|
}Columna_csv_file;
|
||||||
|
|
||||||
|
typedef struct Fila_csv_file
|
||||||
|
{
|
||||||
|
int flags;
|
||||||
|
Cstatic_array *colum;//valor
|
||||||
|
//metodos-----------------------
|
||||||
|
void inicia(int incre=100)
|
||||||
|
{
|
||||||
|
colum = new Cstatic_array(sizeof(Columna_csv_file));
|
||||||
|
colum->incremento=incre;
|
||||||
|
}
|
||||||
|
Columna_csv_file* get(int i)
|
||||||
|
{
|
||||||
|
return(Columna_csv_file*) colum->get(i);
|
||||||
|
}
|
||||||
|
Columna_csv_file* add_coun()
|
||||||
|
{
|
||||||
|
Columna_csv_file* c;
|
||||||
|
colum->reserva();
|
||||||
|
colum->n++;
|
||||||
|
c=(Columna_csv_file*)colum->get(colum->n-1);
|
||||||
|
c->flags=0;
|
||||||
|
c->itex=0;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
void del()
|
||||||
|
{
|
||||||
|
delete(colum);
|
||||||
|
}
|
||||||
|
}Fila_csv_file;
|
||||||
|
|
||||||
|
class C_error;
|
||||||
|
class UTILES_EXPORT Ccsv_file
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
StrArray str;
|
||||||
|
Cstatic_array filas;
|
||||||
|
C_error *er;
|
||||||
|
BOOL b_er;
|
||||||
|
int incre_col;
|
||||||
|
public:
|
||||||
|
|
||||||
|
Ccsv_file(C_error* err=NULL);
|
||||||
|
~Ccsv_file(void);
|
||||||
|
//funciones-------------------------------------------------------------------
|
||||||
|
BOOL lee( char *path,char separa=';' );
|
||||||
|
BOOL guarda( char *path, char separa, BOOL ret_carro=TRUE );
|
||||||
|
|
||||||
|
char* get(int fila,int col);//consigue la columna col de la fila fila
|
||||||
|
int n();//numero de filas
|
||||||
|
int n_col(int fil);//numero de columnas de la fila fil
|
||||||
|
|
||||||
|
int add();//añade una fila (da el indice de dicha fila)
|
||||||
|
int add(int fila, char *valor);//añade una columna a la fila
|
||||||
|
int add(int fila, int valor);
|
||||||
|
int add(int fila, double valor);
|
||||||
|
|
||||||
|
BOOL set(int fila, int col, char* value);//ojo con hacer muchos cambios (la memoria no se libera)
|
||||||
|
BOOL set(int fila, int col, int value);
|
||||||
|
BOOL set(int fila, int col, double value);
|
||||||
|
|
||||||
|
void borra();//borra todo
|
||||||
|
|
||||||
|
//funciones auxiliares--------------------------------------------------------
|
||||||
|
private:
|
||||||
|
|
||||||
|
Fila_csv_file* get_f(int i);
|
||||||
|
char* busca_salto_linea( char* st );
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,392 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "utiles_def.h"
|
||||||
|
#include "dir_manager.h"
|
||||||
|
#include "_error.h"
|
||||||
|
#include "StrArray.h"
|
||||||
|
#include <direct.h>
|
||||||
|
|
||||||
|
#include <winver.h>
|
||||||
|
//****************************************************************
|
||||||
|
|
||||||
|
Cdir_manager::Cdir_manager(void)
|
||||||
|
{
|
||||||
|
dir_exe[0]=dir_datos[0]=dir_log[0]=dir_work[0]=path_conf[0]=dir_ejecucion[0]=path_ejecutable[0]=0;
|
||||||
|
}
|
||||||
|
//****************************************************************
|
||||||
|
Cdir_manager::~Cdir_manager(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//****************************************************************
|
||||||
|
BOOL Cdir_manager::rellena_dirs_ejecucion()
|
||||||
|
{
|
||||||
|
//char *st;
|
||||||
|
BOOL res=TRUE;
|
||||||
|
if (!_getcwd(dir_ejecucion, sizeof(dir_ejecucion)))
|
||||||
|
{
|
||||||
|
res= FALSE;
|
||||||
|
dir_ejecucion[0]=0;
|
||||||
|
}
|
||||||
|
if(!GetModuleFileName(NULL,path_ejecutable,sizeof(path_ejecutable)))
|
||||||
|
|
||||||
|
{
|
||||||
|
path_ejecutable[0]=0;
|
||||||
|
res=FALSE;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//****************************************************************
|
||||||
|
void Cdir_manager::absoluta( char *ruta )
|
||||||
|
{
|
||||||
|
char aux[256];
|
||||||
|
if (strstr(ruta,D_WORK))
|
||||||
|
{
|
||||||
|
strcpy(aux,dir_work);
|
||||||
|
strcat(aux,&ruta[strlen(D_WORK)]);
|
||||||
|
strcpy(ruta,aux);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strstr(ruta,D_DAT))
|
||||||
|
{
|
||||||
|
strcpy(aux,dir_datos);
|
||||||
|
strcat(aux,&ruta[strlen(D_DAT)]);
|
||||||
|
strcpy(ruta,aux);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strstr(ruta,D_LOG))
|
||||||
|
{
|
||||||
|
strcpy(aux,dir_log);
|
||||||
|
strcat(aux,&ruta[strlen(D_LOG)]);
|
||||||
|
strcpy(ruta,aux);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strstr(ruta,D_APP))
|
||||||
|
{
|
||||||
|
strcpy(aux,dir_exe);
|
||||||
|
strcat(aux,&ruta[strlen(D_APP)]);
|
||||||
|
strcpy(ruta,aux);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strstr(ruta,P_CONG))
|
||||||
|
{
|
||||||
|
strcpy(ruta,P_CONG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
BOOL Cdir_manager::lee_reg( char* clave, C_error *er )
|
||||||
|
{
|
||||||
|
HKEY hKey1;
|
||||||
|
long lRetCode,l2;
|
||||||
|
//abrimos clave----------------------------------------
|
||||||
|
lRetCode = RegOpenKeyEx ( HKEY_CURRENT_USER,clave, 0, KEY_READ | KEY_SET_VALUE,&hKey1);
|
||||||
|
|
||||||
|
if (lRetCode != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
if(er)
|
||||||
|
{
|
||||||
|
er->pon_win("lee_reg");
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
l2 = 256;
|
||||||
|
//leemos carpeta
|
||||||
|
RegQueryValueEx(hKey1,"dir",0,NULL,(LPBYTE) dir_work,(LPDWORD) &l2);
|
||||||
|
//cerramos clave------------------------------------
|
||||||
|
RegCloseKey( hKey1);
|
||||||
|
|
||||||
|
//configuramos rutas--------------------------------
|
||||||
|
sprintf(dir_log,"%s\\log",dir_work);
|
||||||
|
sprintf(dir_exe,"%s\\exe",dir_work);
|
||||||
|
sprintf(dir_datos,"%s\\datos",dir_work);
|
||||||
|
sprintf(path_conf,"%s\\conf.ini",dir_work);
|
||||||
|
//ponemos log---------------------------------------
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
void Cdir_manager::relativa( char *ruta )
|
||||||
|
{
|
||||||
|
char aux[256];
|
||||||
|
if (dir_work[0]&&strstr(ruta,dir_work))
|
||||||
|
{
|
||||||
|
strcpy(aux,D_WORK);
|
||||||
|
strcat(aux,&ruta[strlen(dir_work)]);
|
||||||
|
strcpy(ruta,aux);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (dir_datos[0]&&strstr(ruta,dir_datos))
|
||||||
|
{
|
||||||
|
strcpy(aux,D_DAT);
|
||||||
|
strcat(aux,&ruta[strlen(dir_datos)]);
|
||||||
|
strcpy(ruta,aux);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (dir_log[0]&&strstr(ruta,dir_log))
|
||||||
|
{
|
||||||
|
strcpy(aux,D_LOG);
|
||||||
|
strcat(aux,&ruta[strlen(dir_log)]);
|
||||||
|
strcpy(ruta,aux);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (dir_exe[0]&&strstr(ruta,dir_exe))
|
||||||
|
{
|
||||||
|
strcpy(aux,D_APP);
|
||||||
|
strcat(aux,&ruta[strlen(dir_exe)]);
|
||||||
|
strcpy(ruta,aux);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (path_conf[0]&& strcmp(ruta,path_conf)==0)
|
||||||
|
{
|
||||||
|
strcpy(ruta,P_CONG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
char* Cdir_manager::dir_anterior( char*dir )
|
||||||
|
{
|
||||||
|
int n=(int)strlen(dir);
|
||||||
|
for (int i=n-1;i>0;i--)
|
||||||
|
{
|
||||||
|
if (dir[i]=='\\')
|
||||||
|
{
|
||||||
|
dir[i]=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
char* Cdir_manager::nombre_archivo( char *path,char*nombre )
|
||||||
|
{
|
||||||
|
int n=(int)strlen(path);
|
||||||
|
nombre[0]=0;
|
||||||
|
for (int i=n-1;i>0;i--)
|
||||||
|
{
|
||||||
|
if (path[i]=='\\')
|
||||||
|
{
|
||||||
|
strcpy(nombre,&path[i+1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!nombre[0])
|
||||||
|
strcpy(nombre,path);
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL Cdir_manager::listar( char* dir,StrArray *files,StrArray *dirs/*=NULL*/,BOOL recursivo/*=FALSE*/,C_error *er/*=NULL */,char *omite )
|
||||||
|
{
|
||||||
|
BOOL poner_error=FALSE;
|
||||||
|
BOOL p_c=FALSE;
|
||||||
|
BOOL p_f=FALSE;
|
||||||
|
char str[256];
|
||||||
|
//int k;
|
||||||
|
WIN32_FIND_DATA filedat;
|
||||||
|
HANDLE hfile;
|
||||||
|
|
||||||
|
|
||||||
|
if (!dir)
|
||||||
|
{
|
||||||
|
er->pon("listar","Puntero de listar nulo");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//vemos la info a recopilar--------------------------------------------
|
||||||
|
if (er)
|
||||||
|
poner_error=TRUE;
|
||||||
|
if (dirs)
|
||||||
|
p_c=TRUE;
|
||||||
|
if(files)
|
||||||
|
p_f=TRUE;
|
||||||
|
|
||||||
|
strcpy(str,dir);
|
||||||
|
if (str[strlen(str)-1] != '\\')
|
||||||
|
strcat(str,"\\");
|
||||||
|
strcat(str,"*.*");
|
||||||
|
hfile = FindFirstFile(str,&filedat);
|
||||||
|
|
||||||
|
if (hfile != INVALID_HANDLE_VALUE)//existe dir
|
||||||
|
{
|
||||||
|
// existe el dir
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ((strcmp(filedat.cFileName,".") != 0) &&
|
||||||
|
(strcmp(filedat.cFileName,"..") != 0))
|
||||||
|
{
|
||||||
|
if (!omite||strcmp(omite,filedat.cFileName)!=0)
|
||||||
|
{
|
||||||
|
strcpy(str,dir);
|
||||||
|
if (str[strlen(str)-1] != '\\')
|
||||||
|
strcat(str,"\\");
|
||||||
|
strcat(str,filedat.cFileName);
|
||||||
|
if (filedat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
if (p_c)
|
||||||
|
{
|
||||||
|
dirs->add(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(recursivo && !listar( str,files,dirs,recursivo,er,omite ))
|
||||||
|
{
|
||||||
|
FindClose(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (p_f)
|
||||||
|
{
|
||||||
|
files->add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (FindNextFile(hfile,&filedat));
|
||||||
|
FindClose(hfile);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (poner_error)
|
||||||
|
er->pon_win("lista_file_dir");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
BOOL Cdir_manager::listar_elementos( char *dir,StrArray *files,StrArray *dirs,C_error *er/*=NULL*/)
|
||||||
|
{
|
||||||
|
return listar(dir,files,dirs,FALSE,er);
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
BOOL Cdir_manager::lista_files( char *dir,StrArray *files,BOOL recursivo/*=FALSE*/,C_error *er/*=NULL*/,char *omite/*=NULL*/ )
|
||||||
|
{
|
||||||
|
return listar(dir,files,NULL,recursivo,er,omite);
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
char* Cdir_manager::extension_archivo( char *path )
|
||||||
|
{
|
||||||
|
int n=(int)strlen(path)-1;
|
||||||
|
while(n>=0)
|
||||||
|
{
|
||||||
|
if (path[n]=='.')
|
||||||
|
return &path[n+1];
|
||||||
|
n--;
|
||||||
|
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//******************************************************************************************************************************************
|
||||||
|
BOOL Cdir_manager::crea_dir( char *path )
|
||||||
|
{
|
||||||
|
char dir[MAX_PATH];
|
||||||
|
int i, n;
|
||||||
|
DWORD ftyp;
|
||||||
|
n = (int)strlen(path);
|
||||||
|
if (n<3)
|
||||||
|
return TRUE;
|
||||||
|
memcpy(dir, path, 3);
|
||||||
|
for (i = 3; path[i]; i++)
|
||||||
|
{
|
||||||
|
if (i >= MAX_PATH)
|
||||||
|
return FALSE;
|
||||||
|
if (path[i] == '\\')
|
||||||
|
{
|
||||||
|
dir[i] = 0;
|
||||||
|
//comprueba carpeta------------
|
||||||
|
ftyp = GetFileAttributesA(dir);
|
||||||
|
if ((ftyp == INVALID_FILE_ATTRIBUTES) && !CreateDirectory(dir, NULL))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else if ((path[i] == '.'))
|
||||||
|
return TRUE;
|
||||||
|
dir[i] = path[i];
|
||||||
|
}
|
||||||
|
dir[i] = 0;
|
||||||
|
//comprueba carpeta------------
|
||||||
|
ftyp = GetFileAttributesA(dir);
|
||||||
|
if ((ftyp == INVALID_FILE_ATTRIBUTES) && !CreateDirectory(dir, NULL))
|
||||||
|
return FALSE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
BOOL Cdir_manager::borra_archivos( char *paht, char *ext, BOOL recursivo /*= FALSE*/ )
|
||||||
|
{
|
||||||
|
StrArray lfiles;
|
||||||
|
char *f;
|
||||||
|
if(!Cdir_manager::listar(paht, &lfiles, NULL, recursivo ))
|
||||||
|
return FALSE;
|
||||||
|
for (int i = 0; i<lfiles.size(); i++)
|
||||||
|
{
|
||||||
|
f=lfiles.get((i));
|
||||||
|
|
||||||
|
if(!ext || !strcmp(Cdir_manager::extension_archivo(f),ext))
|
||||||
|
DeleteFile(f);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//*******************************************************************************************
|
||||||
|
char* Cdir_manager::cambia_extension_archivo( char *path, char *pathDst, char *newext )
|
||||||
|
{
|
||||||
|
int n=(int)strlen(path);
|
||||||
|
int i=0;
|
||||||
|
char *c=strrchr(path,'.');
|
||||||
|
while(n>i)
|
||||||
|
{
|
||||||
|
pathDst[i] = path[i];
|
||||||
|
if (&path[i]==c)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
if(newext[0]=='.')
|
||||||
|
strcpy(&pathDst[i],&newext[1]);
|
||||||
|
else
|
||||||
|
strcpy(&pathDst[i],newext);
|
||||||
|
|
||||||
|
return pathDst;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*******************************************************************************************
|
||||||
|
char* Cdir_manager::getVersionFile( char *path, char *buf)
|
||||||
|
{
|
||||||
|
DWORD verHandle = 0;
|
||||||
|
UINT size = 0;
|
||||||
|
LPBYTE lpBuffer = NULL;
|
||||||
|
//DWORD verSize = GetFileVersionInfoSize( "D:\\desa\\BIN\\x64\\debug\\utiles.dll", &verHandle);
|
||||||
|
buf[0]=0;
|
||||||
|
|
||||||
|
char verData[1024];
|
||||||
|
|
||||||
|
if (GetFileVersionInfo( path, verHandle, 1024, verData))
|
||||||
|
{
|
||||||
|
if (VerQueryValue(verData,"\\StringFileInfo\\%04x%04x\\FileDescription\\ProductName",(VOID FAR* FAR*)&lpBuffer,&size))
|
||||||
|
{
|
||||||
|
int ii = 0;
|
||||||
|
}
|
||||||
|
if (VerQueryValue(verData,"\\",(VOID FAR* FAR*)&lpBuffer,&size))
|
||||||
|
{
|
||||||
|
if (size)
|
||||||
|
{
|
||||||
|
VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
|
||||||
|
if (verInfo->dwSignature == 0xfeef04bd)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Doesn't matter if you are on 32 bit or 64 bit,
|
||||||
|
// DWORD is always 32 bits, so first two revision numbers
|
||||||
|
// come from dwFileVersionMS, last two come from dwFileVersionLS
|
||||||
|
sprintf(buf, "%d.%d.%d.%d",
|
||||||
|
( verInfo->dwFileVersionMS >> 16 ) & 0xffff,
|
||||||
|
( verInfo->dwFileVersionMS >> 0 ) & 0xffff,
|
||||||
|
( verInfo->dwFileVersionLS >> 16 ) & 0xffff,
|
||||||
|
( verInfo->dwFileVersionLS >> 0 ) & 0xffff
|
||||||
|
);
|
||||||
|
return buf;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*******************************************************************************************
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
|
||||||
|
class C_error;
|
||||||
|
class StrArray;
|
||||||
|
class UTILES_EXPORT Cdir_manager//clase para manejar carpetas
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//carpetas-------------------------------------------------------
|
||||||
|
char dir_work[FILENAME_MAX];
|
||||||
|
char dir_exe[FILENAME_MAX];
|
||||||
|
char dir_log[FILENAME_MAX];
|
||||||
|
char dir_datos[FILENAME_MAX];
|
||||||
|
//archivos-------------------------------------------------------
|
||||||
|
char path_conf[FILENAME_MAX];
|
||||||
|
//rutas de ejecucion---------------------------------------------
|
||||||
|
char dir_ejecucion[FILENAME_MAX];
|
||||||
|
char path_ejecutable[FILENAME_MAX];
|
||||||
|
//funciones------------------------------------------------------
|
||||||
|
Cdir_manager(void);
|
||||||
|
~Cdir_manager(void);
|
||||||
|
//funciones------------------------------------------------------
|
||||||
|
void absoluta(char *ruta);
|
||||||
|
void relativa(char *ruta);
|
||||||
|
|
||||||
|
BOOL lee_reg(char* clave, C_error *er=NULL);
|
||||||
|
BOOL rellena_dirs_ejecucion();
|
||||||
|
//funciones estaticas---------------------------------------
|
||||||
|
static char* dir_anterior(char*dir);//da el directorio anterior
|
||||||
|
static char* nombre_archivo(char *path,char*nombre);//devuelve en nombre el nombre del archivo
|
||||||
|
static char* extension_archivo(char *path);//te da la extension de un path o de un nombre de archivo
|
||||||
|
static char* cambia_extension_archivo(char *path, char *pathDst, char *newext);//te da la extension de un path o de un nombre de archivo
|
||||||
|
static BOOL crea_dir(char *path);//asegura que existe los directorios indicados
|
||||||
|
static BOOL borra_archivos(char *paht, char *ext, BOOL recursivo = FALSE);//borra archivos de una extension dada, si ext es null borra todos
|
||||||
|
//funciones de listado-----------
|
||||||
|
static BOOL listar_elementos(char *dir,StrArray *files,StrArray *dirs,C_error *er=NULL);//dice los files y las dir dentro de un dir(no recursivo)
|
||||||
|
static BOOL lista_files(char *dir,StrArray *files,BOOL recursivo=FALSE,C_error *er=NULL,char *omite=NULL);
|
||||||
|
|
||||||
|
static BOOL listar( char* dir,StrArray *files,StrArray *dirs=NULL,BOOL recursivo=FALSE,C_error *er=NULL,char *omite=NULL );//funcion generica de listar
|
||||||
|
//devuelve version de el archivo
|
||||||
|
static char* getVersionFile(char *path, char *buf);//buffer de 64 sobra
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,261 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef Cgarray_H
|
||||||
|
#define Cgarray_H
|
||||||
|
|
||||||
|
#define GARRAY_INCREMENT 100
|
||||||
|
#include "b_file.h"
|
||||||
|
//array generico---------------------------------
|
||||||
|
/*
|
||||||
|
Clase para manejar arrays genericos de cualquier tipo de clase o estructura
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
class Cgarray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables----------------------------------------------------------------------------------
|
||||||
|
int m; //cache del array
|
||||||
|
int n; //numero de elementos en array
|
||||||
|
int increment; //valor a incrementar en la cache
|
||||||
|
T* ptr; //array de elementos
|
||||||
|
//**************************************************************
|
||||||
|
//constructores-------------------------------------------------------------------------------
|
||||||
|
//**************************************************************
|
||||||
|
Cgarray()
|
||||||
|
{
|
||||||
|
m=0;
|
||||||
|
ptr=NULL;
|
||||||
|
n=0;
|
||||||
|
increment=GARRAY_INCREMENT;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
Cgarray(int cache)//constructor poniendo en memoria posiciones
|
||||||
|
{
|
||||||
|
m=cache;
|
||||||
|
ptr=(T*)malloc(sizeof(T)*m);
|
||||||
|
if (ptr)
|
||||||
|
memset(ptr,0,m * sizeof(T));
|
||||||
|
else
|
||||||
|
m=0;
|
||||||
|
n=0;
|
||||||
|
increment=GARRAY_INCREMENT;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
~Cgarray()
|
||||||
|
{
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
//funciones-----------------------------------------------------------------------------------
|
||||||
|
//**************************************************************
|
||||||
|
inline T& operator[](int i)//da el elemento i-esimo por referencia
|
||||||
|
{
|
||||||
|
return ptr[i];
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline T* get(int i)//da el elemento i-esimo
|
||||||
|
{
|
||||||
|
return &ptr[i] ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline void remove(int ini, int nelem = 1)
|
||||||
|
{
|
||||||
|
if(ini<0)
|
||||||
|
ini =0;
|
||||||
|
if(ini>=n || nelem<1)
|
||||||
|
return;
|
||||||
|
int fin = ini+nelem;
|
||||||
|
if(fin>=n)
|
||||||
|
{
|
||||||
|
n =ini;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memmove(&ptr[ini], &ptr[fin], (n-fin)*sizeof(T));
|
||||||
|
n-=(fin-ini);
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL operator+(T &e )//añade nuevo elemento
|
||||||
|
{
|
||||||
|
T*pp;
|
||||||
|
if (m<n+1)
|
||||||
|
{
|
||||||
|
m+=increment;
|
||||||
|
if (ptr)
|
||||||
|
pp=(T*)realloc(ptr,sizeof(T)*m);
|
||||||
|
else
|
||||||
|
pp=(T*)malloc(sizeof(T)*m);
|
||||||
|
if (!pp)
|
||||||
|
{
|
||||||
|
m-=increment;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
ptr=pp;
|
||||||
|
memset(&ptr[m-increment],0,increment);
|
||||||
|
}
|
||||||
|
ptr[n]=e;
|
||||||
|
n++;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL operator+=(int mas )//añade memoria para mas elementos
|
||||||
|
{
|
||||||
|
T*pp;
|
||||||
|
int inc=n+mas-m;
|
||||||
|
if (inc>0)
|
||||||
|
{
|
||||||
|
if (inc<increment)
|
||||||
|
inc=increment;
|
||||||
|
m+=inc;
|
||||||
|
if (ptr)
|
||||||
|
pp=(T*)realloc(ptr,sizeof(T)*m);
|
||||||
|
else
|
||||||
|
pp=(T*)malloc(sizeof(T)*m);
|
||||||
|
if (!pp)
|
||||||
|
{
|
||||||
|
m-=inc;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
ptr=pp;
|
||||||
|
memset(&ptr[m-inc],0,inc);
|
||||||
|
}
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL ajusta_mem()
|
||||||
|
{
|
||||||
|
if(n == m)
|
||||||
|
return TRUE;
|
||||||
|
int oldm = m;
|
||||||
|
m = n;
|
||||||
|
if(m<=0 && ptr)
|
||||||
|
{
|
||||||
|
free(ptr);
|
||||||
|
ptr = NULL;
|
||||||
|
m =0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
T* pp=(T*)realloc(ptr,sizeof(T)*m);
|
||||||
|
if(!pp)
|
||||||
|
{
|
||||||
|
m = oldm;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
ptr = pp;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL operator+(Cgarray<T> &e) //añade una lista entera
|
||||||
|
{
|
||||||
|
int inc=n+e.n-m;
|
||||||
|
T*pp;
|
||||||
|
if (inc>0)
|
||||||
|
{
|
||||||
|
if (inc<increment)
|
||||||
|
inc=increment;
|
||||||
|
m+=inc;
|
||||||
|
if (ptr)
|
||||||
|
pp=(T*)realloc(ptr,sizeof(T)*m);
|
||||||
|
else
|
||||||
|
pp=(T*)malloc(sizeof(T)*m);
|
||||||
|
if (!pp)
|
||||||
|
{
|
||||||
|
m-=inc;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
ptr=pp;
|
||||||
|
memset(&ptr[m-inc],0,inc);
|
||||||
|
}
|
||||||
|
memcpy(&ptr[n],e.ptr,e.n*sizeof(T));
|
||||||
|
n+=e.n;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
/*inline BOOL add(Cgarray<T> *e) //añade una lista entera
|
||||||
|
{
|
||||||
|
int inc=n+e->n-m;
|
||||||
|
T*pp;
|
||||||
|
if (inc>0)
|
||||||
|
{
|
||||||
|
if (inc<increment)
|
||||||
|
inc=increment;
|
||||||
|
m+=inc;
|
||||||
|
if (ptr)
|
||||||
|
pp=(T*)realloc(ptr,sizeof(T)*m);
|
||||||
|
else
|
||||||
|
pp=(T*)malloc(sizeof(T)*m);
|
||||||
|
if (!pp)
|
||||||
|
{
|
||||||
|
m-=inc;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
ptr=pp;
|
||||||
|
memset(&ptr[m-inc],0,inc);
|
||||||
|
}
|
||||||
|
memcpy(&ptr[n],e->ptr,e.n*sizeof(T));
|
||||||
|
n+=e->n;
|
||||||
|
return TRUE ;
|
||||||
|
};*/
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL add(T *e, int ne) //añade una lista de elementos
|
||||||
|
{
|
||||||
|
int inc=n+ne-m;
|
||||||
|
if (!e || ne<=0)
|
||||||
|
return FALSE;
|
||||||
|
T*pp;
|
||||||
|
if (inc>0)
|
||||||
|
{
|
||||||
|
if (inc<increment)
|
||||||
|
inc=increment;
|
||||||
|
m+=inc;
|
||||||
|
if (ptr)
|
||||||
|
pp=(T*)realloc(ptr,sizeof(T)*m);
|
||||||
|
else
|
||||||
|
pp=(T*)malloc(sizeof(T)*m);
|
||||||
|
if (!pp)
|
||||||
|
{
|
||||||
|
m-=inc;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
ptr=pp;
|
||||||
|
memset(&ptr[m-inc],0,inc);
|
||||||
|
}
|
||||||
|
memcpy(&ptr[n],e,ne*sizeof(T));
|
||||||
|
n+=ne;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline void borra()//libera la memoria del array
|
||||||
|
{
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
ptr=NULL;
|
||||||
|
m=n=0;
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL graba(Cb_file *file)//graba en archivo el array
|
||||||
|
{
|
||||||
|
if(!file->escribe(&n,sizeof(n)))
|
||||||
|
return FALSE;
|
||||||
|
if(!file->escribe(ptr,n*sizeof(T)))
|
||||||
|
return FALSE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL leer(Cb_file *file)//lee de archivo el array
|
||||||
|
{
|
||||||
|
int nn;
|
||||||
|
if(!file->lee(&nn,sizeof(n)))
|
||||||
|
return FALSE;
|
||||||
|
if( nn<=0 || !((*this)+=nn))
|
||||||
|
return FALSE;
|
||||||
|
if(!file->lee(&ptr[n],nn*sizeof(T)))
|
||||||
|
return FALSE;
|
||||||
|
n+=nn;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
#pragma once
|
||||||
|
//array ciclico (al añadir si no entran mas tira por detras)
|
||||||
|
template <typename T>
|
||||||
|
class Cgarray_cicli
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables-----------------------------------------------------
|
||||||
|
int max_elem;//indica el maximo de elementos que puede almacenar
|
||||||
|
int n;//indica el numero de elementos almacenados
|
||||||
|
int m;//capacidad actual del array
|
||||||
|
int ini;//indice al primer elemento;
|
||||||
|
int increment; //incremento para pedir memo
|
||||||
|
T* ptr; //array de elementos
|
||||||
|
//c y d----------------------------------------------------------
|
||||||
|
//*******************************************************
|
||||||
|
Cgarray_cicli(void)
|
||||||
|
{
|
||||||
|
ptr=NULL;
|
||||||
|
increment=100;
|
||||||
|
ini=0;
|
||||||
|
m=n=0;
|
||||||
|
max_elem=0;
|
||||||
|
};
|
||||||
|
//*******************************************************
|
||||||
|
~Cgarray_cicli(void)
|
||||||
|
{
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
};
|
||||||
|
//*******************************************************
|
||||||
|
inline BOOL inicia(int maxi)//inicia la lista poniendo el maximo de elementos que puede almacenar
|
||||||
|
{
|
||||||
|
if (maxi<=0)
|
||||||
|
return FALSE;
|
||||||
|
max_elem=maxi;
|
||||||
|
n=0;
|
||||||
|
ini=0;
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
ptr=(T*)malloc(sizeof(T)*m);
|
||||||
|
if (!ptr)
|
||||||
|
{
|
||||||
|
max_elem=0;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
};
|
||||||
|
//*******************************************************
|
||||||
|
inline T* operator[](int i)//da el elemento i-esimo
|
||||||
|
{
|
||||||
|
if (max_elem<=0 || i<=0 || i>=n)
|
||||||
|
return NULL;
|
||||||
|
return &ptr[(ini+i)%max_elem];
|
||||||
|
};
|
||||||
|
//*******************************************************
|
||||||
|
inline BOOL operator+(T &e )//añade nuevo elemento
|
||||||
|
{
|
||||||
|
if (max_elem<=0|| !ptr)
|
||||||
|
return FALSE;
|
||||||
|
if (n==max_elem)//esta lleno, pone al inicio-----
|
||||||
|
{
|
||||||
|
memcpy(&ptr[ini],&e,sizeof(T));
|
||||||
|
ini=(ini+1)%max_elem;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//revisa memoria---------------------------------
|
||||||
|
if (m<n+1)
|
||||||
|
{
|
||||||
|
m+=increment;
|
||||||
|
if (ptr)
|
||||||
|
ptr=(T*)realloc(ptr,sizeof(T)*m);
|
||||||
|
else
|
||||||
|
ptr=(T*)malloc(sizeof(T)*m);
|
||||||
|
if (!ptr)
|
||||||
|
{
|
||||||
|
m=n=ini=0;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
memset(&ptr[m-increment],0,increment);
|
||||||
|
}
|
||||||
|
//copia al final---------------------------------
|
||||||
|
memcpy(&ptr[(ini+n)%max_elem],&e,sizeof(T));
|
||||||
|
n++;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//*******************************************************
|
||||||
|
inline void borra()//borra los elementos (no livera memoria)
|
||||||
|
{
|
||||||
|
m=n=ini=0;
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
ptr=NULL;
|
||||||
|
};
|
||||||
|
//*******************************************************
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,156 @@
|
||||||
|
#include "garray.h"
|
||||||
|
//array generico ordenado---------------------------------
|
||||||
|
#ifndef CARRAY_ORD_DEF
|
||||||
|
|
||||||
|
|
||||||
|
#define CARRAY_ORD_DEF
|
||||||
|
#define GARRAY_O_MODO_EXACTO 0 //devuelve el elemento exacto si esta en la lista si no null
|
||||||
|
#define GARRAY_O_MODO_MENOR 1//devuelve el elemento menor mas cercano de la lista(si existe)
|
||||||
|
#define GARRAY_O_MODO_MAYOR 2//devuelve el elemento mayor mas cercano de la lista (si existe)
|
||||||
|
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
class Cgarray_ord
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Cgarray<int> ind;
|
||||||
|
Cgarray<T1> dat;
|
||||||
|
public:
|
||||||
|
int (*f_ord)(T1* e1,T1*e2);//resultado de comparar e1 con e2
|
||||||
|
int (*fcomp)( T2 * t, T1*e);//resultado de comparar t con e
|
||||||
|
int modo;
|
||||||
|
//**************************************************************
|
||||||
|
Cgarray_ord(){f_ord=NULL; fcomp=NULL;modo=GARRAY_O_MODO_EXACTO;};
|
||||||
|
~Cgarray_ord(){};
|
||||||
|
//**************************************************************
|
||||||
|
inline T1& operator[](int i)//da el elemento i-esimo por referencia
|
||||||
|
{
|
||||||
|
return dat[ind[i]];
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline int getix(T2*index)//da el indice elemento segun indexado
|
||||||
|
{
|
||||||
|
int f=dat.n-1, i=0 ,a=-1,res;
|
||||||
|
if((fcomp==NULL))
|
||||||
|
return -1;
|
||||||
|
if(dat.n<=0)
|
||||||
|
return -1;
|
||||||
|
//dicotomica-------------------
|
||||||
|
while(f-i>1)
|
||||||
|
{
|
||||||
|
a=(f-i)/2+i;
|
||||||
|
res=fcomp(index,get(a));
|
||||||
|
if (res<0)
|
||||||
|
f=a;
|
||||||
|
else if (res>0)
|
||||||
|
i=a;
|
||||||
|
else
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
res=fcomp( index,get(f));
|
||||||
|
if(res==0)
|
||||||
|
return f;
|
||||||
|
else if (res<0 && modo==GARRAY_O_MODO_MAYOR)
|
||||||
|
return f;
|
||||||
|
res=fcomp( index, get(i));
|
||||||
|
if(res==0)
|
||||||
|
return i;
|
||||||
|
else if(res>0 && modo==GARRAY_O_MODO_MENOR)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
else if (res<0 && modo==GARRAY_O_MODO_MAYOR)
|
||||||
|
return f;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline T1* getx(T2*index)//da el elemento segun indexado
|
||||||
|
{
|
||||||
|
int i=getix(index);
|
||||||
|
if(i<0)
|
||||||
|
return NULL;
|
||||||
|
return dat.get(ind[i]) ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline T1* get(int i)//da el elemento i-esimo
|
||||||
|
{
|
||||||
|
return dat.get(ind[i]) ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL operator+(T1 &e )//añade nuevo elemento
|
||||||
|
{
|
||||||
|
int f=dat.n-1, i=0 ,a=-1,res;
|
||||||
|
if((f_ord==NULL) || !(ind+=1) || !(dat+e) )
|
||||||
|
return FALSE;
|
||||||
|
//dicotomica-------------------
|
||||||
|
while(f-i>1)
|
||||||
|
{
|
||||||
|
a=(f-i)/2+i;
|
||||||
|
res=f_ord(&e,get(a));
|
||||||
|
if (res<0)
|
||||||
|
f=a;
|
||||||
|
else if (res>0)
|
||||||
|
i=a;
|
||||||
|
else
|
||||||
|
f=i=a;
|
||||||
|
}
|
||||||
|
if (f<0)
|
||||||
|
{
|
||||||
|
a=0;
|
||||||
|
}
|
||||||
|
else if (i!=f || a<0)
|
||||||
|
{
|
||||||
|
res=f_ord(&e,get(f));
|
||||||
|
if (res>0)
|
||||||
|
a=f+1;
|
||||||
|
else if (0>f_ord(&e,get(i)))
|
||||||
|
{
|
||||||
|
a=i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
a=f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((a)<ind.n)
|
||||||
|
memcpy(&ind.ptr[a+1],&ind.ptr[a], sizeof(int)*(ind.n-a));
|
||||||
|
ind.n++;
|
||||||
|
ind[a]=dat.n-1;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL operator+=(int mas )//añade memoria para mas elementos
|
||||||
|
{
|
||||||
|
return ((dat+=mas) && (ind+=mas));
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL operator-=(int i )//borra el elemento iesimo
|
||||||
|
{
|
||||||
|
int idi=ind[i];
|
||||||
|
for(idi=0; idi<ind.n; idi++)
|
||||||
|
{
|
||||||
|
if(ind[idi]>ind[0])
|
||||||
|
ind[idi]--;
|
||||||
|
}
|
||||||
|
if(i<(ind.n-1))
|
||||||
|
memcpy(ind.get(i), ind.get(i+1), sizeof(int)*(ind.n-i-1));
|
||||||
|
if((idi+1)<dat.n)
|
||||||
|
memcpy(dat.get(idi),dat.get(idi+1), sizeof(T1)*(dat.n-idi-1));
|
||||||
|
|
||||||
|
dat.n--;
|
||||||
|
ind.n--;
|
||||||
|
return TRUE;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL operator-(T2*index )//borra el elemento correspondiente a el index
|
||||||
|
{
|
||||||
|
int idi= getix(index);
|
||||||
|
return (idi>=0)&& operator-=(idi);
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
inline void borra()//libera la memoria del array
|
||||||
|
{
|
||||||
|
ind.borra();
|
||||||
|
dat.borra();
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,141 @@
|
||||||
|
#pragma once
|
||||||
|
#define GARRAY_INCREMENT 100
|
||||||
|
//cola generico---------------------------------
|
||||||
|
//+cosas por le final
|
||||||
|
//-por el inicio
|
||||||
|
template <typename T>
|
||||||
|
struct Element_Cgcola
|
||||||
|
{
|
||||||
|
T t;
|
||||||
|
Element_Cgcola<T> *ant;
|
||||||
|
Element_Cgcola<T> *sig;
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class Cgcola
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables----------------------------------------------------------------------------------
|
||||||
|
int n; //numero de elementos en array
|
||||||
|
Element_Cgcola<T> *ini; //inicio del array
|
||||||
|
Element_Cgcola<T> *fin; //fin del array
|
||||||
|
//**************************************************************
|
||||||
|
//constructores-------------------------------------------------------------------------------
|
||||||
|
//**************************************************************
|
||||||
|
Cgcola()
|
||||||
|
{
|
||||||
|
ini=fin=NULL;
|
||||||
|
n=0;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
~Cgcola()
|
||||||
|
{
|
||||||
|
borra();
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
//funciones-----------------------------------------------------------------------------------
|
||||||
|
//**************************************************************
|
||||||
|
virtual inline T* operator++()//da puntero al ultimo elemento
|
||||||
|
{
|
||||||
|
if (fin)
|
||||||
|
return &fin->t;
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
virtual inline T* operator--()//da puntero al primero
|
||||||
|
{
|
||||||
|
if(ini)
|
||||||
|
return &ini->t;
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
virtual inline BOOL operator+(T &e )//añade al final
|
||||||
|
{
|
||||||
|
if (fin)
|
||||||
|
{
|
||||||
|
fin->sig=(Element_Cgcola<T>*)malloc(sizeof(Element_Cgcola<T>));
|
||||||
|
if (!fin->sig)
|
||||||
|
return FALSE;
|
||||||
|
fin->sig->ant=fin;
|
||||||
|
fin=fin->sig;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fin=(Element_Cgcola<T>*)malloc(sizeof(Element_Cgcola<T>));
|
||||||
|
if (!fin)
|
||||||
|
return FALSE;
|
||||||
|
ini=fin;
|
||||||
|
fin->ant=NULL;
|
||||||
|
}
|
||||||
|
fin->t=e;
|
||||||
|
fin->sig=NULL;
|
||||||
|
n++;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
virtual inline BOOL operator-(T &e) //añade al principio
|
||||||
|
{
|
||||||
|
if (ini)
|
||||||
|
{
|
||||||
|
ini->ant=(Element_Cgcola<T>*)malloc(sizeof(Element_Cgcola<T>));
|
||||||
|
if (!ini->ant)
|
||||||
|
return FALSE;
|
||||||
|
ini->ant->sig=ini;
|
||||||
|
ini=ini->ant;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ini=(Element_Cgcola<T>*)malloc(sizeof(Element_Cgcola<T>));
|
||||||
|
if (!ini)
|
||||||
|
return FALSE;
|
||||||
|
fin=ini;
|
||||||
|
ini->sig=NULL;
|
||||||
|
}
|
||||||
|
ini->t=e;
|
||||||
|
ini->ant=NULL;
|
||||||
|
n++;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
virtual inline BOOL operator+=(T* e )//da el ultimo u lo elimina
|
||||||
|
{
|
||||||
|
if (!fin)
|
||||||
|
return FALSE;
|
||||||
|
*e=fin->t;
|
||||||
|
Element_Cgcola<T> *el=fin;
|
||||||
|
fin=fin->ant;
|
||||||
|
fin->sig=NULL;
|
||||||
|
if (!fin)
|
||||||
|
ini=fin;
|
||||||
|
free(el);
|
||||||
|
n--;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
virtual inline BOOL operator-=(T* e )//da el primero y lo elimina
|
||||||
|
{
|
||||||
|
if (!ini)
|
||||||
|
return FALSE;
|
||||||
|
*e=ini->t;
|
||||||
|
Element_Cgcola<T> *el=ini;
|
||||||
|
ini=ini->sig;
|
||||||
|
if (!ini)
|
||||||
|
fin=ini;
|
||||||
|
else
|
||||||
|
ini->ant=NULL;
|
||||||
|
free(el);
|
||||||
|
n--;
|
||||||
|
return TRUE ;
|
||||||
|
};
|
||||||
|
//**************************************************************
|
||||||
|
virtual inline void borra()//libera la memoria del array
|
||||||
|
{
|
||||||
|
while(ini)
|
||||||
|
{
|
||||||
|
fin=ini->sig;
|
||||||
|
free(ini);
|
||||||
|
ini=fin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,118 @@
|
||||||
|
#pragma once
|
||||||
|
#include "gcola.h"
|
||||||
|
#include "lock.h"
|
||||||
|
//cola concurrente para usar con multiples thread
|
||||||
|
template <typename T>
|
||||||
|
class Cgcola_con :
|
||||||
|
public Cgcola<T>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables--------------------------------------------------------------------------------
|
||||||
|
Clock cerrojo;//interlock para protejer la cola
|
||||||
|
int modo;//modo 0 bloqueante, modo 1 no bloqueante
|
||||||
|
//funciones--------------------------------------------------------------------------------
|
||||||
|
//*************************************************************************
|
||||||
|
Cgcola_con(void)
|
||||||
|
:Cgcola()
|
||||||
|
{
|
||||||
|
modo=0;
|
||||||
|
};
|
||||||
|
//*************************************************************************
|
||||||
|
virtual ~Cgcola_con(void)
|
||||||
|
{
|
||||||
|
borra();
|
||||||
|
};
|
||||||
|
//*************************************************************************
|
||||||
|
//*************************************************************************
|
||||||
|
virtual inline T* operator++()//da puntero al ultimo elemento
|
||||||
|
{
|
||||||
|
T* res=NULL;
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
if(!cerrojo.puedo())
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cerrojo.entro();
|
||||||
|
res= Cgcola::operator++();
|
||||||
|
cerrojo.salgo();
|
||||||
|
return res;
|
||||||
|
|
||||||
|
};
|
||||||
|
//*************************************************************************
|
||||||
|
virtual inline T* operator--()//da puntero al primero
|
||||||
|
{
|
||||||
|
T* res=NULL;
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
if(!cerrojo.puedo())
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cerrojo.entro();
|
||||||
|
res= Cgcola::operator--();
|
||||||
|
cerrojo.salgo();
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
//*************************************************************************
|
||||||
|
virtual inline BOOL operator+(T &e )//añade al final
|
||||||
|
{
|
||||||
|
BOOL res=FALSE;
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
if(!cerrojo.puedo())
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cerrojo.entro();
|
||||||
|
res= Cgcola::operator+(e);
|
||||||
|
cerrojo.salgo();
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
//*************************************************************************
|
||||||
|
virtual inline BOOL operator-(T &e) //añade al principio
|
||||||
|
{
|
||||||
|
BOOL res=FALSE;
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
if(!cerrojo.puedo())
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cerrojo.entro();
|
||||||
|
res= Cgcola::operator-(e);
|
||||||
|
cerrojo.salgo();
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
//*************************************************************************
|
||||||
|
virtual inline BOOL operator+=(T* e )//da el ultimo y lo elimina
|
||||||
|
{
|
||||||
|
BOOL res=FALSE;
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
if(!cerrojo.puedo())
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cerrojo.entro();
|
||||||
|
res= Cgcola::operator+=(e);
|
||||||
|
cerrojo.salgo();
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
//*************************************************************************
|
||||||
|
virtual inline BOOL operator-=(T* e )//da el primero y lo elimina
|
||||||
|
{
|
||||||
|
BOOL res=FALSE;
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
if(!cerrojo.puedo())
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cerrojo.entro();
|
||||||
|
res= Cgcola::operator-=(e);
|
||||||
|
cerrojo.salgo();
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
//*************************************************************************
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "gconect_srv.h"
|
||||||
|
|
||||||
|
//*****************************************************************************************************************
|
||||||
|
Cgconect_srv::Cgconect_srv(void)
|
||||||
|
{
|
||||||
|
nconex=0;
|
||||||
|
fin=FALSE;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************************
|
||||||
|
Cgconect_srv::~Cgconect_srv(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************************
|
||||||
|
void Cgconect_srv::log_ext( __time64_t tiemp, char *modulo, char *fmt )
|
||||||
|
{
|
||||||
|
Msg_evento_log m;
|
||||||
|
m.tiempo=tiemp;
|
||||||
|
strcpy(m.nivel,modulo);
|
||||||
|
strcpy(m.nivel,fmt);
|
||||||
|
inter_msg.entro();
|
||||||
|
mens+m;
|
||||||
|
inter_msg.salgo();
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************************
|
||||||
|
Cproceso_cliente* Cgconect_srv::crea_cliente( void )
|
||||||
|
{
|
||||||
|
if (fin)
|
||||||
|
return NULL;
|
||||||
|
Cclient_gconect_srv *cli=new Cclient_gconect_srv();
|
||||||
|
if (!cli)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
strcpy(cli->nombre, "Cliente gconex_srv");
|
||||||
|
cli->principal = this;
|
||||||
|
nconex++;
|
||||||
|
return cli;
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************************
|
||||||
|
|
||||||
|
//*****************************************************************************************************************
|
||||||
|
void Cclient_gconect_srv::rum()
|
||||||
|
{
|
||||||
|
int nv=0;//numero de veces esperando sin recivir nada
|
||||||
|
int nb;//numero de bytes recividos en el paquete
|
||||||
|
BOOL procesa=FALSE;//indica si hay paquetes a procesar
|
||||||
|
BYTE *buffer;//buffer donde se almacena paquete recibido
|
||||||
|
BYTE buf[256];//buffer secundario de envios
|
||||||
|
Usuario_conx_0 *usu=NULL;//usuario logeado
|
||||||
|
codifica=FALSE;//indica si la comunicacion va cifrada
|
||||||
|
while(!*soc->pirate && nv<6000 && !principal->fin)
|
||||||
|
{
|
||||||
|
//pillapaquete-----------------------------------------
|
||||||
|
if(!soc->recibe_package(0))
|
||||||
|
{
|
||||||
|
Sleep(10);
|
||||||
|
nv++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (soc->cab.nb>0)
|
||||||
|
{
|
||||||
|
nb=soc->cab.nb;
|
||||||
|
procesa=TRUE;
|
||||||
|
codifica=0;
|
||||||
|
nv=0;
|
||||||
|
if (soc->cab.flags & FLAG_PACKAGE_HEAD_0_ENCRIPT1)
|
||||||
|
codifica=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nb<sizeof(int))//recivida basura
|
||||||
|
continue;
|
||||||
|
if (!procesa || principal->fin )
|
||||||
|
continue;
|
||||||
|
nv=0;
|
||||||
|
procesa=FALSE;
|
||||||
|
//se resta lo que ocupa el entero
|
||||||
|
nb-=sizeof(int);
|
||||||
|
if (nb>0)
|
||||||
|
buffer=&soc->buf[sizeof(int)];
|
||||||
|
else
|
||||||
|
buffer=FALSE;
|
||||||
|
//procesa paquete-------------------------------------------------------------------
|
||||||
|
switch(*(int*)soc->buf)
|
||||||
|
{
|
||||||
|
case PETICION_GENERAL_PRESENTA:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PETICION_GENERAL_OK:
|
||||||
|
{
|
||||||
|
//theApp.log.loguea(_time64(NULL),"cliente","Recivido paquete ok");
|
||||||
|
buf[0]=PETICION_GENERAL_OK;
|
||||||
|
soc->envia_package(buf,1,codifica);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PETICION_GENERAL_DESCONECTA:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PETICION_GENERAL_DAME_LOG://hace falta login
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PETICION_GENERAL_TOMA_COMANDO://hace falta login
|
||||||
|
{
|
||||||
|
principal->escucha->on_recivido(soc,buffer,nb);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default://paquete desconocido se cierra socket
|
||||||
|
{
|
||||||
|
*soc->pirate=TRUE;//sale el thead
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//descontamos thread---------------------------------------------------------
|
||||||
|
principal->escucha->borra_cliente(this);
|
||||||
|
}
|
||||||
|
//*****************************************************************************************************************
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
#pragma once
|
||||||
|
#include "_log.h"
|
||||||
|
#include "garray_cicli.h"
|
||||||
|
#include "proceso_cliente.h"
|
||||||
|
#include "sock_sv.h"
|
||||||
|
//falta hacer login revision de paquetes y clase generica de usuarios
|
||||||
|
class Cclient_gconect_srv;
|
||||||
|
class UTILES_EXPORT C_escucha_conex_srv//clase para escuchar paquetes recividos en conex_srv
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void on_recivido(Csock_cl *soc, BYTE *buf, int nb)=0;//puntero a socket, puntero a paquete, numero de bytes del paquete
|
||||||
|
//para desconectar poner a true la variable pirate del soc
|
||||||
|
virtual void borra_cliente(Cclient_gconect_srv *cli)=0;//funcion en la que se entra cuando se cierra un cliente(se ha de mandar un mensaje a el principal)
|
||||||
|
//no se olvide de restar 1 al numero de thread
|
||||||
|
};
|
||||||
|
//clase conexion entre servidores (servicios) y aplicaciones de administracion
|
||||||
|
class UTILES_EXPORT Cgconect_srv: public C_escucha_log, public Cescucha_sock_sv
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables----------------------------
|
||||||
|
Cgarray_cicli<Msg_evento_log> mens;//cola de mensajes de log
|
||||||
|
Clock inter_msg;//interlock para protejer cola de mensajes
|
||||||
|
Csock_sv soc_sv;//socket de escucha
|
||||||
|
C_escucha_conex_srv *escucha;//recibe paquetes de conexion si no son de log
|
||||||
|
BOOL fin;//indica si hay que irse o no;
|
||||||
|
int nconex;//indica el numero de conexiones activas en el momento
|
||||||
|
/*Clock inter_conex;//interlock para gestionar clientes
|
||||||
|
Csock_cl *soc_basura;//puntero a socket para borrar*/
|
||||||
|
|
||||||
|
//v y d--------------------------------
|
||||||
|
Cgconect_srv(void);
|
||||||
|
~Cgconect_srv(void);
|
||||||
|
|
||||||
|
//funciones----------------------------
|
||||||
|
|
||||||
|
virtual void log_ext( __time64_t tiemp, char *modulo, char *fmt );//pone otro mensaje en cola
|
||||||
|
virtual Cproceso_cliente* crea_cliente( void );//funcion que crea el cliente
|
||||||
|
|
||||||
|
};
|
||||||
|
class UTILES_EXPORT Cclient_gconect_srv: public Cproceso_cliente//thread de clientes
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BOOL codifica;//indica si la comunicacion va cifrada
|
||||||
|
Cgconect_srv *principal;//puntero a clase principal
|
||||||
|
virtual void rum();//funcion thead de conexion
|
||||||
|
|
||||||
|
};
|
||||||
|
//consejos de utilizacion-----------------------------------------
|
||||||
|
/*
|
||||||
|
crear clase y configurar interface (escucha).
|
||||||
|
configurar socket y poner en lisener.
|
||||||
|
|
||||||
|
En el evento borra_cliente enviar un mensaje al que a creado el socket listener.
|
||||||
|
Dentro de dicho mensaje restar 1 a la variable nconex y hacer un delete al argumento de cliente
|
||||||
|
|
||||||
|
para finalizar la aplicación poner a true la variable fin y esperar a que salgan todos los clientes conectados (nconex<=0)
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,250 @@
|
||||||
|
#pragma once
|
||||||
|
#include "garray.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Ordenaciones de varias ordenaciones de un array
|
||||||
|
la funcion de orden f_ord(e1, e2)
|
||||||
|
ha de devolver <0 si e1<e2
|
||||||
|
0 si e1=e2
|
||||||
|
>0 si e1>e2
|
||||||
|
*/
|
||||||
|
typedef struct Indices_gorden
|
||||||
|
{
|
||||||
|
int i; //indice a a elemento con esta posicion
|
||||||
|
int io;//posicion que ocupa el elemento de la lista original en este orden
|
||||||
|
}Indices_gorden;
|
||||||
|
typedef struct Orden_gorden
|
||||||
|
{
|
||||||
|
int (*f_ord)(void* e1, void*e2);//funcion de orden
|
||||||
|
Cgarray<Indices_gorden> ind;//indices
|
||||||
|
}Orden_gorden;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Cgorden
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//variables-----------------------------------
|
||||||
|
Cgarray<Orden_gorden> ord;
|
||||||
|
Cgarray<T> *elem;
|
||||||
|
//c y d---------------------------------------
|
||||||
|
//**************************************************************
|
||||||
|
Cgorden(Cgarray<T> *el=NULL)
|
||||||
|
{
|
||||||
|
elem=el;
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
~Cgorden()
|
||||||
|
{
|
||||||
|
//borramos arrays
|
||||||
|
for (int i=0; i<ord.n; i++)
|
||||||
|
{
|
||||||
|
if(ord[i].ind.ptr)
|
||||||
|
{
|
||||||
|
free(ord[i].ind.ptr);
|
||||||
|
ord[i].ind.n=ord[i].ind.m=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//**************************************************************
|
||||||
|
inline BOOL add_ord(int (*f_ord)(void*, void*))//añade un orden nuevo
|
||||||
|
{
|
||||||
|
Indices_gorden ii;
|
||||||
|
int i;
|
||||||
|
Orden_gorden o;
|
||||||
|
//inicia orden------------------
|
||||||
|
o.f_ord=f_ord;
|
||||||
|
o.ind+=elem->n;
|
||||||
|
for(i=0; i<elem->n; i++)
|
||||||
|
{
|
||||||
|
ii.i=i;
|
||||||
|
o.ind+ii;
|
||||||
|
}
|
||||||
|
//-------------------------------
|
||||||
|
//ordena
|
||||||
|
ord_qsort(0,elem->n-1,&o);
|
||||||
|
//reasigna----------------------------
|
||||||
|
for(i=0; i<elem->n; i++)
|
||||||
|
o.ind[o.ind[i].i]=i;
|
||||||
|
//añade el orden-----------------
|
||||||
|
|
||||||
|
ord+o;
|
||||||
|
o.ind.ptr=NULL;
|
||||||
|
o.ind.m=0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
inline T* get(int i, int o)//da el elemento iesimo del orden o
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
inline int geti(int i, int o)//da el indice del elemento que iesimo del orden o
|
||||||
|
{
|
||||||
|
return ord[o].ind[i].i;
|
||||||
|
}
|
||||||
|
//**************************************************************
|
||||||
|
inline int geti(int i, int o, int oi)//da el la posicion que tiene el iesimo del orden o en el orden oi
|
||||||
|
{
|
||||||
|
return ord[oi].ind[ord[o].ind[i].i].io;
|
||||||
|
}
|
||||||
|
//******************************************************************
|
||||||
|
inline void ord_qsort(int ini, int fin, Orden_gorden *o)
|
||||||
|
{
|
||||||
|
int ii,kf,ki, jf,ji,p1,p, com;
|
||||||
|
BOOL bus=TRUE;
|
||||||
|
//caso base-------------------
|
||||||
|
p=(fin-ini);
|
||||||
|
if(p<1)
|
||||||
|
return;
|
||||||
|
if (p<2)
|
||||||
|
{
|
||||||
|
if(0<o->f_ord(elem->get(o->ind[ini].i),elem->get(o->ind[fin].i)))
|
||||||
|
{
|
||||||
|
ii=o->ind[ini].i;
|
||||||
|
o->ind[ini].i=o->ind[fin].i;
|
||||||
|
o->ind[fin].i=ii;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//a pivotar-------------------
|
||||||
|
//inicializacion
|
||||||
|
p+=ini;
|
||||||
|
p1=p;
|
||||||
|
kf=fin;
|
||||||
|
ki=ini;
|
||||||
|
jf=ji=-1;
|
||||||
|
while(bus)
|
||||||
|
{
|
||||||
|
//busca por la izquierda-----
|
||||||
|
while(p>ki)
|
||||||
|
{
|
||||||
|
com=o->f_ord(elem->get(o->ind[p].i),elem->get(o->ind[ki].i));
|
||||||
|
if(com<0)
|
||||||
|
{
|
||||||
|
if(jf>=0)
|
||||||
|
{
|
||||||
|
ii=o->ind[jf].i;
|
||||||
|
o->ind[jf].i=o->ind[ki].i;
|
||||||
|
o->ind[ki].i=ii;
|
||||||
|
jf=-1;
|
||||||
|
ki++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ji=ki;//encontrado tio que va al otro lado
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(com==0)
|
||||||
|
{
|
||||||
|
//elementos iguales se pone al centro
|
||||||
|
p--;
|
||||||
|
ii=o->ind[p].i;
|
||||||
|
o->ind[p].i=o->ind[ki].i;
|
||||||
|
o->ind[ki].i=ii;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ki++;
|
||||||
|
}
|
||||||
|
//busca por la derecha-----
|
||||||
|
while(p1<kf)
|
||||||
|
{
|
||||||
|
com=o->f_ord(elem->get(o->ind[p1].i),elem->get(o->ind[kf].i));
|
||||||
|
if(com>0)
|
||||||
|
{
|
||||||
|
if(ji>=0)
|
||||||
|
{
|
||||||
|
ii=o->ind[ji].i;
|
||||||
|
o->ind[ji].i=o->ind[kf].i;
|
||||||
|
o->ind[kf].i=ii;
|
||||||
|
ji=-1;
|
||||||
|
kf--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jf=kf;//encontrado tio que va al otro lado
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(com==0)
|
||||||
|
{
|
||||||
|
//elementos iguales se pone al centro
|
||||||
|
p1++;
|
||||||
|
ii=o->ind[p1].i;
|
||||||
|
o->ind[p1].i=o->ind[kf].i;
|
||||||
|
o->ind[kf].i=ii;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
kf--;
|
||||||
|
}
|
||||||
|
//condicion de fuga---
|
||||||
|
bus=(p>ki) && (p1<kf);
|
||||||
|
}
|
||||||
|
//falta por ordenar de un lado
|
||||||
|
//lo malo es que tocara mover memo
|
||||||
|
//se puede sin mover memo
|
||||||
|
if(p>ki)
|
||||||
|
{
|
||||||
|
//falta la izquierda-----------------
|
||||||
|
while(p>ki)
|
||||||
|
{
|
||||||
|
com=o->f_ord(elem->get(o->ind[p].i),elem->get(o->ind[ki].i));
|
||||||
|
if(com<0)
|
||||||
|
{
|
||||||
|
//cambia elemento al otro lado del pivote
|
||||||
|
ii=o->ind[p-1].i;
|
||||||
|
o->ind[p-1].i=o->ind[p1].i;
|
||||||
|
o->ind[p1].i=o->ind[ki].i;
|
||||||
|
o->ind[ki].i=ii;
|
||||||
|
p--;
|
||||||
|
p1--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if(com==0)
|
||||||
|
{
|
||||||
|
//elementos iguales se pone al centro
|
||||||
|
p--;
|
||||||
|
ii=o->ind[p].i;
|
||||||
|
o->ind[p].i=o->ind[ki].i;
|
||||||
|
o->ind[ki].i=ii;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ki++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while(p1<kf)
|
||||||
|
{
|
||||||
|
com=o->f_ord(elem->get(o->ind[p1].i),elem->get(o->ind[kf].i));
|
||||||
|
if(com<0)
|
||||||
|
{
|
||||||
|
//cambia elemento al otro lado del pivote
|
||||||
|
ii=o->ind[p1+1].i;
|
||||||
|
o->ind[p1+1].i=o->ind[p].i;
|
||||||
|
o->ind[p].i=o->ind[kf].i;
|
||||||
|
o->ind[kf].i=ii;
|
||||||
|
p++;
|
||||||
|
p1++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if(com==0)
|
||||||
|
{
|
||||||
|
//elementos iguales se pone al centro
|
||||||
|
p1++;
|
||||||
|
ii=o->ind[p1].i;
|
||||||
|
o->ind[p1].i=o->ind[kf].i;
|
||||||
|
o->ind[kf].i=ii;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
kf--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ord_qsort(ini, p-1, o);
|
||||||
|
ord_qsort(p1+1, fin, o);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,451 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "ini_file.h"
|
||||||
|
#include "_error.h"
|
||||||
|
//*********************************************************************************
|
||||||
|
Cini_file::Cini_file(C_error* err)
|
||||||
|
{
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
borra_error=FALSE;
|
||||||
|
er=err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
er= new C_error();
|
||||||
|
borra_error=TRUE;
|
||||||
|
}
|
||||||
|
grupos.z=sizeof(Ini_file_grupo);
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
Cini_file::~Cini_file(void)
|
||||||
|
{
|
||||||
|
if (er && borra_error)
|
||||||
|
{
|
||||||
|
delete er;
|
||||||
|
}
|
||||||
|
borra();
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
void Cini_file::borra()
|
||||||
|
{
|
||||||
|
Ini_file_grupo*g;
|
||||||
|
for (int i=0; i<grupos.n; i++)
|
||||||
|
{
|
||||||
|
g=(Ini_file_grupo *)grupos.get(i);
|
||||||
|
g->prop.borra();
|
||||||
|
}
|
||||||
|
grupos.borra();
|
||||||
|
str.borra();
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
int Cini_file::get_grupo( char* gr )
|
||||||
|
{
|
||||||
|
Ini_file_grupo *g;
|
||||||
|
char*aux;
|
||||||
|
//buscamos grupo------------------------------------------------
|
||||||
|
for (int i=0; i<grupos.n; i++)
|
||||||
|
{
|
||||||
|
g=(Ini_file_grupo *) grupos.get(i);
|
||||||
|
aux=str.get(g->n);
|
||||||
|
if(!(g->flags & INI_FILE_FLAGS_VACIO)&& aux && (strcmp(gr,aux)==0))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
//no se encontro-------------------------------------------------
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
int Cini_file::geti_valor( int gr,char *pro )
|
||||||
|
{
|
||||||
|
Ini_file_grupo *g;
|
||||||
|
Ini_file_props *p;
|
||||||
|
char* aux;
|
||||||
|
g=(Ini_file_grupo *) grupos.get(gr);
|
||||||
|
if (!g|| (g->flags & INI_FILE_FLAGS_VACIO))
|
||||||
|
return -1;
|
||||||
|
//buscamos entre las propiedades del grupo-----------------------
|
||||||
|
for (int i=0; i<g->prop.n; i++)
|
||||||
|
{
|
||||||
|
p=g->get(i);
|
||||||
|
aux=str.get(p->p);
|
||||||
|
if((!(p->flags & INI_FILE_FLAGS_VACIO))&& aux && strcmp(pro,aux)==0)
|
||||||
|
return p->v;
|
||||||
|
}
|
||||||
|
//no se encontro-------------------------------------------------
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
char* Cini_file::busca( char *str,char c )
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
while(str[i])
|
||||||
|
{
|
||||||
|
if (str[i]==c)
|
||||||
|
return &str[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
//no encontrado-------------------------------------------
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
|
||||||
|
BOOL Cini_file::lee( char *path )
|
||||||
|
{
|
||||||
|
char *buf=NULL;
|
||||||
|
char *ini;
|
||||||
|
char *aux;
|
||||||
|
Ini_file_grupo *g;
|
||||||
|
Ini_file_props *p;
|
||||||
|
char log_[128];
|
||||||
|
|
||||||
|
HANDLE hfile=INVALID_HANDLE_VALUE;
|
||||||
|
DWORD dw,nb;
|
||||||
|
//abrimos archivo---------------------
|
||||||
|
|
||||||
|
hfile = CreateFile(path, GENERIC_READ, 0, NULL,
|
||||||
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_INI_FILE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nb=SetFilePointer(hfile,0,NULL,FILE_END);
|
||||||
|
if(nb==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_INI_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
buf=(char *)malloc(nb+2);
|
||||||
|
|
||||||
|
dw=SetFilePointer(hfile,0,NULL,FILE_BEGIN);
|
||||||
|
if(dw==INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_INI_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
if (!ReadFile(hfile, (LPSTR) buf ,nb,&dw,NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_INI_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
CloseHandle(hfile);
|
||||||
|
hfile=NULL;
|
||||||
|
buf[nb]=0;
|
||||||
|
buf[nb+1]=0;//aseguramos el final de la cadena;
|
||||||
|
ini=buscamos_grupo(buf);
|
||||||
|
//cargamos ini----------------------------
|
||||||
|
while(*ini)//mientras no estemos en el final
|
||||||
|
{
|
||||||
|
//pillamos grupo---------------------
|
||||||
|
|
||||||
|
aux=busca(ini,']');
|
||||||
|
|
||||||
|
if (!aux)
|
||||||
|
{
|
||||||
|
break;//no mas grupos-----------
|
||||||
|
}
|
||||||
|
//añadimos grupo--------------------
|
||||||
|
*aux=0;
|
||||||
|
g=set_coun();
|
||||||
|
g->n=str.size();
|
||||||
|
g->flags=0;
|
||||||
|
g->inicia();
|
||||||
|
str.add(ini);
|
||||||
|
ini=aux+2;
|
||||||
|
|
||||||
|
if (*ini=='\r')
|
||||||
|
ini=ini+1;
|
||||||
|
//buscamos propiedades del grupo---
|
||||||
|
while(*ini &&*ini!='[')
|
||||||
|
{
|
||||||
|
if (*ini=='\n'||*ini==13)
|
||||||
|
{
|
||||||
|
ini=ini+1;
|
||||||
|
|
||||||
|
if (*ini=='\r')
|
||||||
|
ini=ini+1;
|
||||||
|
}
|
||||||
|
ini=busca_prop(ini);
|
||||||
|
if (*ini=='[')
|
||||||
|
{
|
||||||
|
ini=ini+1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(!*ini)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
aux=ini+strlen(ini);
|
||||||
|
//añadimos propiedad------
|
||||||
|
p=g->set_coun();
|
||||||
|
p->flags=0;
|
||||||
|
p->p=str.size();
|
||||||
|
str.add(ini);
|
||||||
|
ini=aux+1;
|
||||||
|
aux=busca(ini,'\n');
|
||||||
|
if (!aux)
|
||||||
|
{
|
||||||
|
sprintf(log_,"lee: archivo ini defectuoso, no se encuentra valor de %s",str.get(p->p));
|
||||||
|
er->pon(MODULO_INI_FILE,log_);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
*aux=0;
|
||||||
|
if (*(aux -1)==13)
|
||||||
|
{
|
||||||
|
*(aux-1)=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
p->v=str.size();
|
||||||
|
str.add(ini);
|
||||||
|
ini=aux+1;
|
||||||
|
//quitamos retorno de carro si hay
|
||||||
|
if (*ini=='\r')
|
||||||
|
ini=ini+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//nos aseguramos que estamos al inicio del grupo----
|
||||||
|
if(*ini=='[')
|
||||||
|
ini=ini+1;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (buf)
|
||||||
|
{
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
//error al leer-----------------------
|
||||||
|
salgo:
|
||||||
|
borra();
|
||||||
|
if(hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
CloseHandle(hfile);
|
||||||
|
if (buf)
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
char* Cini_file::buscamos_grupo( char *st )
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
char busco;
|
||||||
|
busco='[';
|
||||||
|
while(st[i])//mientras no sea 0 (fin de cadeba)
|
||||||
|
{
|
||||||
|
if (st[i]==busco)
|
||||||
|
{
|
||||||
|
if (busco!='[')
|
||||||
|
busco='[';
|
||||||
|
else
|
||||||
|
return &st[i+1];//grupo encontrado
|
||||||
|
}
|
||||||
|
if (st[i]==';')//encontrado comentario
|
||||||
|
busco='\n';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return &st[i];
|
||||||
|
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
Ini_file_grupo* Cini_file::set_coun()
|
||||||
|
{
|
||||||
|
grupos.reserva();
|
||||||
|
grupos.n++;
|
||||||
|
return (Ini_file_grupo*) &grupos.buf[grupos.z*(grupos.n-1)];
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
char* Cini_file::busca_prop( char* st )
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
char busco;
|
||||||
|
busco='=';
|
||||||
|
char*resul=st;
|
||||||
|
while(st[i])//mientras no sea 0 (fin de cadeba)
|
||||||
|
{
|
||||||
|
if (st[i]==busco)
|
||||||
|
{
|
||||||
|
if (busco=='\n')
|
||||||
|
{
|
||||||
|
busco='=';
|
||||||
|
if (st[i+1]=='\r')
|
||||||
|
i++;
|
||||||
|
resul=&st[i+1];
|
||||||
|
}
|
||||||
|
else if (busco=='=')
|
||||||
|
{
|
||||||
|
st[i]=0;
|
||||||
|
return resul;//propiedad encontrada
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (st[i]==';')//encontrado comentario
|
||||||
|
busco='\n';
|
||||||
|
else if(st[i]=='[')//encontrado grupo nuevo
|
||||||
|
{
|
||||||
|
if (busco!=13)//si no esta en un comentario
|
||||||
|
return &st[i];
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return &st[i];
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
char* Cini_file::get( int gr,char *pro )
|
||||||
|
{
|
||||||
|
int val=geti_valor(gr,pro);
|
||||||
|
if (val<0)
|
||||||
|
return NULL;
|
||||||
|
return str.get(val);
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
char* Cini_file::get( int gr,char *pro, char *def)
|
||||||
|
{
|
||||||
|
int val=geti_valor(gr,pro);
|
||||||
|
if (val<0)
|
||||||
|
return def;
|
||||||
|
return str.get(val);
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
int Cini_file::get( int gr,char *pro, int def )
|
||||||
|
{
|
||||||
|
int val=geti_valor(gr,pro);
|
||||||
|
if (val<0)
|
||||||
|
return def;
|
||||||
|
return atoi(str.get(val));
|
||||||
|
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
double Cini_file::get( int gr,char *pro, double def )
|
||||||
|
{
|
||||||
|
int val=geti_valor(gr,pro);
|
||||||
|
if (val<0)
|
||||||
|
return def;
|
||||||
|
return atof(str.get(val));
|
||||||
|
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
BOOL Cini_file::guarda( char *path )
|
||||||
|
{
|
||||||
|
HANDLE hfile=INVALID_HANDLE_VALUE;
|
||||||
|
DWORD dw;
|
||||||
|
int kk;
|
||||||
|
char stra[512];
|
||||||
|
Ini_file_grupo *g;
|
||||||
|
Ini_file_props *p;
|
||||||
|
/*
|
||||||
|
er->pon(MODULO_INI_FILE,"guarda: Función no implementada");
|
||||||
|
return FALSE;*/
|
||||||
|
//abrimos archivo-------------------------------
|
||||||
|
hfile=CreateFile(path,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
0, // exclusive access
|
||||||
|
NULL, // no security
|
||||||
|
CREATE_ALWAYS,
|
||||||
|
0, // no overlapped I/O
|
||||||
|
NULL); // null template
|
||||||
|
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_INI_FILE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//guardamos---------------------------------
|
||||||
|
for (int i=0; i<grupos.n; i++)
|
||||||
|
{
|
||||||
|
//conseguimos grupo---------------------
|
||||||
|
g=(Ini_file_grupo *) grupos.get(i);
|
||||||
|
if (g->flags & INI_FILE_FLAGS_VACIO)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//grabamos nombre grupo-----------------
|
||||||
|
sprintf(stra,"[%s]\r\n",str.get(g->n));
|
||||||
|
kk=(int)strlen(stra);
|
||||||
|
if(!WriteFile(hfile, stra, kk, &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_INI_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
//guardamos propiedades---------------
|
||||||
|
for(int j=0; j<(g->prop.n); j++)
|
||||||
|
{
|
||||||
|
//conseguimos propiedad-----------
|
||||||
|
p=g->get(j);
|
||||||
|
if (p->flags & INI_FILE_FLAGS_VACIO)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//grabamos propiedad--------------
|
||||||
|
sprintf(stra,"%s=%s\r\n",str.get(p->p),str.get(p->v));
|
||||||
|
kk=(int)strlen(stra);
|
||||||
|
if(!WriteFile(hfile, stra, kk, &dw, NULL))
|
||||||
|
{
|
||||||
|
er->pon_win(MODULO_INI_FILE);
|
||||||
|
goto salgo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//cerramos----------------------------------
|
||||||
|
if(hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hfile);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
salgo:
|
||||||
|
if(hfile!=INVALID_HANDLE_VALUE)
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
int Cini_file::add_grupo( char *gr )
|
||||||
|
{
|
||||||
|
int rs = grupos.n;
|
||||||
|
Ini_file_grupo* g =set_coun();
|
||||||
|
g->n=str.size();
|
||||||
|
g->flags=0;
|
||||||
|
g->inicia();
|
||||||
|
str.add(gr);
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
int Cini_file::add( int gr,char *pro,char *val )
|
||||||
|
{
|
||||||
|
//pillamos grupo-------------------------
|
||||||
|
Ini_file_grupo *g=(Ini_file_grupo *) grupos.get(gr);
|
||||||
|
if (!g|| (g->flags & INI_FILE_FLAGS_VACIO))
|
||||||
|
{
|
||||||
|
er->pon(MODULO_INI_FILE,"add: Indice del grupo erroneo");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//añadimos prop--------------------------
|
||||||
|
int rs=g->prop.n;
|
||||||
|
Ini_file_props*p=g->set_coun();
|
||||||
|
p->flags=0;
|
||||||
|
p->p=str.size();
|
||||||
|
str.add(pro);
|
||||||
|
p->v=str.size();
|
||||||
|
str.add(val);
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
int Cini_file::add( int gr,char *pro,int val )
|
||||||
|
{
|
||||||
|
char str[256];
|
||||||
|
sprintf(str,"%ld",val);
|
||||||
|
return add(gr,pro,str);
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
int Cini_file::add( int gr,char *pro,double val )
|
||||||
|
{
|
||||||
|
char str[256];
|
||||||
|
sprintf(str,"%.2f",val);
|
||||||
|
return add(gr,pro,str);
|
||||||
|
}
|
||||||
|
//*********************************************************************************
|
||||||
|
void Cini_file::dame_valor( int gr,char *pro, char* dst,char *def )
|
||||||
|
{
|
||||||
|
strcpy(dst, get(gr,pro,def));
|
||||||
|
}
|
||||||
|
|
||||||
|
//*********************************************************************************
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
#include "StrArray.h"
|
||||||
|
#include "static_array.h"
|
||||||
|
#define INI_FILE_FLAGS_VACIO 0x0001
|
||||||
|
#define MODULO_INI_FILE "Cini_file"
|
||||||
|
//estructuras necesarias------------------------------------------------------------------
|
||||||
|
typedef struct Ini_file_props
|
||||||
|
{
|
||||||
|
short flags;
|
||||||
|
int p;//propiedad
|
||||||
|
int v;//valor
|
||||||
|
}Ini_file_props;
|
||||||
|
|
||||||
|
typedef struct Ini_file_grupo//cabecera base de la cumunicación
|
||||||
|
{
|
||||||
|
int n; //indice a nombre
|
||||||
|
short flags;
|
||||||
|
Cstatic_array prop;
|
||||||
|
Ini_file_grupo()
|
||||||
|
{
|
||||||
|
inicia();
|
||||||
|
n=0;
|
||||||
|
}
|
||||||
|
void inicia()
|
||||||
|
{
|
||||||
|
prop.n=prop.m=0;
|
||||||
|
prop.buf=NULL;
|
||||||
|
prop.z=sizeof(Ini_file_props);
|
||||||
|
prop.incremento=100;
|
||||||
|
}
|
||||||
|
Ini_file_props* get(int i)//da la propiedad i
|
||||||
|
{
|
||||||
|
return (Ini_file_props*) prop.get(i);
|
||||||
|
}
|
||||||
|
Ini_file_props* set_coun()//reserva para una propiedad mas y da el puntero
|
||||||
|
{
|
||||||
|
prop.reserva();
|
||||||
|
prop.n++;
|
||||||
|
return (Ini_file_props*) &prop.buf[prop.z*(prop.n-1)];
|
||||||
|
}
|
||||||
|
}Ini_file_grupo;
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------------------
|
||||||
|
class C_error;
|
||||||
|
class UTILES_EXPORT Cini_file
|
||||||
|
{
|
||||||
|
//variables--------------------------
|
||||||
|
private:
|
||||||
|
StrArray str;
|
||||||
|
Cstatic_array grupos;
|
||||||
|
BOOL borra_error;
|
||||||
|
public:
|
||||||
|
C_error *er;
|
||||||
|
|
||||||
|
Cini_file(C_error* err=NULL);
|
||||||
|
~Cini_file(void);
|
||||||
|
//funciones--------------------------
|
||||||
|
BOOL lee(char *path_);//lee archivo ini y lo carga en memoria
|
||||||
|
|
||||||
|
|
||||||
|
int get_grupo(char* gr);
|
||||||
|
int geti_valor(int gr,char *pro);//devuelve el indice del str valor
|
||||||
|
|
||||||
|
//funciones que dan el valor--------------
|
||||||
|
char* get(int gr,char *pro);// valor en forma de char*
|
||||||
|
int get(int gr,char *pro, int def);
|
||||||
|
double get(int gr,char *pro, double def);
|
||||||
|
char* get( int gr,char *pro, char *def);
|
||||||
|
void dame_valor( int gr,char *pro, char* dst,char *def);
|
||||||
|
//funciones de escritura-----------------
|
||||||
|
void borra();
|
||||||
|
BOOL guarda(char *path);//guarda ini cargado en memoria en un archivo;
|
||||||
|
int add_grupo(char *gr);//añade un grupo nuevo y da el indice
|
||||||
|
int add(int gr,char *pro,char *val);//añade valor de propiedad
|
||||||
|
|
||||||
|
//sobrecarga escritura-----------------
|
||||||
|
int add(int gr,char *pro,int val);//añade valor de propiedad
|
||||||
|
int add(int gr,char *pro,double val);//añade valor de propiedad
|
||||||
|
//funciones aux------------------------
|
||||||
|
private:
|
||||||
|
//funciones ayuda para leer
|
||||||
|
char* busca(char *st,char c);//busca en str el char c o el nulo
|
||||||
|
char* buscamos_grupo(char *st);//busca el siguiente grupo en str
|
||||||
|
char* busca_prop(char* st);
|
||||||
|
Ini_file_grupo* set_coun();
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Cint_array
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int *ind;
|
||||||
|
int m;
|
||||||
|
int n;
|
||||||
|
Cint_array(void);
|
||||||
|
~Cint_array(void);
|
||||||
|
int get(int i)
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
@echo off
|
||||||
|
Echo Borra ncb.
|
||||||
|
del "%~dp0"\*.ncb
|
||||||
|
Echo Borra bak
|
||||||
|
del "%~dp0"\*.bak
|
||||||
|
|
||||||
|
Echo Borra aps
|
||||||
|
del "%~dp0"\*.aps
|
||||||
|
|
||||||
|
Echo Borra debug.
|
||||||
|
rmdir /s /q "%~dp0"\debug"
|
||||||
|
|
||||||
|
Echo Borra release.
|
||||||
|
rmdir /s /q "%~dp0"\release
|
||||||
|
|
||||||
|
|
||||||
|
rmdir /s /q "%~dp0"\x64"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pause
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "lock.h"
|
||||||
|
//************************************************************************************************
|
||||||
|
Clock::Clock(void)
|
||||||
|
{
|
||||||
|
cerrojo=CLOCK_ESTADO_DESBLOQUEADO;
|
||||||
|
cliente=0;
|
||||||
|
t_sleep=25;
|
||||||
|
modo=1;
|
||||||
|
if (!InitializeCriticalSectionAndSpinCount(&cerrojo1, 0x00000400) )
|
||||||
|
modo=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
//************************************************************************************************
|
||||||
|
Clock::~Clock(void)
|
||||||
|
{
|
||||||
|
if (modo)
|
||||||
|
DeleteCriticalSection(&cerrojo1);
|
||||||
|
}
|
||||||
|
//************************************************************************************************
|
||||||
|
void Clock::entro()
|
||||||
|
{
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
while(TRUE)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
EnterCriticalSection(&cerrojo1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (CException* e)
|
||||||
|
{
|
||||||
|
e->Delete();
|
||||||
|
Sleep(t_sleep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long iden = GetCurrentThreadId();
|
||||||
|
long cerrojo_ = InterlockedExchange(&cerrojo,CLOCK_ESTADO_BLOQUEADO);
|
||||||
|
while (cerrojo_ != CLOCK_ESTADO_DESBLOQUEADO)
|
||||||
|
{
|
||||||
|
if (iden==cliente)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Sleep(t_sleep);
|
||||||
|
cerrojo_ = InterlockedExchange(&cerrojo,CLOCK_ESTADO_BLOQUEADO);
|
||||||
|
}
|
||||||
|
cliente=iden;
|
||||||
|
}
|
||||||
|
//************************************************************************************************
|
||||||
|
void Clock::salgo()
|
||||||
|
{
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
LeaveCriticalSection(&cerrojo1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cliente==GetCurrentThreadId())
|
||||||
|
{
|
||||||
|
cliente=0;
|
||||||
|
InterlockedExchange(&cerrojo,CLOCK_ESTADO_DESBLOQUEADO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//************************************************************************************************
|
||||||
|
BOOL Clock::puedo()
|
||||||
|
{
|
||||||
|
if (modo)
|
||||||
|
{
|
||||||
|
return TryEnterCriticalSection(&cerrojo1);
|
||||||
|
}
|
||||||
|
long iden = GetCurrentThreadId();
|
||||||
|
long cerrojo_ = InterlockedExchange(&cerrojo,CLOCK_ESTADO_BLOQUEADO);
|
||||||
|
if (cerrojo != CLOCK_ESTADO_DESBLOQUEADO)
|
||||||
|
{
|
||||||
|
if (iden!=cliente)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cliente=iden;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//************************************************************************************************************************
|
||||||
|
long lck_sum_atm(long *n, int i)
|
||||||
|
{
|
||||||
|
long old;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
old = *n;
|
||||||
|
if (old == InterlockedCompareExchange(n, old + i, old))
|
||||||
|
return old+i;
|
||||||
|
Sleep(1);
|
||||||
|
} while (TRUE);
|
||||||
|
}
|
||||||
|
//************************************************************************************************
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
#pragma once
|
||||||
|
#include "base_head.h"
|
||||||
|
|
||||||
|
#define CLOCK_ESTADO_BLOQUEADO 1
|
||||||
|
#define CLOCK_ESTADO_DESBLOQUEADO 0
|
||||||
|
|
||||||
|
class UTILES_EXPORT Clock//estructura para concurrencia
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
long t_sleep;//tiempo de sleep en milisegundos
|
||||||
|
|
||||||
|
Clock(void);
|
||||||
|
~Clock(void);
|
||||||
|
|
||||||
|
void entro();//pilla el cerrojo durmiendo si es necesario
|
||||||
|
void salgo();//libera el cerrojo
|
||||||
|
BOOL puedo();//intenta pillar el cerrojo, si ya estaba pillado devuelve false si no true
|
||||||
|
|
||||||
|
private:
|
||||||
|
long volatile cerrojo;//variable volatile
|
||||||
|
long cliente;//id del thred que tiene el cerrojo
|
||||||
|
CRITICAL_SECTION cerrojo1;
|
||||||
|
int modo;//indica si usa cerrojo 0 o 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
UTILES_EXPORT long lck_sum_atm(long *n,int i);//suma de manera atomica i a n
|
||||||
|
|
@ -0,0 +1,434 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
#include "mapmatrix.h"
|
||||||
|
#include "_log.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
//*************************************************************************************
|
||||||
|
BOOL CmapMatFloat::lee( char *path, char *ext, BOOL mismosvect/*=TRUE*/)
|
||||||
|
{
|
||||||
|
BOOL mal=FALSE;
|
||||||
|
for(int ic=0; ic<(int)dat.size() && !mal; ic++)
|
||||||
|
{
|
||||||
|
if(!dat[ic].lee(ic,path,ext,(int)dat.size(),mismosvect))
|
||||||
|
mal=TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !mal;
|
||||||
|
}
|
||||||
|
//*************************************************************************************
|
||||||
|
BOOL CmapRowFloat::guarda(HeadCostConj hd, int ic, char *path , char *ext, Cgarray<MapDataFloat> *bufer)
|
||||||
|
{
|
||||||
|
HANDLE hfile = INVALID_HANDLE_VALUE;
|
||||||
|
int nb, i;
|
||||||
|
char file[MAX_PATH];
|
||||||
|
|
||||||
|
sprintf_s(file,MAX_PATH,"%s%06d.%s",path,ic,ext);
|
||||||
|
//crea archivo-----------------------------------
|
||||||
|
hfile = CreateFile(file, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
i=GetLastError();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//graba cabecera------------
|
||||||
|
hd.isVect=isVect;
|
||||||
|
if(isVect)
|
||||||
|
{
|
||||||
|
hd.n=(int)datv.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hd.n=(int)dat.size();
|
||||||
|
}
|
||||||
|
nb = sizeof(hd);
|
||||||
|
if (nb != _lwrite((int)hfile, (LPCCH)&hd, nb))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isVect)
|
||||||
|
{
|
||||||
|
//guarda las componentes del vector
|
||||||
|
nb=sizeof(float);
|
||||||
|
for(i=0;i<hd.n;i++)
|
||||||
|
{
|
||||||
|
if (nb != _lwrite((int)hfile, (LPCCH) &datv[i], nb))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(i<hd.n)
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Cgarray<MapDataFloat> auxbuf;
|
||||||
|
Cgarray<MapDataFloat> *buff;
|
||||||
|
if(bufer)
|
||||||
|
buff = bufer;
|
||||||
|
else
|
||||||
|
buff = &auxbuf;
|
||||||
|
int nbufer= min(hd.n,1000);
|
||||||
|
if(!((*buff)+=nbufer))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
buff->n = nbufer;
|
||||||
|
//guarda componente a componente del map
|
||||||
|
int ii = 0;
|
||||||
|
for (std::map<int, float>::iterator it=dat.begin(); it!=dat.end(); ++it)
|
||||||
|
{
|
||||||
|
//int aux = it->first;
|
||||||
|
(*buff)[ii].k =it->first;
|
||||||
|
(*buff)[ii].v =it->second;
|
||||||
|
ii++;
|
||||||
|
if(ii>=buff->n)
|
||||||
|
{
|
||||||
|
nb = buff->n*sizeof(MapDataFloat);
|
||||||
|
if (nb != _lwrite((int)hfile, (LPCCH) buff->ptr, nb))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
ii =0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(ii>0)
|
||||||
|
{
|
||||||
|
nb = ii*sizeof(MapDataFloat);
|
||||||
|
if (nb != _lwrite((int)hfile, (LPCCH) buff->ptr, nb))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
va_mal:
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*************************************************************************************
|
||||||
|
//ntot solo se usa cuando es map y pasa a vector, porque se necesita cuántos elementos en total tiene que haber
|
||||||
|
BOOL CmapRowFloat::lee(int ic, char *path , char *ext, int ntot, BOOL mismosvect/*=TRUE*/, Cgarray<MapDataFloat> *bufer/* = NULL*/)
|
||||||
|
{
|
||||||
|
HANDLE hfile = INVALID_HANDLE_VALUE;
|
||||||
|
int nb, i;
|
||||||
|
char file[MAX_PATH];
|
||||||
|
HeadCostConj hd;
|
||||||
|
Cgarray<MapDataFloat> buffaux;
|
||||||
|
|
||||||
|
sprintf_s(file,MAX_PATH,"%s%06d.%s",path,ic,ext);
|
||||||
|
//crea archivo-----------------------------------
|
||||||
|
hfile = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
i=GetLastError();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//lee cabecera------------
|
||||||
|
memset(&hd,0,sizeof(HeadCostConj));
|
||||||
|
nb = sizeof(hd);
|
||||||
|
if (nb != _lread((int)hfile,&hd, nb))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
if(mismosvect)
|
||||||
|
isVect=hd.isVect;
|
||||||
|
|
||||||
|
int j=0;
|
||||||
|
float d=0;
|
||||||
|
nb=sizeof(float);
|
||||||
|
dat.clear();
|
||||||
|
datv.clear();
|
||||||
|
|
||||||
|
Cgarray<MapDataFloat> *buff;
|
||||||
|
if(bufer)
|
||||||
|
{
|
||||||
|
bufer->n=0;
|
||||||
|
buff = bufer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
buff =&buffaux;
|
||||||
|
int nbufer= min(hd.n,1000);
|
||||||
|
|
||||||
|
if(hd.isVect)
|
||||||
|
{
|
||||||
|
if(isVect)
|
||||||
|
{
|
||||||
|
//vector a vector
|
||||||
|
datv.reserve(hd.n);
|
||||||
|
/*for (int i = 0; i<hd.n; i++)
|
||||||
|
{
|
||||||
|
int nad = min(5000, hd.n-i);
|
||||||
|
datv.insert(datv.end(),nad,VALNOEXIST_FLOAT);
|
||||||
|
i+=nad;
|
||||||
|
}*/
|
||||||
|
datv.insert(datv.begin(),hd.n,VALNOEXIST_FLOAT);
|
||||||
|
|
||||||
|
if (sizeof(float)*hd.n != _lread((int)hfile,&datv[0], sizeof(float)*hd.n))
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//vector a map
|
||||||
|
if(!((*buff)+=nbufer))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
|
||||||
|
//lee componente a componente del map
|
||||||
|
int nl =0;
|
||||||
|
int nn = 0;
|
||||||
|
for(int i=0;i<hd.n;i+=nn)
|
||||||
|
{
|
||||||
|
nn = min(nbufer,hd.n-nl);
|
||||||
|
nb = sizeof(float)*nn;
|
||||||
|
if (nb != _lread((int)hfile,buff->ptr, nb))
|
||||||
|
break;
|
||||||
|
|
||||||
|
for(int ii =0; ii<nn; ii++)
|
||||||
|
set(i+ii,((float*)buff->ptr)[ii]);
|
||||||
|
|
||||||
|
nl+=nn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!((*buff)+=nbufer))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
buff->n=0;
|
||||||
|
|
||||||
|
//lee componente a componente del map
|
||||||
|
int nl =0;
|
||||||
|
int nn = 0;
|
||||||
|
if(isVect)
|
||||||
|
datv.insert(datv.begin(),ntot,VALNOEXIST_FLOAT);
|
||||||
|
|
||||||
|
for(int i=0;i<hd.n;i+=nn)
|
||||||
|
{
|
||||||
|
nn = min(nbufer,hd.n-nl);
|
||||||
|
nb = sizeof(MapDataFloat)*nn;
|
||||||
|
if (nb != _lread((int)hfile,buff->ptr, nb))
|
||||||
|
break;
|
||||||
|
|
||||||
|
for(int ii =0; ii<nn; ii++)
|
||||||
|
set((*buff)[ii].k,(*buff)[ii].v);
|
||||||
|
|
||||||
|
nl+=nn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
va_mal:
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*************************************************************************************
|
||||||
|
BOOL CmapRowInt::guarda(HeadCostConj hd, int ic, char *path , char *ext)
|
||||||
|
{
|
||||||
|
HANDLE hfile = INVALID_HANDLE_VALUE;
|
||||||
|
int nb, i;
|
||||||
|
char file[MAX_PATH];
|
||||||
|
|
||||||
|
sprintf_s(file,MAX_PATH,"%s%06d.%s",path,ic,ext);
|
||||||
|
//crea archivo-----------------------------------
|
||||||
|
hfile = CreateFile(file, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
i=GetLastError();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//graba cabecera------------
|
||||||
|
hd.isVect=isVect;
|
||||||
|
if(isVect)
|
||||||
|
{
|
||||||
|
hd.n=(int)datv.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hd.n=(int)dat.size();
|
||||||
|
}
|
||||||
|
nb = sizeof(hd);
|
||||||
|
if (nb != _lwrite((int)hfile, (LPCCH)&hd, nb))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isVect)
|
||||||
|
{
|
||||||
|
//guarda las componentes del vector
|
||||||
|
if (datv.size()*sizeof(int) != _lwrite((int)hfile, (LPCCH) &datv[0], datv.size()*sizeof(int)))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Cgarray<MapDataInt> buff;
|
||||||
|
int nbufer= min(hd.n,1000);
|
||||||
|
if(!(buff+=nbufer))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
buff.n = nbufer;
|
||||||
|
//guarda componente a componente del map
|
||||||
|
int ii = 0;
|
||||||
|
for (std::map<int, int>::iterator it=dat.begin(); it!=dat.end(); ++it)
|
||||||
|
{
|
||||||
|
//int aux = it->first;
|
||||||
|
buff[ii].k=it->first;
|
||||||
|
buff[ii].v =it->second;
|
||||||
|
ii++;
|
||||||
|
|
||||||
|
if(ii>=buff.n)
|
||||||
|
{
|
||||||
|
nb = buff.n*sizeof(MapDataInt);
|
||||||
|
|
||||||
|
if (nb != _lwrite((int)hfile, (LPCCH) buff.ptr, nb))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
ii =0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(ii>0)
|
||||||
|
{
|
||||||
|
nb = ii*sizeof(MapDataInt);
|
||||||
|
if (nb != _lwrite((int)hfile, (LPCCH) buff.ptr, nb))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
va_mal:
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*************************************************************************************
|
||||||
|
//falta optimizar al estilo CmapRowFloat
|
||||||
|
BOOL CmapRowInt::lee(int ic, char *path , char *ext, BOOL mismosvect/*=TRUE*/)
|
||||||
|
{
|
||||||
|
HANDLE hfile = INVALID_HANDLE_VALUE;
|
||||||
|
int nb, i;
|
||||||
|
char file[MAX_PATH];
|
||||||
|
HeadCostConj hd;
|
||||||
|
|
||||||
|
sprintf_s(file,MAX_PATH,"%s%06d.%s",path,ic,ext);
|
||||||
|
//crea archivo-----------------------------------
|
||||||
|
hfile = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
i=GetLastError();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//lee cabecera------------
|
||||||
|
memset(&hd,0,sizeof(HeadCostConj));
|
||||||
|
nb = sizeof(hd);
|
||||||
|
if (nb != _lread((int)hfile,&hd, nb))
|
||||||
|
{
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
if(mismosvect)
|
||||||
|
isVect=hd.isVect;//fuerza a que donde lee sea vect o no igual que lo que lee, o no
|
||||||
|
|
||||||
|
int j=0;
|
||||||
|
int d=0;
|
||||||
|
nb=sizeof(int);
|
||||||
|
if(hd.isVect)
|
||||||
|
{
|
||||||
|
//lee los componentes del vector
|
||||||
|
for(i=0;i<hd.n;i++)
|
||||||
|
{
|
||||||
|
if (nb != _lread((int)hfile,&d, nb))
|
||||||
|
break;
|
||||||
|
set(i,d);
|
||||||
|
}
|
||||||
|
if(i<hd.n)
|
||||||
|
goto va_mal;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//lee componente a componente del map
|
||||||
|
for(i=0;i<hd.n;i++)
|
||||||
|
{
|
||||||
|
nb=sizeof(int);
|
||||||
|
if (nb != _lread((int)hfile,&j, nb))
|
||||||
|
break;
|
||||||
|
nb=sizeof(int);
|
||||||
|
if (nb != _lread((int)hfile,&d, nb))
|
||||||
|
break;
|
||||||
|
set(j,d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(i<hd.n)
|
||||||
|
goto va_mal;
|
||||||
|
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
va_mal:
|
||||||
|
CloseHandle(hfile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//*************************************************************************************
|
||||||
|
//*************************************************************************************
|
||||||
|
//*************************************************************************************
|
||||||
|
void ThMapMatFloatLee::run()
|
||||||
|
{
|
||||||
|
mal = FALSE;
|
||||||
|
C_log::log("ThMapMatFloatLee","Subthr %ld, Conjs %04d a %04d", ithr,ini, fin);
|
||||||
|
|
||||||
|
Cgarray<MapDataFloat> buff;
|
||||||
|
|
||||||
|
for(int ic=ini; ic<fin && !mal; ic++)
|
||||||
|
{
|
||||||
|
if(!(*pclas)[ic].lee(ic,path,ext,mismosvect, pclas->dat.size(),&buff))
|
||||||
|
mal=TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//*************************************************************************************
|
||||||
|
BOOL CmapMatFloat::leeThread( char *path, char *ext, int nthread, BOOL mismosvect/*=TRUE*/)
|
||||||
|
{
|
||||||
|
ThMapMatFloatLee th[MAX_THREAD_LEE];
|
||||||
|
int nth = min(nthread,MAX_THREAD_LEE);
|
||||||
|
int n = (int)ceil(dat.size()*1./nth);
|
||||||
|
int asig = 0;
|
||||||
|
int i=0;
|
||||||
|
//C_log::log("leeThread","tot %ld n %ld", dat.size(),n);
|
||||||
|
for(i=0; i<nth && asig<(int)dat.size(); i++)
|
||||||
|
{
|
||||||
|
th[i].ext = ext;
|
||||||
|
th[i].mismosvect = mismosvect;
|
||||||
|
th[i].path = path;
|
||||||
|
th[i].pclas = this;
|
||||||
|
th[i].mal = FALSE;
|
||||||
|
th[i].ithr=i;
|
||||||
|
th[i].ini = i*n;
|
||||||
|
th[i].fin = min((i+1)*n,(int)dat.size());
|
||||||
|
asig=th[i].fin;
|
||||||
|
th[i].lanza();
|
||||||
|
}
|
||||||
|
BOOL mal=FALSE;
|
||||||
|
for(int ic=0; ic<i; ic++)
|
||||||
|
{
|
||||||
|
th[ic].join();
|
||||||
|
mal|=th[ic].mal;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !mal;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,354 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef CmapMat_H
|
||||||
|
#define CmapMat_H
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#define VALNOEXIST_FLOAT (float) 1.e+30
|
||||||
|
#define VALNOEXIST_INT (int) -1
|
||||||
|
#include "garray.h"
|
||||||
|
#include "th.h"
|
||||||
|
|
||||||
|
#pragma pack(8)
|
||||||
|
typedef struct HeadCostConj
|
||||||
|
{
|
||||||
|
int ver; //versión
|
||||||
|
bool isVect; // vect o map
|
||||||
|
int n; //num de elems guardados
|
||||||
|
}HeadCostConj;
|
||||||
|
typedef struct HeadCostAng
|
||||||
|
{
|
||||||
|
int ver; //versión
|
||||||
|
int n; //num de elems guardados
|
||||||
|
}HeadCostAng;
|
||||||
|
#pragma pack (1)
|
||||||
|
typedef struct MapDataFloat{
|
||||||
|
int k;
|
||||||
|
float v;
|
||||||
|
}MapDataFloat;
|
||||||
|
typedef struct MapDataInt{
|
||||||
|
int k;
|
||||||
|
int v;
|
||||||
|
}MapDataInt;
|
||||||
|
#pragma pack(16)
|
||||||
|
#define MAX_THREAD_LEE 8
|
||||||
|
//matixFloat---------------------------------------------
|
||||||
|
class UTILES_EXPORT CmapRowFloat
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
//*********************************
|
||||||
|
//Variables
|
||||||
|
bool isVect;
|
||||||
|
int imin, imax;
|
||||||
|
std::map<int, float> dat;
|
||||||
|
std::vector<float> datv;
|
||||||
|
//*********************************
|
||||||
|
//Métodos
|
||||||
|
CmapRowFloat()
|
||||||
|
{
|
||||||
|
isVect = false;
|
||||||
|
imin=INT_MAX;
|
||||||
|
imax=INT_MIN;
|
||||||
|
}
|
||||||
|
~CmapRowFloat(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//******************************************************
|
||||||
|
inline void set(int i, float v)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(isVect)
|
||||||
|
datv[i]=v;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(v== VALNOEXIST_FLOAT)
|
||||||
|
return;
|
||||||
|
dat[i] = v;
|
||||||
|
if(i<imin)
|
||||||
|
imin=i;
|
||||||
|
if(i>imax)
|
||||||
|
imax=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//******************************************************
|
||||||
|
inline float operator[](int irow)
|
||||||
|
{
|
||||||
|
if(isVect)
|
||||||
|
return datv[irow];
|
||||||
|
if(irow< imin || irow>imax)
|
||||||
|
return VALNOEXIST_FLOAT;
|
||||||
|
//si tiene esa clave la devuelve, si no, devuelve MAYUSCULO
|
||||||
|
std::map<int, float>::iterator elem = dat.find(irow);
|
||||||
|
if(elem == dat.end())
|
||||||
|
//no tiene la clave
|
||||||
|
return VALNOEXIST_FLOAT;
|
||||||
|
return elem->second;
|
||||||
|
}
|
||||||
|
inline void configVector(int ymax)
|
||||||
|
{
|
||||||
|
isVect = true;
|
||||||
|
dat.clear();
|
||||||
|
|
||||||
|
//datv.reserve(ymax);
|
||||||
|
datv.insert(datv.begin(),ymax,VALNOEXIST_FLOAT);
|
||||||
|
|
||||||
|
bool inVector = false;
|
||||||
|
/*for (int i =0 ; i<ymax; i++)
|
||||||
|
datv.push_back(VALNOEXIST_FLOAT);*/
|
||||||
|
}
|
||||||
|
//ajusta map a memoria justa
|
||||||
|
inline void memAjust()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
inline void clear()
|
||||||
|
{
|
||||||
|
dat.clear();
|
||||||
|
datv.clear();
|
||||||
|
isVect=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL guarda(HeadCostConj hd, int ic, char *path , char *ext, Cgarray<MapDataFloat> *bufer = NULL);
|
||||||
|
BOOL lee(int ic, char *path , char *ext, int ntot, BOOL mismosvect=TRUE, Cgarray<MapDataFloat> *bufer = NULL);
|
||||||
|
};
|
||||||
|
#define MAX_MEM_MAPFLOAT 1024.*1024.*300./sizeof(float)
|
||||||
|
|
||||||
|
class UTILES_EXPORT CmapMatFloat
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//*********************************
|
||||||
|
//Variables
|
||||||
|
std::vector<CmapRowFloat> dat;
|
||||||
|
|
||||||
|
//*********************************
|
||||||
|
//Métodos
|
||||||
|
CmapMatFloat()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~CmapMatFloat(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//******************************************************
|
||||||
|
inline CmapRowFloat& operator[](int irow)
|
||||||
|
{
|
||||||
|
return dat[irow];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set(int x, int y, float val)
|
||||||
|
{
|
||||||
|
if(val>= VALNOEXIST_FLOAT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dat[x].set(y,val);
|
||||||
|
}
|
||||||
|
//ajusta los map a la memoria minima posible
|
||||||
|
inline void memAjust()
|
||||||
|
{
|
||||||
|
for(std::vector<CmapRowFloat>::iterator elem = dat.begin(); elem!= dat.end(); elem++)
|
||||||
|
{
|
||||||
|
elem->memAjust();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline void clear()
|
||||||
|
{
|
||||||
|
dat.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//reparte los nvect disponibles entre los threads, poniendo las primeras filas de cada uno de vect
|
||||||
|
inline void inicializa(int xmax, int nthr, int nvect=-1)
|
||||||
|
{
|
||||||
|
dat.reserve(xmax);
|
||||||
|
bool inVector = false;
|
||||||
|
if(nvect<0)
|
||||||
|
nvect =(int)(MAX_MEM_MAPFLOAT/xmax);
|
||||||
|
|
||||||
|
int vectthr=0,novecthr=0,iparc=0;
|
||||||
|
if(nvect<xmax)
|
||||||
|
{
|
||||||
|
vectthr = (int)(nvect*1./nthr);
|
||||||
|
novecthr = (int)((xmax-nvect)*1./nthr);
|
||||||
|
}
|
||||||
|
//xmax = novec;
|
||||||
|
for (int i =0 ; i<xmax; i++)
|
||||||
|
{
|
||||||
|
dat.push_back(CmapRowFloat());
|
||||||
|
if(nvect>=xmax)
|
||||||
|
dat[i].configVector(xmax);
|
||||||
|
else if(nvect>0)
|
||||||
|
{
|
||||||
|
if((i-iparc)<vectthr)
|
||||||
|
dat[i].configVector(xmax);
|
||||||
|
else if((i-iparc)>=(vectthr+novecthr))
|
||||||
|
iparc+=vectthr+novecthr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BOOL lee(char *path, char *ext, BOOL mismosvect=TRUE);
|
||||||
|
BOOL leeThread( char *path, char *ext, int nthread, BOOL mismosvect/*=TRUE*/);
|
||||||
|
};
|
||||||
|
class UTILES_EXPORT ThMapMatFloatLee: public Cth
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CmapMatFloat *pclas;
|
||||||
|
int ini;//fila inicio
|
||||||
|
int fin;//fila fin
|
||||||
|
int ithr;
|
||||||
|
BOOL mal;//indica si ha ido bien
|
||||||
|
BOOL mismosvect;
|
||||||
|
char*path;
|
||||||
|
char*ext;
|
||||||
|
virtual void run();
|
||||||
|
};
|
||||||
|
class UTILES_EXPORT CmapRowInt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//*********************************
|
||||||
|
//Variables
|
||||||
|
std::map<int, int> dat;
|
||||||
|
std::vector<int> datv;
|
||||||
|
int imin, imax;
|
||||||
|
bool isVect;
|
||||||
|
//*********************************
|
||||||
|
//Métodos
|
||||||
|
CmapRowInt()
|
||||||
|
{
|
||||||
|
imin=INT_MAX;
|
||||||
|
imax=INT_MIN;
|
||||||
|
isVect = false;
|
||||||
|
}
|
||||||
|
~CmapRowInt(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//******************************************************
|
||||||
|
inline void set(int i, int v)
|
||||||
|
{
|
||||||
|
if(v== VALNOEXIST_INT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(isVect)
|
||||||
|
datv[i]=v;
|
||||||
|
else
|
||||||
|
dat[i] = v;
|
||||||
|
|
||||||
|
if(i<imin)
|
||||||
|
imin=i;
|
||||||
|
if(i>imax)
|
||||||
|
imax=i;
|
||||||
|
}
|
||||||
|
//******************************************************
|
||||||
|
inline int operator[](int irow)
|
||||||
|
{
|
||||||
|
if(isVect)
|
||||||
|
return datv[irow];
|
||||||
|
if(irow< imin || irow>imax)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
//si tiene esa clave la devuelve, si no, devuelve MAYUSCULO
|
||||||
|
std::map<int, int>::iterator elem = dat.find(irow);
|
||||||
|
if(elem == dat.end())
|
||||||
|
//no tiene la clave
|
||||||
|
return VALNOEXIST_INT;
|
||||||
|
return elem->second;
|
||||||
|
}
|
||||||
|
//ajusta map a memoria justa
|
||||||
|
inline void memAjust()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
inline void configVector(int ymax)
|
||||||
|
{
|
||||||
|
isVect = true;
|
||||||
|
dat.clear();
|
||||||
|
datv.insert(datv.begin(),ymax,VALNOEXIST_INT);
|
||||||
|
/*datv.reserve(ymax);
|
||||||
|
for (int i =0 ; i<ymax; i++)
|
||||||
|
datv.push_back(VALNOEXIST_INT);*/
|
||||||
|
}
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
isVect = false;
|
||||||
|
dat.clear();
|
||||||
|
datv.clear();
|
||||||
|
}
|
||||||
|
BOOL guarda(HeadCostConj hd, int ic, char *path , char *ext);
|
||||||
|
BOOL lee(int ic, char *path, char *ext, BOOL mismosvect=TRUE );
|
||||||
|
};
|
||||||
|
#define MAX_MEM_MAPINT 1024.*1024.*200./sizeof(int)
|
||||||
|
class UTILES_EXPORT CmapMatInt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//*********************************
|
||||||
|
//Variables
|
||||||
|
std::vector<CmapRowInt> dat;
|
||||||
|
|
||||||
|
//*********************************
|
||||||
|
//Métodos
|
||||||
|
CmapMatInt()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~CmapMatInt(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//******************************************************
|
||||||
|
inline CmapRowInt& operator[](int irow)
|
||||||
|
{
|
||||||
|
return dat[irow];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set(int x, int y, int val)
|
||||||
|
{
|
||||||
|
if(val== VALNOEXIST_INT)
|
||||||
|
return;
|
||||||
|
dat[x].set(y,val);
|
||||||
|
}
|
||||||
|
//ajusta los map a la memoria minima posible
|
||||||
|
inline void memAjust()
|
||||||
|
{
|
||||||
|
for(std::vector<CmapRowInt>::iterator elem = dat.begin(); elem!= dat.end(); elem++)
|
||||||
|
{
|
||||||
|
elem->memAjust();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline void clear()
|
||||||
|
{
|
||||||
|
dat.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void inicializa(int xmax, int nthr, int nvect=-1)
|
||||||
|
{
|
||||||
|
dat.reserve(xmax);
|
||||||
|
bool inVector = false;
|
||||||
|
if(nthr<=0)
|
||||||
|
nthr=1;
|
||||||
|
if(nvect<0)
|
||||||
|
nvect =(int)(MAX_MEM_MAPINT/xmax);
|
||||||
|
int vectthr=0,novecthr=0,iparc=0;
|
||||||
|
if(nvect<xmax)
|
||||||
|
{
|
||||||
|
vectthr = (int)(nvect*1./nthr);
|
||||||
|
novecthr = (int)((xmax-nvect)*1./nthr);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i =0 ; i<xmax; i++)
|
||||||
|
{
|
||||||
|
dat.push_back(CmapRowInt());
|
||||||
|
if(nvect>=xmax)//nvec>=xmax
|
||||||
|
dat[i].configVector(xmax);
|
||||||
|
else if(nvect==0)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if((i-iparc)<vectthr)
|
||||||
|
dat[i].configVector(xmax);
|
||||||
|
else if((i-iparc)>=(vectthr+novecthr))
|
||||||
|
iparc+=vectthr+novecthr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,132 @@
|
||||||
|
#include "StdAfx.h"
|
||||||
|
/*
|
||||||
|
#include "mysql_con.h"
|
||||||
|
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
Cmysql_con::Cmysql_con(void)
|
||||||
|
{
|
||||||
|
conn=NULL;
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
Cmysql_con::~Cmysql_con(void)
|
||||||
|
{
|
||||||
|
cierra();
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
BOOL Cmysql_con::contecta( char *url,char *usr,char *key, char* dbname, int puerto )
|
||||||
|
{
|
||||||
|
char *opt_socket_name = NULL;
|
||||||
|
unsigned int opt_flags = 0;
|
||||||
|
cierra();
|
||||||
|
//inicia conexion---------------------------------------------
|
||||||
|
conn = mysql_init (NULL);
|
||||||
|
if (!conn)
|
||||||
|
{
|
||||||
|
err.pon("mysql","Error al inicializar la conexión");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//conecta con servidor----------------------------------------
|
||||||
|
if (!mysql_real_connect (conn, url, usr, key,
|
||||||
|
dbname, puerto, opt_socket_name, opt_flags))
|
||||||
|
{
|
||||||
|
pon_error();
|
||||||
|
cierra();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
void Cmysql_con::cierra()
|
||||||
|
{
|
||||||
|
if (conn != NULL)
|
||||||
|
{
|
||||||
|
mysql_close (conn);
|
||||||
|
conn = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
void Cmysql_con::pon_error()
|
||||||
|
{
|
||||||
|
char resultado[255];
|
||||||
|
if (conn != NULL)
|
||||||
|
{
|
||||||
|
sprintf(resultado, "Error %u (%s)", mysql_errno(conn), mysql_error(conn));
|
||||||
|
err.pon("mysql",resultado);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
BOOL Cmysql_con::envia( char *sent )
|
||||||
|
{
|
||||||
|
if (mysql_query(conn, sent) != 0)
|
||||||
|
{
|
||||||
|
pon_error();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
BOOL Cmysql_con::recibe()
|
||||||
|
{
|
||||||
|
MYSQL_RES *res;
|
||||||
|
MYSQL_ROW row;
|
||||||
|
int i;
|
||||||
|
info.borra_virut();
|
||||||
|
registros=columnas=0;
|
||||||
|
if (!conn)
|
||||||
|
{
|
||||||
|
err.pon("mysql","Sin conexion");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
res = mysql_store_result(conn);
|
||||||
|
if (!res)
|
||||||
|
{
|
||||||
|
pon_error();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//registros = (int)mysql_num_rows(res);
|
||||||
|
columnas = mysql_num_fields(res);
|
||||||
|
while ((row = mysql_fetch_row(res)) != NULL)
|
||||||
|
{
|
||||||
|
registros++;
|
||||||
|
for (i = 0; i < columnas; i++)
|
||||||
|
{
|
||||||
|
if (row[i] != NULL)
|
||||||
|
info.add((char*)row[i]);
|
||||||
|
else
|
||||||
|
info.add("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
char* Cmysql_con::get( int f,int c )
|
||||||
|
{
|
||||||
|
if(f<0 || f>=registros || c<0 || c>=columnas)
|
||||||
|
return NULL;
|
||||||
|
return info.get(f*columnas+c);
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
void Cmysql_con::get( int f, int c, int *res )
|
||||||
|
{
|
||||||
|
char *st=get(f,c);
|
||||||
|
if (st)
|
||||||
|
*res=atoi(st);
|
||||||
|
else
|
||||||
|
*res=0;
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
void Cmysql_con::get( int f, int c, double *res )
|
||||||
|
{
|
||||||
|
char *st=get(f,c);
|
||||||
|
if (st)
|
||||||
|
*res=atof(st);
|
||||||
|
else
|
||||||
|
*res=0;
|
||||||
|
}
|
||||||
|
//**********************************************************************************************************************************
|
||||||
|
void Cmysql_con::get( int f, int c, __int64 *res )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//**********************************************************************************************************************************
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue