panthema (page 7 of 1 2 3 4 5 6 7 8 9)
Small drawing of a parse tree

Published STX Expression Parser Framework Version 0.7

Posted on 2007-07-17 17:10 by Timo Bingmann at Permlink with 0 Comments. Tags: c++ stx-exparser c++

Released the first version 0.7 of the STX Expression Parser C++ Framework package. The library is licensed under the GNU Lesser General Public License (LGPL) (2.1 or later).

The STX Expression Parser provides a C++ framework, which can process user-specified expression strings containing program-specific variables. It can be integrated into applications to allow user-customized data selection and filtering. The expresssion strings are intuitive SQL-like WHERE-clauses and can contain arbitrarily complex arithmetic. At the same time the expression processing time is guaranteed to be fast enough to safely iterate over larger data sets.

The expression parser can process arbitrarily complex arithmetic expressions like those seen below. To access application-defined data, functions and variables may be included in the expression. An expression can be used as a boolean filter by using comparison and logic operators.

For more information see the STX Expression Parser web page.

Most impressive are the interactive online CGI parser demo and the online CSV file filter.


Screenshot der Webpage www.bundestrojaner.net

Spaß-Webpage - Bundestrojaner.net

Posted on 2007-06-06 09:38 by Timo Bingmann at Permlink with 0 Comments. Tags: fun

Online-Durchsuchungen sind zur Zeit wieder auf der politischen Tagesordnung, denn "Das Internet ist das entscheidende Kommunikationsmittel des internationalen Terrorismus [...]" (Zitat vom BKA-Chef auf tagesschau.de).

Windows wird aber nicht in Deutschland entwickelt und daher kann das BKA nur schwer bei Microsoft ein eigenes Backdoor beantragen. Das (angeblich) bereits vorhandene Backdoor der NSA kann wohl rechtsstaatlich nicht verwendet werden.

Daher ist es notwendig ein "Bundestrojaner" auf den zu untersuchenden Rechnern zu installieren. Dieses (Schad-)Programm soll dann vom BKA ferngesteuert die Festplatten durchsuchen.

Auf www.bundestrojaner.net gibt es bereits eine Betaversion zum Ausprobieren. Nein, nicht wirklich: es ist eine mit vielen politischen Sprüchen aufgemachte Satire-Webpage. Durch Appelle an unseren Patriotismus und Glauben an rechtsstaatlichen Grundsätze wird man aufgefordert den "Bundestrojaner" herunterzuladen und sich freiwillig durchsuchen zu lassen. Hier einige Zitate:

Seien Sie ein guter Demokrat und unterstützen Sie die Bundesregierung beim Kampf gegen den Terror und die Bürgerrechte.

Sie haben nichts zu verbergen? Dann sollten Sie umgehend den Bundestrojaner installieren!

Leider ist das downloadbare Programm nicht sehr ausgereift: es zeigt (anscheinend) nur eine kurze Slideshow-Sequenz und bittet den Benutzer um "Geduld, Ihre Daten werden übertragen".

Außerdem hat der CCC am 1. April diesen Jahres bereits den "Bundestrojaner" ausgemacht: in der Elster-Software des Finanzamts.


C++ Code Snippet - In-Place and String-Copy Uppercase/Lowercase Conversion of STL Strings

Posted on 2007-06-02 13:22 by Timo Bingmann at Permlink with 2 Comments. Tags: c++ code-snippet

This post completes the small C++ function collection of simple STL string manipulations. The following code snippet shows simple locale-unware uppercase and lowercase conversion functions using tolower and toupper. Nothing revolutionary; I'm just misusing this weblog as a code-paste dump for reuseable code.

Sometimes it is better to have a case-insensitive string class. More about ci_string can be found at Guru of the Week (GotW) #29: Case-Insensitive Strings.

#include <string>
#include <cctype>

// functionals for std::transform with correct signature
static inline char string_toupper_functional(char c)
{
    return std::toupper(c);
}

static inline char string_tolower_functional(char c)
{
    return std::tolower(c);
}

static inline void string_upper_inplace(std::string &str)
{
    std::transform(str.begin(), str.end(), str.begin(), string_toupper_functional);
}

static inline void string_lower_inplace(std::string &str)
{
    std::transform(str.begin(), str.end(), str.begin(), string_tolower_functional);
}

static inline std::string string_upper(const std::string &str)
{
    std::string strcopy(str.size(), 0);
    std::transform(str.begin(), str.end(), strcopy.begin(), string_toupper_functional);
    return strcopy;
}

