Skip to content
This repository was archived by the owner on Apr 24, 2020. It is now read-only.

About Channels

Victor Gubin edited this page Jul 8, 2014 · 8 revisions

About

Channels is a simple C++ library for providing Input/Output.

Motivation

C++ standard library input output has not very useful API for the production applications. It is good for writing an testing or teaching applications, but has limited usage for the real work applications. iostreams: are difficult in extend (you need to worry about file buffers etc, slow, not thread safe, uses like global variables i.e. std::cin, std::cout, std::err, adds restrictions for the data type and don't knows anything about Unicode as well as asynchronous input/output. Also streams are not very useful for working with the binary data.
Unlike iostreams channels have different design, it is split to the different layers. On the lowest layer there are channels and buffers, which are good for work with binary data. For example can be used for reading data from network socket and writing it into file or console device, or vice versa, copy files etc. Readers and writers are build on top of channels they also provides the character set conversation for example you source code is encoded as Windows CP1250 and you can write string literals to console/device/socket/file as Unicode or any another character representation (Char set) which is provided. Readers and writes a template based, so unlike iostreams you can use the char, char8_t, char16_t, char32_t as well as the wchar_t with the same API.

Description

Unlike of standard c++ lib (iostreams) this API is don't care about data you are using. And it is don't care about data types you using i.e you can use Unicode strings with char, char8_t-char32_t, wchar_t etc any binary data in uint8_t, float, double etc.

The original API idea is from Java NIO, anyway implementation is C++ specific and not 100% the same.

Currently you can open: read, write and read-write channel from file, and read and write channel from system console devices (in/out and err) , it is also trivial to add support of network using Boost Asio including synch and assych Supported operating systems are Microsoft Windows (starting from XP) and Unix.

Channels also support some high level abstractions, like Reader and Writer. This templates can be used for read and write strings e.g. std::basic_string with any char type for read and write data into channels. In the same time reader and writer uses - Converters for converting characters from different code pages. I.e. you can read the incoming file/socket/pipe or device which revives Windows 1250 characters for example directly to the UTF-8 or UTF-16[32][LE]/[BE] or any another supported character set. Also you can manipulate character set conversation manually using Converter interface directly. Conversation is based 3-d party libraries - libiconv, MS MLang or IBM ICU. Only one library can be used at time, and you need to build Channels with the selected. Converter - is a facade upon the code page converting library API. Currently gnu libiconv, IBM ICU and Microsoft MLang (COM component part of the Internet Explorer) implementations available.

Flowing you can found supported character set (code page) list:

Single byte

  • ASCII
  • KOI8-R
  • KOI8-RU
  • KOI8-U

ISO

  • ISO-8859-1
  • ISO-8859-2
  • ISO-8859-3
  • ISO-8859-4
  • ISO-8859-5
  • ISO-8859-6
  • ISO-8859-7
  • ISO-8859-8
  • ISO-8859-9

Windows national code pages

  • CP1250
  • CP1251
  • CP1252
  • CP1253
  • CP1254
  • CP1255
  • CP1256
  • CP1257
  • CP1258

Unicode:

  • UTF-8
  • UTF-16LE
  • UTF-16BE
  • UTF-32BE
  • UTF-32LE
  • UTF-7

Licensing

Software is licensed according GNU Lesser General Public License third version (LGPL V3) https://www.gnu.org/licenses/lgpl.html It is free for commercial (only if you link as DLL (Windows) or shared library (Unix [Linux including Android, MacOSX, FreeBSD etc] )) and non commercial usage.

Note

Library uses exceptions and need to be compiled with the C++ exceptions option in case you will use them. Anyway each C++ throw statements are protected with the boost::throw_exception wrapper, so you are able to compile and use library without exceptions support, for example for the mobile or embedded platforms when you need to make application size as small as possible, anyway it is not recommended since you can not handle I/O errors. RTTI is not squared and not used.

Dependencies:

Required

Boost http://www.boost.org/

Can be selected:

  • gnu libiconv - http://www.gnu.org/software/libiconv/ (or any another libiconv implementation) - in case it is used, default for LINUX and for the MinGW windows build. Any another libiconv implementation can be used for MaxOS X for instance. Can be used on Windows and Unix both.
  • IBM ICU - http://site.icu-project.org all character set conversation will be done over the UNICODE, can be used on any platform. This implementation is provided to be compatible with boost Regex. This engine is not recommended such as it conversation over the UNICODE ass additional time and memory fee, when you need to convert an non UNICODE characters to yet another non UNICODE characters.
  • Microsoft Internet Explorer need to be installed in Windows in case of MLang charset conversation engine

Tested OS/compilers:

  • gcc 4.7, 4.8 (Linux and MinGW32 (32 bit only))
  • MS VC++ 10 (64 bit only)

Current issues:

  • Limited build system used CMake. Code::Blocks IDE project files are preferred to create .dll/.so .a/.lib files.
  • No automatic input character set identification.
  • No unit tests, only simple test application.