DataReelDataReelC++ Toolkit Documentation

Example Programs

Every example is one source file and is built and tested with this release.

Contents

Building and Running
Object database
Object database patterns
TLS networking
General support
Plain text diagnostics

Building and Running

The examples are in the examples folder and are built with the library by CMake:

cmake -S . -B cmake-build -DCMAKE_BUILD_TYPE=Release
cmake --build cmake-build -j
cmake-build/examples/db_infohog          # Linux
cmake-build\examples\Release\db_infohog  # Windows

The database examples pause for Enter between steps; give them empty input (< /dev/null or < nul) to run straight through. The TLS servers need a certificate and key; see Certificates for making test ones. tests/run_tests.sh builds everything and runs the examples against each other and against mock mail and FTPS servers.

Object database

examples/database/simple/testprog.cpp

db_simple: gxDatabase basics: create a file, allocate, write, read and delete blocks, file statistics.

examples/database/database/testprog.cpp

db_database: Store and find fixed-size objects in a gxDatabase file.

examples/database/btree/testprog.cpp

db_btree: gxBtree index with a custom key class: insert, find, walk in order, delete.

examples/database/btree_cached/testprog.cpp

db_btree_cached: The same B-tree operations through a BtreeCache.

examples/database/btree_node/testprog.cpp

db_btree_node: Inside a B-tree node: key layout and branches.

examples/database/database_cache/testprog.cpp

db_database_cache: gxDatabaseCache write-back cache over a database file.

examples/database/defrag/testprog.cpp

db_defrag: Free-space reuse and rebuilding (defragmenting) a database file.

examples/database/pod/testprog.cpp

db_pod: POD: a data file with one or several index files opened together.

examples/database/infohog/infohog.cpp

db_infohog: InfoHog object database: records with a key and variable members, add, find, change, delete, list and reopen.

Object database patterns

examples/oodb/typed_objects.cpp

typed_objects: A typed class sent over gxStream, stored in a gxDatabase, exported to plain text and imported back.

examples/oodb/journal_recovery.cpp

journal_recovery: gxdJournal transactions: a writer killed mid-transaction, Recover(), a consistency check and Rollback(). POSIX only.

examples/oodb/day_events.cpp

day_events: One database file per YYYY/MM/DD folder and a time-range query across days.

examples/oodb/vector_basics.cpp

vector_basics: The vector index: float32, float16 and int8 files, exact against graph search (recall), the l2/cosine/ip metrics, tags and filters, update, delete, repair, a rolled back transaction and the format fields.

examples/oodb/vector_records.cpp

vector_records: Records that carry their own vectors (vector members): record and node in one transaction, records read back by address, Verify() with a resolver, the index rebuilt from the records alone.

examples/oodb/vector_days.cpp

vector_days: One vector index per day searched as one through a .vixset manifest: threads, a day range that skips files, an archived day, a live writer attached.

examples/oodb/vector_search_service.cpp

vector_search_service: Vector searches through the database object server (VECTOR_INFO, VECTOR_SEARCH) over mutual TLS, with a day range. Linux and Windows.

examples/oodb/object_replication.cpp

object_replication: gxObjRepl: a primary and a copy, a few commits read back on the copy, then a planned switch (takeover and rejoin) and more commits, with the digests equal on both nodes. Windows and Linux.

examples/oodb/replication_copy.cpp

replication_copy: A database folder copied with robocopy or cp while its writer is stopped, checked with digests, and the copy's indexes rebuilt from its records after a fault. Windows and Linux.

TLS networking

examples/tls/tls_echo_server.cpp

tls_echo_server: TLS server using gxsTLSServer and a ThreadPool. Usage: tls_echo_server port cert.pem key.pem

examples/tls/tls_echo_client.cpp

tls_echo_client: TLS client with certificate checking. Usage: tls_echo_client host port [--ca ca.pem] [--insecure]

examples/tls/https_get.cpp

https_get: Fetch a URL or download a file with gxsHTTPClient. Usage: https_get url [file] [--ca ca.pem]

examples/tls/https_server.cpp

https_server: Small HTTPS file server built on gxsHTTPReadRequest() and gxsHTTPWriteResponse().

