On Fri, Feb 7, 2014 at 12:28 PM, Tom Browder <[email protected]> wrote:
> No argument there!  Ideas welcome!. But I'm actually moving toward a
> consolidation of such conversions into a more general function--maybe

My thoughts on the hex/bin str/bu_vls/bitv conversions:

1.  As a group they are conversions to/from either a bin/hex string
format or bin/hex//bitv format.
2.  Group into something like

  bu_bitv_cvt_to_vls
  bu_bitv_cvt_from_vls   [wrapper around "bu_bitv_cvt_from_vls2" with
no choice of number of bytes]
  bu_bitv_cvt_from_vls2 [user chooses number of bytes]
  bu_vls_cvt_bin2hex [input binary string to bu_vls hex string]
  bu_vls_cvt_hex2bin [input hex string to bu_vls binary string]

Those 6 would absorb 9 (or possibly 12) current functions that I know of:

BU_EXPORT extern void bu_bitv_vls(struct bu_vls *v, const struct bu_bitv *bv);
BU_EXPORT extern void bu_pr_bitv(const char *str, const struct bu_bitv *bv);
BU_EXPORT extern void bu_bitv_to_hex(struct bu_vls *v, const struct
bu_bitv *bv);
BU_EXPORT extern struct bu_bitv *bu_hex_to_bitv(const char *str);
BU_EXPORT extern void bu_bitv_to_binary(struct bu_vls *v, const struct
bu_bitv *bv);
BU_EXPORT extern struct bu_bitv *bu_binary_to_bitv(const char *str);
BU_EXPORT extern struct bu_bitv *bu_binary_to_bitv2(const char *str,
const int nbytes);
BU_EXPORT extern void bu_hexstr_to_binstr(const char *hexstr, struct bu_vls *b);
BU_EXPORT extern void bu_binstr_to_hexstr(const char *binstr, struct bu_vls *h);

and possibly:

BU_EXPORT extern void bu_vls_printb
BU_EXPORT extern void bu_printb
BU_TESTS_EXPORT extern void dump_bitv

3.  Desired output string formats are also specified for appropriate
functions by an enum:

typedef enum {
    BU_BITV_CVT_HEX,         = 0x000010 /* e.g., "0xff" */
    BU_BITV_CVT_HEX_UC,      = 0x000011 /* e.g., "0XFF" */
    BU_BITV_CVT_HEX_PLAIN,   = 0x000012 /* e.g., "ff"   */

    BU_BITV_CVT_BINARY       = 0x001000,       /* e.g., "0b11" */
    BU_BITV_CVT_BINARY_UC    = 0x001001,    /* e.g., "0B11" */
    BU_BITV_CVT_BINARY_PLAIN = 0x001002, /* e.g., "11"   */

    BU_BITV_CVT_VLS          = 0x100001,          /* e.g., "(0, 4, 5)" */
    BU_BITV_CVT_DUMP         = 0x100002 /* e.g.,
                               *                3         2         1
                               *  bit    76543210987654321098765432109876543210
                               *  val    00011110010001111010001011101001000101
                               *
                               */
} bitv_convert_t;

Best regards,

-Tom

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-devel

Reply via email to