.
Oprime F8 y veras...
Aun así mírate esto: http://msdn.microsoft.com/es-es/library/ktf38f66(v=vs.80).aspx
Dulces Lunas!¡.
Oprime F8 y veras...
Aun así mírate esto: http://msdn.microsoft.com/es-es/library/ktf38f66(v=vs.80).aspx
Dulces Lunas!¡.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
#ifndef _MODUTILES_H
#define _MODUTILES_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
#ifndef Byte_
#define Byte_
typedef unsigned char Byte;
#endif // Byte_
#ifndef e_CompareMethod_
#define e_CompareMethod_
enum e_CompareMethod{
BINARY = 1,
TEXTCOMPARE = 2
};
#endif //e_CompareMethod_
#ifndef Struct_Byte_
#define Struct_Byte_
struct Struct_Byte
{
Byte *pbyt_bytes;
size_t szt_lenbytes;
};
#endif // Struct_Byte_
#ifndef Struct_Byte_Split_
#define Struct_Byte_Split_
struct Struct_Byte_Split
{
struct Struct_Byte **Struct;
size_t szt_ln;
};
#endif // Struct_Byte_Split_
size_t ByteIndex ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find, size_t szt_lsf, size_t szt_Start, e_CompareMethod enum_Compare );
size_t ByteIndex ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find, size_t szt_lsf, size_t szt_Start );
size_t ByteIndex ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find, size_t szt_lsf );
bool ByteExits ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find , size_t szt_lsf , size_t szt_Start , long lng_interval, e_CompareMethod enum_Compare);
bool ByteExits ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find , size_t szt_lsf , size_t szt_Start , long lng_interval);
bool ByteExits ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find , size_t szt_lsf , size_t szt_Start);
bool ByteExits ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find , size_t szt_lsf );
Struct_Byte *ByteReplace ( Byte *pByt_Bytes , size_t szt_lnBytes , Byte *pByt_Find , size_t szt_lnFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start , long lng_Count , e_CompareMethod enum_Compare );
Struct_Byte *ByteReplace ( Byte *pByt_Bytes , size_t szt_lnBytes , Byte *pByt_Find , size_t szt_lnFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start , long lng_Count );
Struct_Byte *ByteReplace ( Byte *pByt_Bytes , size_t szt_lnBytes , Byte *pByt_Find , size_t szt_lnFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start );
Struct_Byte *ByteReplace ( Byte *pByt_Bytes , size_t szt_lnBytes , Byte *pByt_Find , size_t szt_lnFind , Byte *pByt_Replacement , size_t szt_lnReplacement );
Byte *reallocpp ( Byte *pvoid_in , size_t szt_a, size_t szt_n );
Byte *ByteClone ( Byte *pByt_Bytes , size_t szt_lenbytes );
Byte CmpCharMTLTM ( Byte *chr_v );
Struct_Byte *ByteMid ( Byte* pbyt_str , size_t szt_lnstr , size_t szt_start , size_t szt_len );
Struct_Byte_Split *ByteSplit ( Byte *pbyt_str , size_t szt_lnstr , Byte *pbyt_delimiter , size_t szt_lndelimiter , long lng_limit );
Struct_Byte_Split *ByteSplit ( Byte *pbyt_str , size_t szt_lnstr , Byte *pbyt_delimiter , size_t szt_lndelimiter );
size_t flen ( FILE *pFl );
template <class T>
T setnewptrd( T &old , T New , bool array ) {
if ( old != NULL ) {
if ( array == false ) {
delete old;
} else {
delete[] old;
}
}
return old = New;
}
template <class T>
T setnewptrf( T &old , T New ) {
if ( &old != NULL ) {
free (old);
}
return old = New;
}
template <class T>
T setnewptrf( T &old , T New , size_t sztln ) {
if ( &old != NULL ) {
for (;sztln>0;--sztln) {
free (&old[sztln-1]);
}
free ( old );
}
//return old = New;
}
template <class T>
T rectific_num( T t_val , T t_min , T t_max )
/**
Corrige [vVal] con respecto a un minimo y a un maximo valor.
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
if (t_val < t_min)
return t_min;
else if ( t_val > t_max )
return t_max;
else
return t_val;
}
template <class T>
bool fix_numbers_range( T *t_ini , T *t_end , long *lng_ln , long *lng_distance , T t_min , T t_max )
/**
Corrige los rangos de [t_ini],[t_end], [lng_ln] con respecto a un minimo y a un maximo valor.
[lng_ln] corresponde a la distancia entre [t_ini] y [t_end].
Se retorna false solo si [t_max] es menor que que [t_ini] o que [*lng_ln] es igual o menor a [0]
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
T T_Swap;
if ( t_ini!=NULL && lng_ln!=NULL )
if ( t_max >= *t_ini && *lng_ln != 0 )
{
if (*lng_ln < 0 )
{
t_ini = t_ini + *lng_ln + 1;
*lng_ln = *lng_ln * -1;
}
if ( lng_distance != NULL )
if (*lng_distance < 0)
{
t_ini += *lng_distance;
if (*t_ini < 0)
return false;
T_Swap = *lng_distance*(-1);
*lng_distance = *lng_ln;
*lng_ln = T_Swap;
}
(*lng_ln)--;
*t_ini = rectific_num<T>( *t_ini , t_min , t_max);
*t_end = rectific_num<T>( *t_ini+*lng_ln , *t_ini , t_max);
if ( lng_distance != NULL )
*lng_distance = rectific_num<T>( *lng_distance , t_min , t_max-(*t_end));
*lng_ln = *t_end-*t_ini+1;
return *lng_ln>0 ? true: false;
}
return false;
}
#endif // MODUTILES_H
#include "modutiles.h"
size_t ByteIndex( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find, size_t szt_lsf, size_t szt_Start, e_CompareMethod enum_Compare )
/**
[*pByt_Bytes] Puntero a los Bytes.
[szt_ls]] Longitud de [*pByt_Bytes].
[*pByt_Find] Puntero a los Bytes a buscar dentro de [*pByt_Bytes].
[szt_lsf]] Longitud de [*pByt_Find].
[szt_Start] Punto inicial desde donde se buscara en [*pByt_Bytes].
[enum_Compare] Indica el metodo de busqueda.
Retorna la posicion de [*pByt_Find] en [*pByt_Bytes] desde [szt_Start] hasta [szt_ls].
Nota: se pude quitar [szt_Start] y obviar en [*pByt_Bytes].
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
size_t szt_i = 0;
bool boo_v = false;
if ( szt_ls>=szt_lsf )
for ( szt_i=szt_Start, boo_v=false ; szt_i<(szt_ls-szt_lsf+1) && boo_v==false; szt_i++ )
boo_v = ByteExits(pByt_Bytes, szt_ls, pByt_Find, szt_lsf, szt_i, 1, enum_Compare);
if (boo_v != false)
return szt_i;
return 0;
}
size_t ByteIndex( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find, size_t szt_lsf, size_t szt_Start )
{ return ByteIndex ( pByt_Bytes , szt_ls, pByt_Find , szt_lsf , szt_Start , TEXTCOMPARE); }
size_t ByteIndex( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find, size_t szt_lsf )
{ return ByteIndex ( pByt_Bytes , szt_ls, pByt_Find , szt_lsf , 0, TEXTCOMPARE); }
bool ByteExits ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find , size_t szt_lsf , size_t szt_Start , long lng_interval, e_CompareMethod enum_Compare)
/**
[*pByt_Bytes] Puntero a los Bytes.
[szt_ls]] Longitud de [*pByt_Bytes].
[*pByt_Find] Puntero a los Bytes a buscar dentro de [*pByt_Bytes].
[szt_lsf]] Longitud de [*pByt_Find].
[szt_Start] Punto inicial desde donde se buscara en [*pByt_Bytes].
[lng_interval] Intervalo de busqueda de [*pByt_Find].
[enum_Compare] Indica el metodo de busqueda.
Retorna [true] si se encuentra [*pByt_Find] en [*pByt_Bytes] desde [szt_Start] hasta [szt_ls] en un intervalo de [lng_interval] y [false] si no lo encuentra.
Nota: se pude quitar [szt_Start] y obviar en [*pByt_Bytes].
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
size_t szt_i,
szt_j;
bool boo_v;
long lng_res = (lng_interval*(szt_lsf-1)) + szt_Start;
boo_v = lng_res>=0 && lng_res<=szt_ls ? true:false; // Verifica limites cerrados de [ 0 , szt_ls ].
switch ( enum_Compare ) {
case BINARY:
for ( szt_i=szt_Start, szt_j=0; szt_j<szt_lsf && boo_v==true ; szt_i+=lng_interval, szt_j++ ) {
boo_v = pByt_Bytes[szt_i]==pByt_Find[szt_j] ? true:false;
}
break;
case TEXTCOMPARE:
for ( szt_i=szt_Start, szt_j=0; szt_j<szt_lsf && boo_v==true ; szt_i+=lng_interval, szt_j++ ) {
if ( pByt_Bytes[szt_i]==pByt_Find[szt_j] )
boo_v = true;
else if ( CmpCharMTLTM(&pByt_Bytes[szt_i]) == pByt_Find[szt_j] )
boo_v = true ;
else
boo_v = false;
}
break;
}
return boo_v;
}
bool ByteExits ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find , size_t szt_lsf , size_t szt_Start , long lng_interval)
{ return ByteExits ( pByt_Bytes , szt_ls, pByt_Find , szt_lsf , szt_Start , lng_interval, TEXTCOMPARE); }
bool ByteExits ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find , size_t szt_lsf , size_t szt_Start)
{ return ByteExits ( pByt_Bytes , szt_ls, pByt_Find , szt_lsf , szt_Start , 1, TEXTCOMPARE); }
bool ByteExits ( Byte *pByt_Bytes , size_t szt_ls, Byte *pByt_Find , size_t szt_lsf )
{ return ByteExits ( pByt_Bytes , szt_ls, pByt_Find , szt_lsf , 0 , 1, TEXTCOMPARE); }
Struct_Byte* ByteReplace(Byte *pByt_Bytes, size_t szt_lnBytes, Byte *pByt_Find, size_t szt_lnFind, Byte *pByt_Replacement, size_t szt_lnReplacement, size_t szt_Start, long lng_Count, e_CompareMethod enum_Compare)
/**
[*pByt_Bytes] Bytes a Clonar.
[*szt_lnBytes] Cantidad de Bytes a Clonar.
[*pByt_Find] Puntero al inicio de los bytes a buscar en [*pByt_Bytes].
[szt_lnFind] longitud de [*pByt_Find].
[*pByt_Replacement] Puntero a los bytes con los cuales se reemplazaran [*pByt_Find].
[szt_lnReplacement] Indica la longitud de Bytes de [*pByt_Replacement].
[szt_Start] Indice de [*pByt_Bytes] donde se empesara a buscar a [*pByt_Find].
[lng_Count] Indica la cantidad de Coherencias a reemplazar, si es -1 indica TODAs las coherencias encontradas.
[enum_Compare] Indica el modo de Buqueda.
Retorna una copia con los TODAS las coherencias de bytes ya reemplazados en [*pByt_Bytes].
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
size_t szt_c = 0;
Struct_Byte *pstrs_ret = NULL;
Struct_Byte_Split *pstrspli_ret = NULL;
if ( (pstrs_ret = (Struct_Byte*)malloc(sizeof(Struct_Byte))) == NULL || szt_lnBytes <= 0 )
return pstrs_ret;
pstrs_ret->pbyt_bytes = NULL;
pstrs_ret->szt_lenbytes = 0;
if ( !(szt_lnFind > 0 && szt_lnBytes >= (szt_lnFind) && lng_Count != 0) )
return pstrs_ret;
if ( szt_Start > (szt_lnBytes - szt_lnFind) )
return pstrs_ret;
if ( lng_Count == 0 )
return pstrs_ret;
pstrspli_ret = ByteSplit ( &pByt_Bytes[szt_Start] , szt_lnBytes , pByt_Find , szt_lnFind , lng_Count+1 );
if ( pstrspli_ret != NULL ) {
for ( szt_c = 0 ; szt_c < pstrspli_ret->szt_ln ; szt_c++ ) {
if ( pstrspli_ret->Struct[ szt_c ] != NULL ) {
if ( pByt_Replacement != NULL )
if ( szt_c >= (pstrspli_ret->szt_ln-1))
szt_lnReplacement = 0;
pstrs_ret->pbyt_bytes = (Byte*)reallocpp( pstrs_ret->pbyt_bytes , pstrs_ret->szt_lenbytes , szt_lnReplacement+pstrs_ret->szt_lenbytes+pstrspli_ret->Struct[szt_c]->szt_lenbytes);
if ( pstrs_ret->pbyt_bytes != NULL ) {
if ( pstrspli_ret->Struct[ szt_c ]->szt_lenbytes>0 ) {
memcpy( &pstrs_ret->pbyt_bytes[ pstrs_ret->szt_lenbytes ] , pstrspli_ret->Struct[ szt_c ]->pbyt_bytes , pstrspli_ret->Struct[ szt_c ]->szt_lenbytes );
pstrs_ret->szt_lenbytes += pstrspli_ret->Struct[szt_c]->szt_lenbytes;
}
if ( pByt_Replacement != NULL )
if ( szt_c < (pstrspli_ret->szt_ln-1) ) {
memcpy( &pstrs_ret->pbyt_bytes[ pstrs_ret->szt_lenbytes ] , pByt_Replacement , szt_lnReplacement );
pstrs_ret->szt_lenbytes += szt_lnReplacement;
}
}
free ( pstrspli_ret->Struct[ szt_c ]->pbyt_bytes );
free ( pstrspli_ret->Struct[ szt_c ] );
}
}
free ( pstrspli_ret->Struct );
free ( pstrspli_ret );
}
return pstrs_ret;
}
Struct_Byte* ByteReplace(Byte *pByt_Bytes, size_t szt_lnBytes, Byte *pByt_Find, size_t szt_lnFind, Byte *pByt_Replacement, size_t szt_lnReplacement, size_t szt_Start, long lng_Count)
{ return ByteReplace( pByt_Bytes , szt_lnBytes , pByt_Find , szt_lnFind , pByt_Replacement , szt_lnReplacement , szt_Start , lng_Count , BINARY ); }
Struct_Byte* ByteReplace(Byte *pByt_Bytes, size_t szt_lnBytes, Byte *pByt_Find, size_t szt_lnFind, Byte *pByt_Replacement, size_t szt_lnReplacement, size_t szt_Start)
{ return ByteReplace( pByt_Bytes , szt_lnBytes , pByt_Find , szt_lnFind , pByt_Replacement , szt_lnReplacement , szt_Start , -1 , BINARY ); }
Struct_Byte* ByteReplace(Byte *pByt_Bytes, size_t szt_lnBytes, Byte *pByt_Find, size_t szt_lnFind, Byte *pByt_Replacement, size_t szt_lnReplacement)
{ return ByteReplace( pByt_Bytes , szt_lnBytes , pByt_Find , szt_lnFind , pByt_Replacement , szt_lnReplacement , 0 , -1 , BINARY ); }
Byte *reallocpp( Byte *pvoid_in , size_t szt_a, size_t szt_n )
{
Byte *pvoid_ret = (Byte*)malloc(sizeof(Byte)*szt_n);
if ( pvoid_in != NULL && pvoid_ret != NULL ) {
if ( szt_a>0 ) {
memcpy ( pvoid_ret , pvoid_in , szt_a );
}
delete pvoid_in;
}
return pvoid_ret;
}
Byte* ByteClone( Byte *pByt_Bytes , size_t szt_lenbytes )
/**
[*pByt_Bytes] Bytes a Clonar.
[*szt_lenbytes] Cantidad de Bytes a Clonar.
Retorna una copia exacta de [*pByt_Bytes] con la longitud indicada en [*szt_lenbytes],
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
if ( pByt_Bytes == NULL || szt_lenbytes <= 0 ) {
return NULL;
}
szt_lenbytes *= sizeof(Byte);
return (Byte*)memcpy( (Byte*)malloc(sizeof(Byte)*szt_lenbytes) , pByt_Bytes , szt_lenbytes );
}
Byte CmpCharMTLTM(Byte *chr_v)
/**
[*chr_v] Puntero a la Cedena (Solo se tomara en cuenta el primer elemento).
Se retorna si es Alfabeto ( de la "AZaz" en mayusculas y minusculas) y segun el primer elemento se retornara la consonante o vocal contraria; es decir si es mayuscula se retornara una minuscula y viceversa, si no es del Alfabeto se retornara solo el 1er elemento de [*chr_v]
Nota: se puede obviar a [ulng_pos] por medio de [*chr_v].
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
if ( chr_v != NULL ) {
if ( (chr_v[0]>='a' && chr_v[0]<='z') )
return (Byte)(chr_v[0] - ('a' - 'A'));
else if ( chr_v[0]=='ñ' )
return (Byte)'Ñ';
else if ( (chr_v[0]>='A' && chr_v[0]<='Z') || chr_v[0]=='Ñ' )
return (Byte)(chr_v[0] + ('a' - 'A'));
else if ( chr_v[0]=='Ñ' )
return (Byte)'ñ';
return chr_v[0];
}
return (Byte)'\0';
}
Struct_Byte* ByteMid( Byte* pbyt_str , size_t szt_lnstr , size_t szt_start , size_t szt_len )
/**
Se obtiene el fragmento deseado de [*pbyt_str]
[szt_start] Indica desde donde se empesara
[Len] Indica la distancia.
Retorna el puntero al clon del fragmento deseado de [*pbyt_str]
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
struct Struct_Byte *strbyte_ret = (Struct_Byte*)malloc(sizeof(Struct_Byte));
size_t szt_end = szt_start+szt_len-1;
strbyte_ret->szt_lenbytes = 0;
strbyte_ret->pbyt_bytes = NULL;
if ( fix_numbers_range<size_t>( &szt_start , &szt_end , (long*)&szt_len , NULL , 0 , szt_lnstr-1) == true ) {
strbyte_ret->szt_lenbytes = sizeof(Byte) * szt_len;
strbyte_ret->pbyt_bytes = (Byte*)malloc(sizeof(Byte)*strbyte_ret->szt_lenbytes);
if ( strbyte_ret->pbyt_bytes == NULL )
setnewptrf<Struct_Byte*>( strbyte_ret , NULL );
else
memcpy( strbyte_ret->pbyt_bytes , &pbyt_str[szt_start] , szt_len );
}
return strbyte_ret;
}
Struct_Byte_Split *ByteSplit( Byte *pbyt_str , size_t szt_lnstr , Byte *pbyt_delimiter , size_t szt_lndelimiter , long lng_limit )
/**
Separa a [*pbyt_str] cada vez que se encuentre a [*pbyt_delimiter] con un limite definido en [lng_limit]
Si [lng_limit] = -1 se crea un Maximo mayor a [-1] en el indice del vector retornado
Si [lng_limit] > -1 Se indica y establece un indice mayor [pero no fijo] del indice mayor del vector retornado
Se retorna el puntero a la estructura contenedora a los puntos separados. funcion retorna el puntero a el vector retultante.
En casos contrarios no crea un vector y retorna 0 y [lng_limit] = [-1]
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
size_t szt_bytind = 0,
szt_bytindb = 0;
struct Struct_Byte_Split *pi_out = (Struct_Byte_Split*)malloc(sizeof(Struct_Byte_Split));
pi_out->szt_ln = 0;
if ( lng_limit >= -1 && pi_out != NULL ) {
pi_out->szt_ln = 0;
pi_out->Struct = NULL;
if ( szt_lndelimiter != 0 )
for(;;) {
pi_out->Struct = (Struct_Byte**)reallocpp( (Byte*)pi_out->Struct , sizeof(Struct_Byte*)*(pi_out->szt_ln) , sizeof(Struct_Byte*)*(pi_out->szt_ln+1) );
if ( pi_out->szt_ln == (lng_limit-1) ) {
pi_out->Struct[ pi_out->szt_ln++ ] = ByteMid( pbyt_str , szt_lnstr , szt_bytindb , szt_lnstr );
break;
}
szt_bytind = ByteIndex( pbyt_str , szt_lnstr , pbyt_delimiter , szt_lndelimiter , szt_bytindb , BINARY );
if ( szt_bytind == 0 && szt_bytindb >= szt_lnstr )
break;
if ( szt_bytind == 0 ) {
pi_out->Struct[pi_out->szt_ln++] = ByteMid( pbyt_str , szt_lnstr , szt_bytindb , szt_lnstr );
break;
}
pi_out->Struct[pi_out->szt_ln++] = ByteMid( pbyt_str , szt_lnstr , szt_bytindb , ((--szt_bytind)-szt_bytindb) );
szt_bytindb = szt_bytind + szt_lndelimiter;
if ( szt_bytindb == szt_lnstr) {
pi_out->Struct = (Struct_Byte**)reallocpp( (Byte*)pi_out->Struct , sizeof(Struct_Byte*)*(pi_out->szt_ln) , sizeof(Struct_Byte*)*(pi_out->szt_ln+1) );
pi_out->Struct[pi_out->szt_ln] = (Struct_Byte*)malloc(sizeof(Struct_Byte));
pi_out->Struct[pi_out->szt_ln]->pbyt_bytes = NULL;
pi_out->Struct[pi_out->szt_ln++]->szt_lenbytes = 0;
break;
}
}
}
return pi_out;
}
Struct_Byte_Split *ByteSplit( Byte *pbyt_str , size_t szt_lnstr , Byte *pbyt_delimiter , size_t szt_lndelimiter )
{ return ByteSplit( pbyt_str , szt_lnstr , pbyt_delimiter , szt_lndelimiter ); }
size_t flen(FILE *pFl)
/**
[*pFl] Puntero al Archivo abierto
Retorna el peso en [BYTES] del archivo [*pFl].
By BlackZeroX ( http://Infrangelux.sytes.net/ )
**/
{
size_t szt_pn = 0,
szt_fl = 0;
if ( pFl != NULL ) {
szt_pn = ftell( pFl );
fseek ( pFl , 0L , SEEK_END);
szt_fl = ftell( pFl );
fseek ( pFl , szt_pn , SEEK_SET);
}
return szt_fl;
}
Cita de: seba123neo en 27 Abril 2011, 05:16 AM
en la misma pagina de microsoft lo dice
CitarEs solo una similitud con la Notación Húngara es decir que si no te apatece usar dicha notacion en tu programa puedes implementar esta, aun que solo es factible en vb6 ya que de hecho la Notación Hungara es aun mucho mejor desde mi punto de vista, aun que me a mi en lo personal me gusta la declaracion corta.
No le veo mucha utilidad pero le da facha a mis funciones jajaja , un saludo !!
dim variable&
msgbox typename(variable&)
' // Aun que es lo mismo que:
msgbox typename(variable)
#ifndef _CLS_BYTE_H_
#define _CLS_BYTE_H_
#include <fstream>
#include <stdlib.h>
#include <string.h>
#include "Bytes/modutiles.h"
// #include <stdbool.h> <-- C ANSI... (C99)CLS_BYTE_CPP
class cls_byte;
#ifndef Struct_clsByte_
#define Struct_clsByte_
struct Struct_clsByte
{
cls_byte *pbyt_class;
size_t szt_count;
};
#endif // Struct_clsByte_
class cls_byte
{
private:
size_t szt_len;
Byte *pbyt_data;
public:
cls_byte();
~cls_byte();
size_t Getlen ( );
Byte *GetBytesPtr ( );
struct Struct_Byte *GetBytes ( );
Byte *SetBytes ( Byte *pByt_Bytes , size_t szt_lnBytes ); // ok
Byte *SetBytes ( cls_byte *pclsbyteFind );
Byte *SetBytes ( Struct_Byte *pclsbyteFind ); // ok
bool SetBytesFromFile( const char *pcchr );
bool SetBytesFromFile( const char *pcchr , size_t szt_ini );
bool SetBytesFromFile( const char *pcchr , size_t szt_ini , long lng_len );
cls_byte *Mid ( size_t szt_start , size_t szt_len );
cls_byte *Mid ( size_t szt_start );
Struct_clsByte *Split ( Byte *pbyt_delimiter , size_t szt_lndelimiter , long lng_limit );
Struct_clsByte *Split ( Byte *pbyt_delimiter , size_t szt_lndelimiter );
Struct_clsByte *Split ( cls_byte *pclsbytelim , long lng_limit );
Struct_clsByte *Split ( cls_byte *pclsbytelim );
cls_byte *Replace ( cls_byte *pclsbyteFind , cls_byte *pclsbyteReplacement );
cls_byte *Replace ( cls_byte *pclsbyteFind , cls_byte *pclsbyteReplacement , size_t szt_Start );
cls_byte *Replace ( cls_byte *pclsbyteFind , cls_byte *pclsbyteReplacement , size_t szt_Start , long lng_Count );
cls_byte *Replace ( cls_byte *pclsbyteFind , cls_byte *pclsbyteReplacemente , size_t szt_Start , long lng_Count , e_CompareMethod enum_Compare );
cls_byte *Replace ( cls_byte *pclsbyteFind , Byte *pByt_Replacement , size_t szt_lnReplacement );
cls_byte *Replace ( cls_byte *pclsbyteFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start );
cls_byte *Replace ( cls_byte *pclsbyteFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start , long lng_Count );
cls_byte *Replace ( cls_byte *pclsbyteFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start , long lng_Count , e_CompareMethod enum_Compare );
cls_byte *Replace ( Byte *pByt_Find , size_t szt_lnFind , cls_byte *pclsbyteReplacemente );
cls_byte *Replace ( Byte *pByt_Find , size_t szt_lnFind , cls_byte *pclsbyteReplacemente , size_t szt_Start );
cls_byte *Replace ( Byte *pByt_Find , size_t szt_lnFind , cls_byte *pclsbyteReplacemente , size_t szt_Start , long lng_Count );
cls_byte *Replace ( Byte *pByt_Find , size_t szt_lnFind , cls_byte *pclsbyteReplacemente , size_t szt_Start , long lng_Count , e_CompareMethod enum_Compare );
cls_byte *Replace ( Byte *pByt_Find , size_t szt_lnFind , Byte *pByt_Replacement , size_t szt_lnReplacement );
cls_byte *Replace ( Byte *pByt_Find , size_t szt_lnFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start );
cls_byte *Replace ( Byte *pByt_Find , size_t szt_lnFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start , long lng_Count );
cls_byte *Replace ( Byte *pByt_Find , size_t szt_lnFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start , long lng_Count , e_CompareMethod enum_Compare );
size_t Index ( cls_byte *pclsbyte );
size_t Index ( cls_byte *pclsbyte , size_t szt_Start );
size_t Index ( cls_byte *pclsbyte , size_t szt_Start , e_CompareMethod enum_Compare );
size_t Index ( Byte *pByt_Find , size_t szt_lsf );
size_t Index ( Byte *pByt_Find , size_t szt_lsf , size_t szt_Start );
size_t Index ( Byte *pByt_Find , size_t szt_lsf , size_t szt_Start , e_CompareMethod enum_Compare );
bool Exits ( cls_byte *pclsbyte );
bool Exits ( cls_byte *pclsbyte , size_t szt_Start );
bool Exits ( cls_byte *pclsbyte , size_t szt_Start , long lng_interval );
bool Exits ( cls_byte *pclsbyte , size_t szt_Start , long lng_interval , e_CompareMethod enum_Compare );
bool Exits ( Byte *pByt_Find , size_t szt_lsf );
bool Exits ( Byte *pByt_Find , size_t szt_lsf , size_t szt_Start );
bool Exits ( Byte *pByt_Find , size_t szt_lsf , size_t szt_Start , long lng_interval );
bool Exits ( Byte *pByt_Find , size_t szt_lsf , size_t szt_Start , long lng_interval , e_CompareMethod enum_Compare );
};
// #include "cls_byte.cpp"
#endif // CLS_BYTE_H
#ifndef _CLS_BYTE_CPP
#define _CLS_BYTE_CPP 1
#include "cls_byte.h"
cls_byte::cls_byte()
{
this->szt_len = 0;
this->pbyt_data = NULL;
}
cls_byte::~cls_byte()
{ setnewptrf<Byte*>( this->pbyt_data , NULL ); }
size_t cls_byte::Getlen()
{ return this->szt_len; }
Byte *cls_byte::GetBytesPtr()
{ return this->pbyt_data; }
bool cls_byte::SetBytesFromFile(const char *pcchr)
{ return this->SetBytesFromFile( pcchr , 0 , -1 ); }
bool cls_byte::SetBytesFromFile(const char *pcchr, size_t szt_ini)
{ return this->SetBytesFromFile( pcchr , szt_ini , -1 ); }
bool cls_byte::SetBytesFromFile(const char *pcchr, size_t szt_ini, long lng_len)
{
FILE *hfile = fopen( pcchr , "r+b" );
Struct_Byte stbyt_data = { NULL , 0 };
size_t szt_end = 0;
if ( hfile != NULL )
{
stbyt_data.szt_lenbytes = flen( hfile );
if ( lng_len <= -1 )
lng_len = stbyt_data.szt_lenbytes;
szt_end = 0;
if ( fix_numbers_range<size_t>( &szt_ini , &szt_end , &lng_len , NULL , 0 , stbyt_data.szt_lenbytes-1 ) == true )
{
stbyt_data.pbyt_bytes = (Byte*)malloc(sizeof(Byte)*lng_len);
fseek ( hfile , (long)szt_ini , SEEK_SET);
fread ( (char*)stbyt_data.pbyt_bytes , 1 , lng_len , hfile );
}
stbyt_data.szt_lenbytes = (size_t)lng_len;
fclose ( hfile );
this->SetBytes( &stbyt_data );
}
}
Byte *cls_byte::SetBytes(Struct_Byte *pclsbyteFind)
{ return this->SetBytes( pclsbyteFind->pbyt_bytes , pclsbyteFind->szt_lenbytes ); }
Byte *cls_byte::SetBytes(cls_byte *pclsbyteFind)
{ return this->SetBytes( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() ); }
Byte *cls_byte::SetBytes(Byte *pByt_Bytes, size_t szt_lnBytes)
{
this->szt_len = szt_lnBytes;
if ( setnewptrf<Byte*>( this->pbyt_data , ByteClone( pByt_Bytes , this->szt_len ) ) == NULL)
{
this->szt_len = 0;
return pByt_Bytes;
}
return NULL;
}
Struct_Byte *cls_byte::GetBytes()
{
struct Struct_Byte *pstrbyt_ret = (Struct_Byte*)malloc(sizeof(Struct_Byte));
pstrbyt_ret->pbyt_bytes = ByteClone( this->pbyt_data , this->szt_len );
pstrbyt_ret->szt_lenbytes = this->szt_len;
if ( pstrbyt_ret->pbyt_bytes == NULL )
pstrbyt_ret->szt_lenbytes = 0;
return pstrbyt_ret;
}
size_t cls_byte::Index(Byte *pByt_Find, size_t szt_lsf)
{ return ByteIndex( this->pbyt_data , this->szt_len ,pByt_Find , szt_lsf ); }
size_t cls_byte::Index(Byte *pByt_Find, size_t szt_lsf, size_t szt_Start)
{ return ByteIndex( this->pbyt_data , this->szt_len , pByt_Find , szt_lsf , szt_Start ); }
size_t cls_byte::Index(Byte *pByt_Find, size_t szt_lsf, size_t szt_Start, e_CompareMethod enum_Compare)
{ return ByteIndex( this->pbyt_data , this->szt_len , pByt_Find , szt_lsf , szt_Start , enum_Compare ); }
size_t cls_byte::Index(cls_byte *pclsbyte)
{ return ByteIndex( this->pbyt_data , this->szt_len , pclsbyte->pbyt_data , pclsbyte->szt_len ); }
size_t cls_byte::Index(cls_byte *pclsbyte, size_t szt_Start)
{ return ByteIndex( this->pbyt_data , this->szt_len , pclsbyte->pbyt_data , pclsbyte->szt_len , szt_Start ); }
size_t cls_byte::Index(cls_byte *pclsbyte, size_t szt_Start, e_CompareMethod enum_Compare)
{ return ByteIndex( this->pbyt_data , this->szt_len , pclsbyte->pbyt_data , pclsbyte->szt_len , szt_Start , enum_Compare ); }
bool cls_byte::Exits(cls_byte *pclsbyte)
{ return ByteExits( this->pbyt_data , this->szt_len , pclsbyte->pbyt_data , pclsbyte->szt_len ); }
bool cls_byte::Exits(cls_byte *pclsbyte, size_t szt_Start)
{ return ByteExits( this->pbyt_data , this->szt_len , pclsbyte->pbyt_data , pclsbyte->szt_len , szt_Start ); }
bool cls_byte::Exits(cls_byte *pclsbyte, size_t szt_Start, long lng_interval)
{ return ByteExits( this->pbyt_data , this->szt_len , pclsbyte->pbyt_data , pclsbyte->szt_len , szt_Start , lng_interval ); }
bool cls_byte::Exits(cls_byte *pclsbyte, size_t szt_Start, long lng_interval, e_CompareMethod enum_Compare)
{ return ByteExits( this->pbyt_data , this->szt_len , pclsbyte->pbyt_data , pclsbyte->szt_len , szt_Start , lng_interval , enum_Compare ); }
bool cls_byte::Exits(Byte *pByt_Find, size_t szt_lsf)
{ return ByteExits( this->pbyt_data , this->szt_len , pByt_Find , szt_lsf ); }
bool cls_byte::Exits(Byte *pByt_Find, size_t szt_lsf, size_t szt_Start)
{ return ByteExits( this->pbyt_data , this->szt_len , pByt_Find , szt_lsf , szt_Start ); }
bool cls_byte::Exits(Byte *pByt_Find, size_t szt_lsf, size_t szt_Start, long lng_interval)
{ return ByteExits( this->pbyt_data , this->szt_len , pByt_Find , szt_lsf , szt_Start , lng_interval ); }
bool cls_byte::Exits(Byte *pByt_Find, size_t szt_lsf, size_t szt_Start, long lng_interval, e_CompareMethod enum_Compare)
{ return ByteExits( this->pbyt_data , this->szt_len , pByt_Find , szt_lsf , szt_Start , lng_interval , enum_Compare ); }
cls_byte *cls_byte::Replace ( cls_byte *pclsbyteFind , cls_byte *pclsbyteReplacement )
{ return this->Replace( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() , pclsbyteReplacement->GetBytesPtr() , pclsbyteReplacement->Getlen() , 0 , -1 , BINARY ); }
cls_byte *cls_byte::Replace ( cls_byte *pclsbyteFind , cls_byte *pclsbyteReplacement , size_t szt_Start )
{ return this->Replace( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() , pclsbyteReplacement->GetBytesPtr() , pclsbyteReplacement->Getlen() , szt_Start , -1 , BINARY ); }
cls_byte *cls_byte::Replace ( cls_byte *pclsbyteFind , cls_byte *pclsbyteReplacement , size_t szt_Start , long lng_Count )
{ return this->Replace( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() , pclsbyteReplacement->GetBytesPtr() , pclsbyteReplacement->Getlen() , szt_Start , lng_Count , BINARY ); }
cls_byte *cls_byte::Replace ( cls_byte *pclsbyteFind , cls_byte *pclsbyteReplacement , size_t szt_Start , long lng_Count , e_CompareMethod enum_Compare )
{ return this->Replace( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() , pclsbyteReplacement->GetBytesPtr() , pclsbyteReplacement->Getlen() , szt_Start , lng_Count , enum_Compare ); }
cls_byte *cls_byte::Replace ( cls_byte *pclsbyteFind , Byte *pByt_Replacement , size_t szt_lnReplacement )
{ return this->Replace( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() , pByt_Replacement , szt_lnReplacement , 0 , -1 , BINARY ); }
cls_byte *cls_byte::Replace ( cls_byte *pclsbyteFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start )
{ return this->Replace( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() , pByt_Replacement , szt_lnReplacement , szt_Start , -1 , BINARY ); }
cls_byte *cls_byte::Replace ( cls_byte *pclsbyteFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start , long lng_Count )
{ return this->Replace( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() , pByt_Replacement , szt_lnReplacement , szt_Start , lng_Count , BINARY ); }
cls_byte *cls_byte::Replace ( cls_byte *pclsbyteFind , Byte *pByt_Replacement , size_t szt_lnReplacement , size_t szt_Start , long lng_Count , e_CompareMethod enum_Compare )
{ return this->Replace( pclsbyteFind->GetBytesPtr() , pclsbyteFind->Getlen() , pByt_Replacement , szt_lnReplacement , szt_Start , lng_Count , enum_Compare ); }
cls_byte *cls_byte::Replace ( Byte *pByt_Find , size_t szt_lnFind , cls_byte *pclsbyteReplacement )
{ return this->Replace( pByt_Find , szt_lnFind , pclsbyteReplacement->GetBytesPtr() , pclsbyteReplacement->Getlen() , 0 , -1 , BINARY ); }
cls_byte *cls_byte::Replace ( Byte *pByt_Find , size_t szt_lnFind , cls_byte *pclsbyteReplacement , size_t szt_Start )
{ return this->Replace( pByt_Find , szt_lnFind , pclsbyteReplacement->GetBytesPtr() , pclsbyteReplacement->Getlen() , szt_Start , -1 , BINARY ); }
cls_byte *cls_byte::Replace ( Byte *pByt_Find , size_t szt_lnFind , cls_byte *pclsbyteReplacement , size_t szt_Start , long lng_Count )
{ return this->Replace( pByt_Find , szt_lnFind , pclsbyteReplacement->GetBytesPtr() , pclsbyteReplacement->Getlen() , szt_Start , lng_Count , BINARY ); }
cls_byte *cls_byte::Replace ( Byte *pByt_Find , size_t szt_lnFind , cls_byte *pclsbyteReplacement , size_t szt_Start , long lng_Count , e_CompareMethod enum_Compare )
{ return this->Replace( pByt_Find , szt_lnFind , pclsbyteReplacement->GetBytesPtr() , pclsbyteReplacement->Getlen() , szt_Start , lng_Count , enum_Compare ); }
cls_byte *cls_byte::Replace(Byte *pByt_Find, size_t szt_lnFind, Byte *pByt_Replacement, size_t szt_lnReplacement)
{ return this->Replace( pByt_Find , szt_lnFind , pByt_Replacement , szt_lnReplacement , 0 , -1 , BINARY ); }
cls_byte *cls_byte::Replace(Byte *pByt_Find, size_t szt_lnFind, Byte *pByt_Replacement, size_t szt_lnReplacement, size_t szt_Start)
{ return this->Replace( pByt_Find , szt_lnFind , pByt_Replacement , szt_lnReplacement , szt_Start , -1 , BINARY ); }
cls_byte *cls_byte::Replace(Byte *pByt_Find, size_t szt_lnFind, Byte *pByt_Replacement, size_t szt_lnReplacement, size_t szt_Start, long lng_Count)
{ return this->Replace( pByt_Find , szt_lnFind , pByt_Replacement , szt_lnReplacement , szt_Start , lng_Count , BINARY ); }
cls_byte *cls_byte::Replace(Byte *pByt_Find, size_t szt_lnFind, Byte *pByt_Replacement, size_t szt_lnReplacement, size_t szt_Start, long lng_Count, e_CompareMethod enum_Compare)
{
cls_byte *cls_Ret = (cls_byte*)malloc(sizeof(cls_byte));
Struct_Byte *pByt_Ret = NULL;
Byte *pByt_ClnF = ByteClone ( pByt_Find , szt_lnFind );
Byte *pByt_ClnR = ByteClone ( pByt_Replacement , szt_lnReplacement );
pByt_Ret = ByteReplace( this->pbyt_data , this->szt_len , pByt_ClnF , szt_lnFind , pByt_ClnR , szt_lnReplacement , szt_Start , lng_Count , enum_Compare );
cls_Ret->SetBytes ( pByt_Ret );
setnewptrf<Byte*> ( pByt_ClnF , NULL );
setnewptrf<Byte*> ( pByt_ClnR , NULL );
setnewptrf<Byte*> ( pByt_Ret->pbyt_bytes , NULL );
setnewptrf<Struct_Byte*> ( pByt_Ret , NULL );
return cls_Ret;
}
cls_byte *cls_byte::Mid(size_t szt_start)
{ return this->Mid ( szt_start , this->szt_len ); }
cls_byte *cls_byte::Mid(size_t szt_start, size_t szt_len)
{
cls_byte *cls_Ret = (cls_byte*)malloc(sizeof(cls_byte));
Struct_Byte *pByt_Ret = NULL;
pByt_Ret = ByteMid ( this->pbyt_data , this->szt_len , szt_start , szt_len );
cls_Ret->SetBytes ( pByt_Ret );
setnewptrf<Byte*> ( pByt_Ret->pbyt_bytes , NULL );
setnewptrf<Struct_Byte*> ( pByt_Ret , NULL );
return cls_Ret;
}
Struct_clsByte *cls_byte::Split(Byte *pbyt_delimiter, size_t szt_lndelimiter)
{ return this->Split ( pbyt_delimiter , szt_lndelimiter , -1 ); }
Struct_clsByte *cls_byte::Split(Byte *pbyt_delimiter, size_t szt_lndelimiter, long lng_limit)
{
Struct_clsByte *cls_Ret = (Struct_clsByte*)malloc(sizeof(Struct_clsByte));
Struct_Byte_Split *pByt_Ret = NULL;
Byte *pByt_Clone = ByteClone ( pbyt_delimiter , szt_lndelimiter );
pByt_Ret = ByteSplit ( this->pbyt_data , this->szt_len , pByt_Clone , szt_lndelimiter , lng_limit );
cls_Ret->szt_count = 0;
cls_Ret->pbyt_class = (cls_byte*)malloc(sizeof(cls_byte)*pByt_Ret->szt_ln);
for ( cls_Ret->szt_count=0 ; cls_Ret->szt_count<pByt_Ret->szt_ln ; ++cls_Ret->szt_count )
{
cls_Ret->pbyt_class[ cls_Ret->szt_count ].SetBytes( pByt_Ret->Struct[ cls_Ret->szt_count ] );
setnewptrf<Byte*> ( pByt_Ret->Struct[ cls_Ret->szt_count ]->pbyt_bytes , NULL );
setnewptrf<Struct_Byte*> ( pByt_Ret->Struct[ cls_Ret->szt_count ] , NULL );
}
setnewptrf<Byte*> ( pByt_Clone , NULL );
setnewptrf<Struct_Byte_Split*> ( pByt_Ret , NULL );
return cls_Ret;
}
Struct_clsByte *cls_byte::Split(cls_byte *pclsbytelim)
{ return this->Split ( pclsbytelim->GetBytesPtr() , pclsbytelim->Getlen() , -1 ); }
Struct_clsByte *cls_byte::Split(cls_byte *pclsbytelim, long lng_limit)
{ return this->Split ( pclsbytelim->GetBytesPtr() , pclsbytelim->Getlen() , lng_limit ); }
#endif
Cita de: ŞCØRPIØN-X3 en 25 Abril 2011, 21:47 PM
gracias por la respuesta, estoy probando pero le falta el loop para que se repita la operación y falta ponerle un limite a bBuf
Public Function WindirConc(byval str$)
WindirConc = (Environ$("windir")) & "\" & str$ & ".php"
End Function
' // En otro proceso...
msgbox WindirConc(Form1.txtName.Text)
Do While EOF(ff) = false
const sfile as string = "C:\Archivo.txt"
Dim bBuff() As byte ' // usamos byte por que con string nos consumira el doble de memoria.
Dim ff As Integer
if (dir(sfile,vbarchive)<>"") then
ff = FreeFile
Open (sfile) For Binary As ff
if ( LOF(ff) > 0 ) then
redim bBuff( 0 to (LOF(ff)-1) ) ' // con una string seria sBuff=space(LOF(ff)) sin el "-1"
Get ff, , bBuff
end if
Close ff
Form1.Winsock1.SendData bBuff
end if
sub main()
dim sVar as string
sVar = "Holaaa" & _
vbcrlf & _
"Cosa que monada" & _
" tampien vamonos derecho no? " & _
vbcrlf & vbtab & _
"Ecole una tabulacion en una nueva linea"
msgbox sVar, _
"TituloX"
end sub
sub main()
dim sVar as string
sVar = "Holaaa" & vbcrlf & _
"Cosa que monada tampien vamonos derecho no? " & _
vbcrlf & vbtab & "Ecole una tabulacion en una nueva linea"
msgbox sVar, _
"TituloX"
end sub