89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
#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();
|
|
};
|