# FBB::OHexBuf(3bobcat)

## Write hex values
(libbobcat-dev_6.07.01)

## 2005-2025

## NAME

FBB::OHexBuf - Writes characters written to an ostream as hex values

## SYNOPSIS

#include <bobcat/ohexbuf>
Linking option: -lbobcat

## DESCRIPTION

OHexBuf is a specialization of FBB::OFilterBuf inserting all the characters it receives to a destination file as 2-character wide hexadecimal values. Optionally a maximum linelength can be specified.

Note that all information received by an OHexBuf object is inserted as (a series of) hexadecimal values, not only plain characters. E.g., when inserting the value 123 the characters '1', '2' and '3' are successively inserted and so this will result in the string 313233 being inserted into the destination stream.

## NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

## INHERITS FROM

FBB::OFilterBuf

## CONSTRUCTOR

- OHexBuf(std::ostream &stream, size_t width = 0, std::string const &separator = ""):
  The hexadecimal characters produced by the OFilterBuf object are inserted into stream. Optionally the maximum line width (in number of characters) may be specified using width. The (default) value 0 indicates that no line breaks are requested. The parameter separator defines the separator that's inserted between hexadecimal character values. By default no separator is used.

Copy and move constructors (and assignment operators) are not available.

The destructor writes any buffered information to the destination stream and then flushes the destination stream. Finally, the destructor restores the original formatting flags of the receiving ostream.

## MEMBER FUNCTIONS

All members of FBB::OFilterBuf, in particular its out() and reset members are available, as FBB::OHexBuf inherits from this class.

- void eoi():
  This member completes the current hexadecimal character conversion, clears the separator, and no longer uses a the maximum output line width. Instead of calling this member the eoi manipulator (see below) can be used.

- void separator(bool reset = true):
  This member clears the separator that's inserted between hexadecimal character values. When the reset parameter is set to true (which is the default) the currently used output width is reset to 0.

- void separator(std::string const &separator, bool reset = true):
  This member resets the separator that's inserted between hexadecimal character values to separator's value. When the reset parameter is set to true (which is the default) the currently used output width is reset to 0.

- void setWidth(size_t width):
  This member sets the width of the generated output lines to width characters. No maximum line width is used when width = 0 is specified.

- size_t size() const:
  This member returns the next column offset where the next hexadecimal character will appear. If a maximum line length is requested and size() does not return 0 then the last line inserted was not terminated by a '\n' character. See also the example below.

  This member's return value is undefined if no maximum line length was requested.

## MANIPULATOR

- FBB::eoi:
  The eoi manipulator can be inserted into the ostream to complete the hexaecimal conversion. It acts identically to calling the end member. If inserted into a plain std::ostream nothing happens.

## STATIC MEMBER

- std::string text2bin(std::string const &in):
  This static member converts a series of hexadecimal characters generated by a OHexBuf object back to their binary form. E.g, when called as OHexBuf::text2bin("736d616c6c206976") then the returned std::string will contain 8 characters, having respectively the binary values 0x73, 0x6d, 0x61, 0x6c, 0x6c, 0x20, 0x69, and 0x76.

  This function does not verify whether its argument is properly formed. A properly formed argument consists of an even number of hexadecimal number characters ('0' until '9', 'a' until 'f' (or uppercase)). For improperly formed arguments the return value is undefined.

## EXAMPLE

        #include <iostream>
        #include <bobcat/ohexbuf>

        using namespace std;
        using namespace FBB;

        int main()
        {
            OHexBuf ohex(cout, 40);
            ostream out(&ohex);
            out << cin.rdbuf();
            if (ohex.size())
                cout << '\n';
        }

## FILES

bobcat/ohexbuf - defines the class interface

## SEE ALSO

bobcat(7), ofilterbuf(3bobcat)

## BUGS

None Reported.

## BOBCAT PROJECT FILES

- https://fbb-git.gitlab.io/bobcat/: gitlab project page;

Debian Bobcat project files:

- libbobcat6: debian package containing the shared library, changelog and copyright note;
- libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;

## BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

## COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

## AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).