static inline std::string string_lower(const std::string &str)
{
    std::string strcopy(str.size(), 0);
    std::transform(str.begin(), str.end(), strcopy.begin(), string_tolower_functional);
    return strcopy;
}
This blog entry continues on the next page ...

C++ Code Snippet - In-Place and String-Copy Space Trimming of STL Strings

Posted on 2007-05-30 17:28 by Timo Bingmann at Permlink with 1 Comments. Tags: c++ code-snippet

Yesterday I once again stumbled upon whitespace trimming of STL strings: a check was required if the given user input is empty. Where "empty" also means some user-given string containing only spaces. After one hour of unproductive searching for something as simple as a space trimming function, I decided to put the resulting code here for future reference.

The following code snippet contains two versions of the function: in-place trimming and string-copy trimming. I prefer the copy-trimming function because they allow a more functional programming style. The functions only trim spaces, but can be modified by replacing each ' ' with something like " \n\r\t".

#include <string>

static inline void string_trim_left_inplace(std::string &str)
{
    str.erase(0, str.find_first_not_of(' '));
}

static inline void string_trim_right_inplace(std::string &str)
{
    str.erase(str.find_last_not_of(' ') + 1, std::string::npos);
}

static inline std::string string_trim_left(const std::string &str)
{
    std::string::size_type pos = str.find_first_not_of(' ');
    if (pos == std::string::npos) return std::string();

    return str.substr(pos, std::string::npos);
}

static inline std::string string_trim_right(const std::string &str)
{
    std::string::size_type pos = str.find_last_not_of(' ');
    if (pos == std::string::npos) return std::string();

    return str.substr(0, pos + 1);
}

static inline std::string string_trim(const std::string& str)
{
    std::string::size_type pos1 = str.find_first_not_of(' ');
    if (pos1 == std::string::npos) return std::string();

    std::string::size_type pos2 = str.find_last_not_of(' ');
    if (pos2 == std::string::npos) return std::string();

    return str.substr(pos1 == std::string::npos ? 0 : pos1,
                      pos2 == std::string::npos ? (str.length() - 1) : (pos2 - pos1 + 1));
}

static inline void string_trim_inplace(std::string& str)
{
    std::string::size_type pos = str.find_last_not_of(' ');
    if(pos != std::string::npos) {
        str.erase(pos + 1);
        pos = str.find_first_not_of(' ');
        if(pos != std::string::npos) str.erase(0, pos);
    }
    else
        str.erase(str.begin(), str.end());
}
This blog entry continues on the next page ...

Screenshot of the wxBTreeDemo v0.8

Updated STX B+ Tree to 0.8 which now includes wxBTreeDemo

Posted on 2007-05-13 19:48 by Timo Bingmann at Permlink with 0 Comments. Tags: c++ stx-btree

Released an updated version 0.8 of the STX B+ Tree C++ Template Classes package. The update fixes a few segmentation faults with empty trees without root node.

This new release includes the demonstration program wxBTreeDemo. This program draws illustrations of the B+ trees constructed by the STX B+ Tree template classes. It allows the user to selected different types of B+ tree instantiations: integer or string keys and different slot numbers. The user may insert and erase key/data pairs from the tree and run different search operations. The demo program uses the cross-platform wxWidgets toolkit and can be compiled on Linux, Windows and MacOSX.

The source code package including the wxBTreeDemo source is available for download from this webpage.

Some compiled binaries of wxBTreeDemo for Win32 and Linux are available on the demo download page.

As before, the only slightly changed main B+ tree implementation can be found in doxygen stx/btree.h or with plain text comments stx/btree.h.


lcov: A Good HTML Generator for gcov Results

Posted on 2007-05-08 11:08 by Timo Bingmann at Permlink with 0 Comments. Tags: c++ linux

Writing test cases is a good way to prevent and detect problems or bugs in source code. They improve understanding of the difficult parts by requiring deeper thought into how to test of those areas. By rerunning the same test sequences one can assure that the code still produces the same results even after making significant changes. cppunit provides a C++ test framework which is sort of over-bloated. However reduced to a set of reusable template files the framework gets quite handy.

To measure how much of the code is tested, gcov provides a way to determine which lines are executed during a test suite run. Note that this simple line-is-touched metric is only one aspect of how well a piece of code is tested. However gcov's results are printed in text mode and it cannot merge the results from multiple coverage files, so multi-file test suites cannot be measured as a whole.

