|
IntroductionOverviewThis library is a collection of various C++ objects I have created and found to be useful over the last few years. Generally speaking, there is no focus on any specific domain in the library, it mostly contains general utility sorts of things. One of the bigger and more notable features is the API abstraction layer which allows you to create portable applications that make use of TCP sockets, threads, file browsing, and simple graphical user interfaces. There is, however, much more than just that. This library also aims to be simple, portable, and modern. Everything is developed with the Design by Contract methodology. You can read about Design by Contract on the internet for more information but from the point of view of a user of this library it basically means that there exists complete and precise documentation and aggressive debugging modes that can be enabled. I always try to make sure everything is as portable as possible. All platform specific code is confined inside the API wrappers. Everything else is either layered on top of those wrappers or is written in pure ISO standard C++. Currently the library is known to work on OS X, MS Windows, Linux, Solaris, the BSDs, and HP-UX. It should work on any POSIX platform but I haven't had the opportunity to test it on any others (if you have access to other platforms and would like to help increase this list then let me know). The rest of this page explains everything you need to know to get started using the library. It explains where to find the documentation for each object/function and how to interpret what you find there. For help compiling with dlib check out the how to compile page. Or if you are having trouble finding where a particular object's documentation is located you may be able to find it by consulting the index. The library is also covered by the very liberal Boost Software License so feel free to use it however you like. Much of the organization and notation used in this library I learned from the Software Component Engineering course sequence at OSU. As such, this library is heavily influenced by the Design by Contract and generic programming methodologies. NotationFor the most part I try to document my code in a way that any C++ programmer would understand, but for the sake of brevity I use some of the following uncommon notation.
For example, you might see a line in this section that says "my_size == size()". This just means that the member variable my_size always contains the value returned by the size() function.
OrganizationThe library can be thought of as a collection of components. Each component consists of one "kernel" specification that defines exactly what the component's interface looks like and what it does. Additionally each component may have extensions to its kernel. Each kernel and extension specification can have many implementations.
Creating ObjectsTo create many of the objects in this library you need to choose which kernel implementation you would like and if you want the checking version or any extensions. To make this easy there are header files which define typedefs of all this stuff. For example, to create a queue of ints using queue kernel implementation 1 you would type dlib::queue<int>::kernel_1a my_queue;. Or to get the debugging/checking version you would type dlib::queue<int>::kernel_1a_c my_queue;. There can be a lot of different typedefs for each component. You can find a list of them in the section for the component in question. For the queue component they can be found here. None of the above applies to the API components (or any global functions or objects that don't list multiple implemenations in their documenation). To use/create them you just need to include the appropriate headers. For example, to create a mutex object from the threads component you would simply type dlib::mutex my_mutex;. There is no need to specify which kernel implementation. The correct kernel implementation is determined by which platform you compile under. There are also no explicit checking versions of the API components. However, there are DLIB_ASSERT statements that perform checking and you can enable them by #defining DEBUG or ENABLE_ASSERTS. AssumptionsThere are some restrictions on the behavior of certain objects or functions. Rather than replicating these restrictions all over the place in my documentation they are listed here.
Thread SafetyIn the library there are three kinds of objects with regards to threading. There are objects that are completely thread safe. Then there are objects that are not thread safe but can be used if access to them is serialized using a mutex. Lastly, there are objects which share some kind of global resource or are reference counted. The last kind of object is extremely thread unfriendly and can only be used in a threaded program with great care. How do you know which components/objects are thread safe and which aren't? The rule is that if the specification for the component doesn't mention threading or thread safety then it is ok to use as long as you serialize access to it. If the component might have some global resources or be reference counted then the specifications will tell you this. And lastly if the component is thread safe then the specification will tell you this also. |