libclc bitset import/export 
Author Message
 libclc bitset import/export

I suggest the following two functions for libclc:
size_t clc_bitset_import(clc_bitset bitset, unsigned char *buf, size_t len)
size_t clc_bitset_export(clc_bitset bitset, unsigned char *buf, size_t len)

These functions copies a buffer of unsigned chars into the bitset. Each
uchar holds 8 bits to be inserted into the bitset. The function will copy
up to len bits or the size of the bitset, whichever is smaller. It returns
the number of bits successfully copied.

--
Freenet distribution not available
Never have children, only grandchildren.
                --{*filter*}Vidal



Wed, 31 Aug 2005 10:48:16 GMT  
 libclc bitset import/export

Quote:
> I suggest the following two functions for libclc:
> size_t clc_bitset_import(clc_bitset bitset, unsigned char *buf, size_t
len)
> size_t clc_bitset_export(clc_bitset bitset, unsigned char *buf, size_t
len)

> These functions copies a buffer of unsigned chars into the bitset. Each
> uchar holds 8 bits to be inserted into the bitset. The function will copy
> up to len bits or the size of the bitset, whichever is smaller. It returns
> the number of bits successfully copied.

Seems kind of wasteful if CHAR_BIT is a lot larger than 8.
--
C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 "The C-FAQ Book" ISBN 0-201-84519-9
C.A.P. FAQ: ftp://cap.connx.com/pub/Chess%20Analysis%20Project%20FAQ.htm


Wed, 31 Aug 2005 11:32:52 GMT  
 libclc bitset import/export

Quote:

> I suggest the following two functions for libclc:
> size_t clc_bitset_import(clc_bitset bitset, unsigned char *buf, size_t
len)
> size_t clc_bitset_export(clc_bitset bitset, unsigned char *buf, size_t
len)

> These functions copies a buffer of unsigned chars into the bitset.
> Each uchar holds 8 bits to be inserted into the bitset. The function
> will copy up to len bits or the size of the bitset, whichever is
> smaller. It returns the number of bits successfully copied.

I suggest the functions take a pointer to void, and you convert that into a
pointer to unsigned char internally in the implementation of the function.
This then allows you to import from or export to any object without ugly
typecasts.

I also suggest having two sets of functions: one set for using only 8 bits
per unsigned char, and the other one packing  all CHAR_BIT bits per unsigned
char. Or is that going too far? :-)

I also suggest that the import functions take a pointer to const, both as a
guarantee not to modify the buffer, and so that you can pass a pointer to a
const object if the need arises.

(Names abbreviated to prevent word-wrapping:)
size_t clc_bitset_import_8  (clc_bitset bs, const void *bf, size_t ln)
size_t clc_bitset_export_8  (clc_bitset bs,       void *bf, size_t ln)
size_t clc_bitset_import_all(clc_bitset bs, const void *bf, size_t ln)
size_t clc_bitset_export_all(clc_bitset bs,       void *bf, size_t ln)

--
Simon.



Wed, 31 Aug 2005 12:00:40 GMT  
 libclc bitset import/export

Quote:

> > I suggest the following two functions for libclc:
> > size_t clc_bitset_import(clc_bitset bitset, unsigned char *buf, size_t
>  len)
> > size_t clc_bitset_export(clc_bitset bitset, unsigned char *buf, size_t
>  len)

> > These functions copies a buffer of unsigned chars into the bitset.
> > Each uchar holds 8 bits to be inserted into the bitset. The function
> > will copy up to len bits or the size of the bitset, whichever is
> > smaller. It returns the number of bits successfully copied.

> I suggest the functions take a pointer to void, and you convert that into a
> pointer to unsigned char internally in the implementation of the function.
> This then allows you to import from or export to any object without ugly
> typecasts.

With void* arg:
if the caller provide, e.g., a buffer of unsigned int,
the corresponding sequence of unsigned chars will
differ from plateform to plateform because of endianess issues.
The padding bits are another problem.

With unsigned char*: import/export is definitively better than
the previously suggested map/unmap, because the former does not
expose the implementation, and thus does not couple the interface
with it (in map/unmap, the provided buffer is shared, not copied,
so the user knows the implementation of the bit-buffer).

Quote:
> I also suggest having two sets of functions: one set for using only 8 bits
> per unsigned char, and the other one packing  all CHAR_BIT bits per unsigned
> char. Or is that going too far? :-)

I Don't like duplicate functions:
merge them in one with an additional
parameter bpc (the number of used bits per unsigned chars):

size_t
clc_bitset_import
(clc_bitset bs, const unsigned char *bf, size_t bpc, size_t ln);

size_t
clc_bitset_export
(clc_bitset bs, unsigned char *bf, size_t bpc, size_tln);

--
Regis



Wed, 31 Aug 2005 19:30:14 GMT  
 libclc bitset import/export

Quote:



>> I suggest the following two functions for libclc:
>> size_t clc_bitset_import(clc_bitset bitset, unsigned char *buf, size_t
> len)
>> size_t clc_bitset_export(clc_bitset bitset, unsigned char *buf, size_t
> len)

>> These functions copies a buffer of unsigned chars into the bitset. Each
>> uchar holds 8 bits to be inserted into the bitset. The function will copy
>> up to len bits or the size of the bitset, whichever is smaller. It returns
>> the number of bits successfully copied.

> Seems kind of wasteful if CHAR_BIT is a lot larger than 8.

Well, you can add a field you number of bits, but we should allow
(more-or-less) portable I/O. I was hoping to reduce the complexity of the
implementation.

--
Freenet distribution not available
Q:      Why don't lawyers go to the beach?
A:      The cats keep trying to bury them.



Thu, 01 Sep 2005 11:58:56 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. libclc: bitset interface, new final vote

2. libclc: bitset interface

3. I want to Export and then import table( like in DTS Export/Import Wiz).

4. exporting/importing structs to/from dlls

5. SQL Server and Oracle database export/import

6. Importing and Exporting X509 public keys

7. Quest about import/export a c++ class from/into a dll

8. Turbo C Graphics Import/Export Help

9. SURVEY> Data Format Import/Export Tools

10. Creating a table from VC++ using stored in Access import/export table specification

11. Q: Exporting to XLS -- IDispatch or import?

12. Exporting Const value to .tli/tlh files with #import directive

 

 
Powered by phpBB® Forum Software