Posted on 2009-11-10 22:30 by Timo at Permlink with Comments. Tags: c++
Published a small, but very useful console tool to update md5sum or shasum digest files. It will read existing md5sum.txt files and add new files to it without rereading the whole directory tree.
This makes digup very useful to update and verify incremental archives like chronological data storages or music collections, which are nowadays commonly stored and backuped on hard disks. Using a full file digest scan even slowly creeping bad blocks on old hard disks can be detected. By using a crontab entry, this check can be performed unattended and routinely.
For more information, the source code and binaries for various platforms see the digup web page.
Published Flex Bison C++ Example 0.1.4Posted on 2009-09-05 10:40 by Timo at Permlink with Comments. Tags: flex-bison-cpp-example c++ code-example
Released a minor updated source code version for Flex Bison C++ Example. The example source code is released into the public domain or, at your option, under the Do What The Fuck You Want To Public License (WTFPL).
This minor bugfix release fixes up two simple compilation issues with the newest bison version 2.4.1.
For more information and the download package see the Flex Bison C++ Example web page.
Posted on 2009-08-08 11:25 by Timo at Permlink with Comments. Tags: cryptote c++ cryptography
After almost one year of personally testing the program, I decided to publicly released the first version of CryptoTE v0.5.390. One year in the making, CryptoTE is a very useful little text-editor with integrated cryptography. The name stands for CRYPTOgraphy Text Editor and it transparently encrypts text files storing them into secure containers. The program incorporates the popular editing component Scintilla and makes heavy use of wxWidgets.
For more information, the source code and binaries for various platforms see the CryptoTE web page.
Published Flex Bison C++ Example 0.1.3Posted on 2008-10-23 11:25 by Timo at Permlink with Comments. Tags: flex-bison-cpp-example c++ code-example
Released yet another updated source code package for Flex Bison C++ Example. The example source code is released into the public domain or, at your option, under the Do What The Fuck You Want To Public License (WTFPL).
This bugfix release solves a subtle, severe bug, which rendered the template code useless. Even the example exprtext program segfaulted with any expression.
Corrected a very subtle bug with the newly introduced virtual yywrap() function in the FlexLexer class. Depending on how the header was included, the class contained the virtual yywrap() function or not. These differing class declarations lead to very strange NULL pointer exceptions, because the different compiled objects assume different class memory layouts. Ultimately the exprtest program always segfaulted.
For more information and the download package see the Flex Bison C++ Example web page.
Posted on 2008-09-07 18:31 by Timo at Permlink with Comments. Tags: c++ stx-btree
Released another updated version 0.8.3 of the STX B+ Tree C++ Template Classes package. The updated release fixes up issues with the root node == NULL when the tree is initially empty.
Fixed crash when running verify() on an empty btree object. Now the root node is freed when the last item is removed. Also fixed crash when attempting to copy an empty btree or when trying to remove a non-existing item from an empty btree.
Also enhancing the speedtest to test the hash table container implementation from __gnu_cxx. Extending tests by another set of runs measuring only the find/lookup functions. See the speed results web page for more information.
The updated source code package 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 updated main B+ tree implementation can be found in doxygen stx/btree.h or with plain text comments stx/btree.h.
Posted on 2008-09-01 22:30 by Timo at Permlink with Comments. Tags: c++ code-snippet
Yesterday I was tasked to analyzed an inner function of a reasonably complex software package. The inner function was called thousands of times from many different parts of the program, a simple counter print-out showed that. However I was interested in which execution paths reach this inner function and how often the different parts access the function.
My straight-forward idea was to dump a stack backtrace each time the inner function is called, similar to the one printed by a debugger. However I needed some code snippet to dump the stack backtrace programmatically, without using gdb to halt the program each time.
Stack backtraces can be saved with backtrace(3), resolved into symbolic names using backtrace_symbols(3) and printed using backtrace_symbols_fd(3). These functions are well documented and fairly easy to use.
However I was debugging a C++ program, which made heavy use of templates and classes. C++ symbols names (including namespace, class and parameters) are mangled by the compiler into plain text symbols: e.g. the function N::A<int>::B::func(int) becomes the symbol _ZN1N1AIiE1B4funcEi. This makes the standard backtrace output very unreadable for C++ programs.
To demangle these strings the GNU libstdc++ library (integrated into the GNU Compiler Collection) provides a function called __cxa_demangle(). Combined with backtrace(3) a pretty stack backtrace can be outputted. The demangling function only works for programs compiled with g++.
The following header file contains a function print_stacktrace(), which uses backtrace(3), backtrace_symbols(3) and __cxa_demangle() to print a readable C++ stack backtrace.
Posted on 2008-08-13 16:48 by Timo at Permlink with Comments. Tags: c++ stx-btree
Released an updated version 0.8.2 of the STX B+ Tree C++ Template Classes package. The updated release fixes up all issues with iterators and one harmless bad-memory access.
The reverse_iterator classes of the B+ tree were completely reworked. Now they are real implementations and do not use STL magic. Both reverse_iterator and const_reverse_iterator should work as expected now. Added two large test cases for iterators. Enabled public default-constructors on iterators.
Also fixed a memory access bug which happens in erase_one_descend(): leaf->slotkey[leaf->slotuse - 1] if leaf-slotuse == 0. This doesn't have any other bad effect, because the case only occurs when leaf == root and then the resulting btree_update_lastkey message is never really processed. However it still is a bad-memory access.
The updated 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 updated main B+ tree implementation can be found in doxygen stx/btree.h or with plain text comments stx/btree.h.
Published Flex Bison C++ Example 0.1.2Posted on 2008-08-03 14:26 by Timo at Permlink with Comments. Tags: flex-bison-cpp-example c++ code-example
Released an updated source code package for Flex Bison C++ Example. The example source code is released into the public domain or, at your option, under the Do What The Fuck You Want To Public License (WTFPL).
This bugfix release solves two problems there were reported to me via e-mail:
The first problem were compilation errors that occured when no %union directive is used in the grammar: in this case the include headers order is changed around by bison and thereby breaks compilation. This was fixed by never including parser.h directly, but always using scanner.h.
And the second issue was raised because new versions of flex were released after years of stagnation. The new flex version 2.5.35 adds a virtual function yywrap() to the yyFlexLexer class. This function is automatically defined in any lexer source file generated by flex. However because I copied FlexLexer.h from an older flex distribution, the function definition throughs a "no yywrap() member function" compiler error. Updating the FlexLexer.h with a conditional declaration of yywrap() hopefully did the trick and now works on all versions. Usually this file should be taken from /usr/include and not from the package. However that will break compilation if flex is not installed, and a self-sufficient compilation package was a primary goal of the example.
For more information and the download package see the Flex Bison C++ Example web page.
Posted on 2008-01-25 15:48 by Timo at Permlink with Comments. Tags: c++ stx-btree
Released a bugfix version 0.8.1 of the STX B+ Tree C++ Template Classes package. The bug fixed is a possibly illegal memory access during find() function.
I received a new test case via email in which valgrind detected an uninitialized memory access. By tracing it, I soon found that it happens during any find(key) call with a key that is larger than any item contained in the tree. During the find() function find_lower() is called on a leaf node and returns the slot number with the smallest or equal key. However if the queried key is larger than all keys in a leaf node or in the whole tree, find_lower() returns a slot number past the last valid key slot. Comparison of this invalid slot with the queried key then yields an uninitialized memory error in valgrind.
The updated 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 updated main B+ tree implementation can be found in doxygen stx/btree.h or with plain text comments stx/btree.h.
Published Flex Bison C++ Example 0.1Posted on 2007-08-20 11:53 by Timo at Permlink with Comments. Tags: flex-bison-cpp-example c++ code-example
Released example source code package Flex Bison C++ Example. The example source code is released into the public domain or, at your option, under the Do What The Fuck You Want To Public License (WTFPL).
This example shows how to use both Flex and Bison in C++ mode. This way both lexer and parser code and data is encapsulated into classes. Thus the lexer and parser are fully re-entrant, because all state variables are contained in the class objects. Furthermore multiple different lexer-parser pairs can easily be linked into one binary, because they have different class names and/or are located in a different namespace.
Why Use These Old Tools? Well, they are here to stay and they work well. But most important, the code generated by Flex and Bison requires no compile-time dependencies, because they generate fully autonomous source code. So far I have not found any modern parser generator which outputs independent code. It is even possible to compile the generated source on Windows with Visual C++ 2005.
For more information and the download package see the Flex Bison C++ Example web page.
Posted on 2007-07-17 17:10 by Timo at Permlink with 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.
6 + 3 * 12(a - 28) * (int)(e + 0.4 * 2.5 / (PI() - EXP(-0.644) * 4))6 * 9 == 42a >= 5 OR (42 <= field2 AND field2 <= 48) || NOT(got == "yes")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.
Posted on 2007-06-02 13:22 by Timo at Permlink with 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.
Posted on 2007-05-30 17:28 by Timo at Permlink with 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".
Posted on 2007-05-13 19:48 by Timo at Permlink with 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.
Posted on 2007-05-08 11:08 by Timo at Permlink with 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.
Posted on 2007-04-27 15:02 by Timo at Permlink with 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.
Posted on 2007-03-28 18:23 by Timo at Permlink with Comments. Tags: c++ code-snippet
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.
Posted on 2007-03-14 14:43 by Timo at Permlink with Comments. Tags: c++ code-snippet
The Boost library is a collection of very useful C++ (template) libraries. However it's documentation is very complex and using the library straight-forward usually results in g++ scrolling endless pages of template instantiation errors.
This code snippet shows by example how to use the Boost.Regex library. It compiles and executes regular expressions on strings. Some test I ran showed that it is not as fast as pcre, however Boost.Regex it is easier and more elegant to use in C++ programs. The program must be linked with -lboost_regex.
Posted on 2007-03-01 14:47 by Timo at Permlink with Comments. Tags: c++ code-snippet
How to get a custom class to work with std::cout << obj; ? I for my part always forget the exact prototype of the required operator<<. Here is an minimal working example to copy code from:
Posted on 2006-10-10 12:56 by Timo at Permlink with Comments. Tags: qtsqlview c++
Released the first version 0.8.0 of QtSqlView under the GPL.
QtSqlView is a simple and easy to use SQL database browser written in Qt 4.x using the excellent QtSql components. Using QtSql drivers it can natively connect to MySQL, PostgreSQL and SQLite databases. Furthermore other database systems may be accessed using their ODBC drivers. QtSqlView is released under the GNU General Public License: source code and win32 binary may be downloaded here.
This short program was initially written for a set of windows users, who need to access and edit a PostgreSQL database. All this is possible with M$ Access and ODBC, but the configuration of PostgreSQL's ODBC driver and the ODBC DSN is far too complicated for the average database editor. Thus problem-free access of open-source databases was top priority for QtSqlView.
QtSqlView boasts the following features:
You may download the source code for Linux/OSX or a setup package for Windows.
More screenshots are available as well.
Posted on 2006-09-14 09:26 by Timo at Permlink with Comments. Tags: sdios06 university c++
As promised the source code to SDIOS06 was released under the GPL.
SDIOS06 is a toy operating system developed during the practical course SDI (System Design and Implementation) at the Systems Architecture Group of the University of Karlsruhe. It was designed and written by Timo Bingmann, Matthias Braun, Torsten Geiger and Andreas Mähler. Two games were ported to a custom SDL implementation using the VMware "hard"-ware: SDLjump and SuperTux. For more information and screenshots see my blog entry 20060727-SDI-Demo.
The source code archive was published on the L4Ka.org page: http://www.l4ka.org/projects/SDIOS06/
A local copy of the source archive (7.4 MB) is available as well. The README file contains a great deal of information about SDIOS06's design and modules. The complete source code can be browsed on the web.
To make demonstration as easy as possible a ready-to-run binary vmware image (3.8 MB) can be downloaded. The image contains SDIOS06 installed on a virtual vmware disk image. The VMware image can be run using the free VMware Player.
sdlfractal 0.1Posted on 2006-08-09 21:33 by Timo at Permlink with Comments. Tags: sdlfractal c++
Sdlfractal is a port of a simple little fractal generator which I wrote some five years ago. It is not supposed to replace wonderful tools like xfractint so it is very simple and not very fast. The main goal of this project was to learn SDL and it turned out that fltk was also required. The main construction is an SDL surface extended by a canvas class which simulates a high-resolution coordinate system. On this coordinate system the fractals can be drawn.
To control fractal parameters the generator displays a second window using the fltk engine. From this dialog the currently displayed fractal and it's parameters can be changed. This requires a dual engine event loop in the program.
By dragging the mouse on the drawing canvas you can zoom into all fractals. If fractal drawing takes too long (and nothing is shown), then just click the canvas and the generator will stop.
The fractal generator can also save high-resolution PNG files. The following images are some examples created by the fractal generator.
The source code to sdlfractal 0.1 can be downloaded in a tar.bz2 archive (121 KB). It is also browsable on the web.
Sdlfractal was designed to the portable to Win32 using SDL and fltk compiled with MinGW. A compiled version which should run out of the box on most windows. Download the zip archive (267 KB) containing the executable.
MD5sums of the source and binary archives:
538da60a5ef2d427fbb901d6080e631e sdlfractal-0.1.tar.bz2
5bab1ccb93e170f5c42d995a6761ca7a sdlfractal-0.1-win32.zip
![]() | This section of the mandelbrot fractal is so beautiful that it is my current wallpaper. It can be downloaded at 800x600 (242 KB), 1024x768 (372 KB) or 1280x960 (552 KB). |
Posted on 2006-06-20 17:31 by Timo at Permlink with Comments. Tags: compsci study thesis university c++
Heute habe ich meine Studienarbeit "Visualisierung sehr großer Graphen" am Institut für Theoretische Informatik fertig gestellt und abgegeben. Die Studienarbeit ist eine 3-4 monatige wissenschaftliche Arbeit und dient als Vorbereitung auf die Diplomarbeit.
Die Studienarbeit kann zum Durchlesen als PDF (2,4 MB) herunter geladen werden. Auf diesen Abschnitt folgenden die deutsche und englische Zusammenfassung der Arbeit. Weiter gibt es eine Version zum Ausdrucken (PDF 15,3 MB) mit einer hochauflösenden Vektorgraphik im Anhang.
In dieser Studienarbeit wird untersucht, mit welchen Methoden sehr große Graphen wie ein Straßennetzwerk von Europa effizient und komfortabel visualisiert werden können. Als Ausarbeitung entsteht ein C++ Rahmenwerk für die Datenhaltung eines Graphen mit Attributen und ein Java Applet, das mit dem Datenhaltungs-Server mittels CORBA kommuniziert. Das Rahmenwerk kann leicht in bestehende Graphanwendungen integriert werden, um deren Algorithmen zu animieren.
Als Basis-Graphstruktur wird ein Adjazenz-Array verwendet und um Strukturen erweitert, die zu jedem Knoten und jeder Kante beliebig viele Attributwerte speichern. Zwei der Knotenattribute werden als Zeichenkoordinaten verwendet. Der Grundgraph und die Datenhaltung der Attributwerte wird auf möglichst kompakte Art und Weise gelöst. Graphanwendungen können eine Liste von temporären Änderungen erzeugen, die mit dem großen globalen Graphen zusammengeführt werden können. Um das Vorgehen der Graph-Algorithmen zu visualisieren, werden deren Funktionsaufrufe in einer Änderungsfolge kodiert, welche als Animation zum Java Client übertragen wird.
Um die Geschwindigkeit einer Ausschnittsanfrage zu erhöhen, wird die mehrdimensionale Indexstruktur R-Tree verwendet. Diese ermöglicht Anfragezeiten, die linear zur Anzahl der zurückgelieferten Kanten und unabhängig vom gewählten Ausschnitt sind. Es können komplexe Filterausdrücke aus Vergleichsbedingungen mit boolschen und arithmetische Operatoren verwendet werden, um die angezeigten Kanten in einem Visualisierungsauschnitt einzuschränken und so komfortabel bestimmte Aspekte der Anwendungs-Algorithmen zu untersuchen oder hervorzuheben.
Als Referenzanwendung wird das Rahmenwerk von der am Institut für Theoretische Informatik in Karlsruhe entwickelten Routenplanungsanwendung zur Visualisiserung mittels Web Applet verwendet.
This study thesis investigates and implements methods used to efficiently visualize very large graphs like a street network of Europe. A C++ server framework is designed, which implements a data management library for graphs with attributes. A Java applet communicates with the data server via CORBA and draws sections of the graph. The graph data management library can easily be integrated into existing graph application to visual and animate calculations.
The data management library uses the adjacency array structure for representing the base graph. It is extended by similar data structures to hold an arbitrary number of attributes for each vertex and edge. The data structures are optimized towards highest storage efficiency. To modify the static global graph an application may construct a list of changes, which are efficiently merged into permanent data storage. To visualize the workings of an algorithm its function call sequence can be recorded into a list of graph changes. This change time line can be transfered to the Java client and displayed as an animation.
To accelerate access to arbitrary sections of the graph the spatial index structure R-Tree is used. It enables query times to linearly increase with the number of returned edges and be independent of the section size or position.
Furthermore complex filter expressions including comparisons and arithmetic operators can be applied to limit the displayed edges. This enables the client to explore the graph's details comfortably and highlight interesting aspects of an algorithm.
The graph data management library is used in a route planning application, which is being developed in a research group of the University of Karlsruhe. It will be used to visualize the route using a web applet.
Posted on 2006-05-03 16:19 by Timo at Permlink with Comments. Tags: university talk c++
Im Sommersemester 2005 habe ich am Praktikum "Real-Life Programming" am IPD Lehrstuhl der UniKa teilgenommen. Hier platt die Beschreibung von der Homepage zitiert:
Wie programmiert man richtig?
Viele performancekritische Software wird immer noch in C geschrieben. C erlaubt dem Compiler einen sehr großen Optimierungsspielraum, in diesem Praktikum wird geübt, wie dieser ausgenutzt werden kann und wie die dabei auftretenden Klippen zu umschiffen sind.
In diesem Kontext könnt ihr lernen:
In diesem Zusammenhang haben zwei Komilitonen und ich einen Vortrag über "Objekt-orientiertes Programmieren in C" (ohne ++) ausgearbeitet und gehalten. Weiteres Schwerpunktthema war die Darstellung von C++ in Maschine, also wie der C++ Übersetzer dann die Klassen abbildet.
| Vortragsfolien: | OOC-Folien.pdf | 179 kB |
| Handout: | OOC-Handout.pdf | 122 kB |
| Beispielcode: | OOC-Beispiele.tar.gz | 4 kB |
Hier noch ein Auszug des Inhaltsverzeichnisses:
Diese Folien geben einen kompetenten Überblick über den Themenbereich.