Yesterday I finally found a good open-source Linux tool to get correct coverage results: lcov. It was designed to measure coverage in the Linux kernel, but works very well on user-space programs as well. lcov builds on gcov's data files and generates HTML report files. It even highlights the untested source code lines.

I uploaded the test coverage results of the STX B+ Tree test suite. It shows 89.2% coverage of the main, most difficult header file implementing the insert and erase algorithms.


Small drawing of a B+ tree

Published STX B+ Tree C++ Template Classes Version 0.7

Posted on 2007-04-27 15:02 by Timo Bingmann at Permlink with 0 Comments. Tags: stx-btree c++

Released the first version 0.7 of the STX B+ Tree C++ Template Classes package. The template classes are licensed under the LGPL.

The STX B+ Tree package is a set of C++ template classes implementing a B+ tree key/data container in main memory. The classes are designed as drop-in replacements of the STL containers set, map, multiset and multimap and follow their interfaces very closely. By packing multiple value pairs into each node of the tree the B+ tree reduces heap fragmentation and utilizes cache-line effects better than the standard red-black binary tree. The tree algorithms are based on the implementation in Cormen, Leiserson and Rivest's Introduction into Algorithms, Jan Jannink's paper and other algorithm resources. The classes contain extensive assertion and verification mechanisms to ensure the implementation's correctness by testing the tree invariants.

The main B+ tree implementation can be found in doxygen stx/btree.h or with plain text comments stx/btree.h.

The source code package is available for download from this webpage.

The classes are documented extensively using doxygen. The generated HTML documentation can be browsed online or downloaded.

Special interest was put into performing a speed comparison test between the standard red-black tree and the new B+ tree implementation. The speed test results are interesting and show the B+ tree to be significantly faster for trees containing more than 16,000 items.


Thumbnail der fertig aufgestellten Duetta

Lautsprecher-Odyssee und Duetta Selbstbau

Posted on 2007-04-18 19:00 by Timo Bingmann at Permlink with 23 Comments. Tags: hifi selbstbau

Zusammenfassung

In diesem Blog-Eintrag beschreibe ich meine drei-monatige, intensive Suche nach neuen Lautsprechern. Der Eintrag enthält viele persönliche Meinungen und soll insbesondere zu der Zeit angestellte Überlegungen und Vermutungen erfassen. Dieser Bericht soll sein, was ich in damals vergeblich im Internet gesucht habe: eine detaillierte Entwicklung von völlig unerfahrenen Musikhörer zum Boxen-Selbstbauer. Der ganze Bericht ist natürlich subjektiv, manch Suchender wird völlig anderer Meinung sein.

Die Suche startet im letzten Dezember bei den einschlägigen Elektronikmärkten. Mit den bekannten Test-Magazinen bewaffnet, hätte ich dort um Haaresbreite ein Paar Lautsprecher gekauft. Durch Zufall kamen wir dann zu Orbid-Sound und durften dort begeistert alles probe hören und sogar zwei Paar Lautsprecher ausleihen. Am Ende landete ich jedoch beim HiFi-Selbstbau. Nach langem Vergleich der verschiedenen im Internet verfügbaren Bausätze entschied ich mich zu Udo Wohlgemuth nach Bochum zu fahren und dort zwei Duetta-Bausätze zu kaufen.

Die zehntägige Bastelarbeit an dem Paar Duettas hat mir sehr viel Spaß gemacht. Hier werden die einzelnen Schritte nur kurz beschrieben aber durch viele Photos illustriert. Besonderes Augenmerk legte ich auf die Schwierigkeiten, welche ich damals als totaler Selbstbau-Neuling überwinden musste. Der Blog-Eintrag endet mit einer differenzierten Beschreibung des Klangs meiner Duettas.

This blog entry continues on the next page ...

Thumbnail of the current HMTG Webpage

HMTG Web Page Redesign

Posted on 2007-04-14 20:24 by Timo Bingmann at Permlink with 0 Comments. Tags: webdesign hartmetall

Finished redesigning the web site and e-catalog of the Hartmetall-Gesellschaft. This is actually the fifth version of the homepage. It is now based on Template::Toolkit technology with the old PostgreSQL database back-end. The style was adapted to todays modern web designs.

On this occasion I have collected and organized versions of older home pages. They show a stream of development which the page has taken:

This blog entry continues on the next page ...

C++ Code Snippet - Compressing STL Strings with zlib

Posted on 2007-03-28 18:23 by Timo Bingmann at Permlink with 11 Comments. Tags: c++ code-snippet frontpage

The zlib library can be found on virtually every computer. It is THE general-purpose lossless patent-free compression library.