examples/tls/https_check.cpp

https_check: Check a list of web sites over TLS: status, time (fastest/median/slowest with --count), size, redirects, and the response headers with --headers (7.4). Usage: https_check [--head] [--headers] [--count N] [--list file] [--ca ca.pem] url ...

examples/tls/smtp_send.cpp

smtp_send: Send mail over implicit TLS or STARTTLS.

examples/tls/pop3_list.cpp

pop3_list: List and read a POP3 mailbox over TLS.

examples/tls/imap_fetch.cpp

imap_fetch: Read an IMAP mailbox over TLS (or STARTTLS, or plain text for a local server): search, list newest first, save each message once to a spool folder (7.4).

examples/tls/ftps_client.cpp

ftps_client: List, download and upload with FTPS.

examples/tls/dir_upload.cpp

dir_upload: gxsFTPClient: watch a folder and upload each settled file by FTPS (as NAME.part, renamed, size-checked), then delete it or move it to a done folder. The password comes from DR_FTP_PASSWORD or a mode-600 file, never the command line. Usage: dir_upload --dir DIR --host HOST [--port N] --user USER [--password-file FILE] [--ca FILE] [--implicit] [--remote-dir DIR] [--pattern GLOB] [--settle S] [--interval S] [--done DIR] [--once] [--log FILE]

examples/tls/stream_server.cpp

stream_server: gxStream server that stores client blocks in a gxDatabase file.

examples/tls/stream_client.cpp

stream_client: gxStream client that stores and reads back blocks over TLS.

General support

examples/general/config_file.cpp

config_file: gxConfig: write, read and change a configuration file.

examples/general/logfile.cpp

logfile: LogFile shared by several threads.

examples/general/thread_pool.cpp

thread_pool: ThreadPool tasks, results and exceptions.

examples/general/trading_sessions.cpp

trading_sessions: CDate and systime.h: US market sessions, holidays, trading days.

examples/general/string_utils.cpp

string_utils: strutil.h, base 64 and CRC-32, each checked against a known answer.

examples/general/service_example.cpp

service_example: gxProcessLock and the frame of a long-running program: one instance, work every few seconds, a clean stop on SIGTERM, Ctrl+C, a stop file or the Windows service manager; --daemon on POSIX, --install/--service/--uninstall on Windows (demand start, LocalService). Exit 2 if another instance runs. Usage: service_example [--name NAME] --lock FILE --log FILE [--stop-file FILE] [--interval S] [--run-for S] [--daemon]; service_example --service ... (started by the service manager); service_example --install ... / --uninstall [--name NAME] (as administrator).

examples/general/csv_merge.cpp

csv_merge: gxCSVReader and gxCSVWriter: merge two spreadsheets exported as CSV on a key column. Usage: csv_merge [--inner] [--delimiter C] KEY A.csv B.csv [OUT.csv]

Plain text diagnostics

examples/diagnostics/ping.cpp

ping: ICMP and ICMPv6 echo. Usage: ping host [count] [-4|-6]

examples/diagnostics/telnet_client.cpp

telnet_client: Telnet login and command (plain text; trusted networks only).

examples/diagnostics/serial_read.cpp

serial_read: gxSerialComm: read a serial port (Linux /dev/ttyS0, /dev/ttyUSB0 or a pty; Windows COM1...) to standard output or a capture file flushed after every read. Usage: serial_read DEVICE [--baud N] [--parity N|E|O] [--bits 7|8] [--stop 1|2] [--flow none|hard|soft] [--out FILE] [--hex] [--seconds N] [--bytes N] [--quiet]. Windows: COM10 and up are opened as \\.\COMn, reads end within 100 ms (the time limit and Ctrl+C are seen at once), standard output is binary; a serial line has no hangup there, so the read runs to Ctrl+C, --seconds or --bytes.

examples/diagnostics/udp_broadcast.cpp

udp_broadcast: Send and receive UDP broadcast datagrams with gxSocket (plain text; trusted local networks only) (7.4).

examples/diagnostics/udp_multicast.cpp

udp_multicast: Send and receive IPv4 or IPv6 multicast datagrams, join a group (plain text; trusted local networks only) (7.4).