This small C++ code snippet features a pair of functions which use this ubiquitous library to compress ordinary STL strings. There are many uses for this code snippet, like compressing string data stored in a database or binary data transfered over a network. Keep in mind that the compressed string data is binary, so the string's c_str() representation must be avoided.

To compile the following small program use "gcc testzlib.cc -o testzlib -lz" where testzlib.cc is the code.

// Copyright 2007 Timo Bingmann <tb@panthema.net>
// Distributed under the Boost Software License, Version 1.0.
// (See http://www.boost.org/LICENSE_1_0.txt)

#include <string>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <sstream>

#include <zlib.h>

/** Compress a STL string using zlib with given compression level and return
  * the binary data. */
std::string compress_string(const std::string& str,
                            int compressionlevel = Z_BEST_COMPRESSION)
{
    z_stream zs;                        // z_stream is zlib's control structure
    memset(&zs, 0, sizeof(zs));

    if (deflateInit(&zs, compressionlevel) != Z_OK)
        throw(std::runtime_error("deflateInit failed while compressing."));

    zs.next_in = (Bytef*)str.data();
    zs.avail_in = str.size();           // set the z_stream's input

    int ret;
    char outbuffer[32768];
    std::string outstring;

    // retrieve the compressed bytes blockwise
    do {
        zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
        zs.avail_out = sizeof(outbuffer);

        ret = deflate(&zs, Z_FINISH);

        if (outstring.size() < zs.total_out) {
            // append the block to the output string
            outstring.append(outbuffer,
                             zs.total_out - outstring.size());
        }
    } while (ret == Z_OK);

    deflateEnd(&zs);

    if (ret != Z_STREAM_END) {          // an error occurred that was not EOF
        std::ostringstream oss;
        oss << "Exception during zlib compression: (" << ret << ") " << zs.msg;
        throw(std::runtime_error(oss.str()));
    }

    return outstring;
}

/** Decompress an STL string using zlib and return the original data. */
std::string decompress_string(const std::string& str)
{
    z_stream zs;                        // z_stream is zlib's control structure
    memset(&zs, 0, sizeof(zs));

    if (inflateInit(&zs) != Z_OK)
        throw(std::runtime_error("inflateInit failed while decompressing."));

    zs.next_in = (Bytef*)str.data();
    zs.avail_in = str.size();

    int ret;
    char outbuffer[32768];
    std::string outstring;

    // get the decompressed bytes blockwise using repeated calls to inflate
    do {
        zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
        zs.avail_out = sizeof(outbuffer);

        ret = inflate(&zs, 0);

        if (outstring.size() < zs.total_out) {
            outstring.append(outbuffer,
                             zs.total_out - outstring.size());
        }

    } while (ret == Z_OK);

    inflateEnd(&zs);

    if (ret != Z_STREAM_END) {          // an error occurred that was not EOF
        std::ostringstream oss;
        oss << "Exception during zlib decompression: (" << ret << ") "
            << zs.msg;
        throw(std::runtime_error(oss.str()));
    }

    return outstring;
}

/** Small dumb tool (de)compressing cin to cout. It holds all input in memory,
  * so don't use it for huge files. */
int main(int argc, char* argv[])
{
    std::string allinput;

    while (std::cin.good())     // read all input from cin
    {
        char inbuffer[32768];
        std::cin.read(inbuffer, sizeof(inbuffer));
        allinput.append(inbuffer, std::cin.gcount());
    }

    if (argc >= 2 && strcmp(argv[1], "-d") == 0)
    {
        std::string cstr = decompress_string( allinput );

        std::cerr << "Inflated data: "
                  << allinput.size() << " -> " << cstr.size()
                  << " (" << std::setprecision(1) << std::fixed
                  << ( ((float)cstr.size() / (float)allinput.size() - 1.0) * 100.0 )
                  << "% increase).\n";

        std::cout << cstr;
    }
    else
    {
        std::string cstr = compress_string( allinput );

        std::cerr << "Deflated data: "
                  << allinput.size() << " -> " << cstr.size()
                  << " (" << std::setprecision(1) << std::fixed
                  << ( (1.0 - (float)cstr.size() / (float)allinput.size()) * 100.0)
                  << "% saved).\n";

        std::cout << cstr;
    }
}

Show Page: 1 2 3 4 5 6 7 8 9 Next >
RSS 2.0 Weblog Feed Atom 1.0 Weblog Feed Valid XHTML 1.1 Valid CSS (2.1)
Copyright 2005-2017 Timo Bingmann - Impressum