farLib

This source library can be used in any project that does not violate the license as described at the end of this document.

The library is a collection of useful and integrated classes which have utility in a wide variety of projects.

Download farlib.zip



To install this library, unzip the source files into the folder of your choice.



With a simple two-line edit, the library can be used in Windows, Linux or Unix projects, separately, in a compiled library (dll) or compiled together with the main program file. A Make file is included for the Linux (gcc) build. Add the names of your source files to the Makefile file to create a simple Linux project.

To use this library in a Linux or Unix project, open and edit the source file prefixb.h.

Find the two lines

#define FV_MSWINDOWS
#define FV_MSWIN32

and replace them with the single line

#define FV_UNIX

To use the library in Windows, just leave the two lines alone.



The farLib classes do not use the STL or any other templates except for a single template for supporting smart pointers. You will find the template in the prefixb.h file with the name TPtr.

It is very easy to use smart pointers in your own code. I recommend that when you create your own classes, you follow the pattern used in the library header files. Here is the general pattern for defining a class to support smart pointers, called CMyClass, in a header file:

#ifndef MYCLASS_H
#define MYCLASS_H

#includes here

_FBDEF(CMyClass)
class FBC_USE CMyClass: public CAtom
{
    ... the innards
}; // CMyClass

(any other classes? You can add them here as per standard C++ using same pattern as above.)

#end // MYCLASS_H

Using the _FBDEF macro is the key. This defines two derived types that you use for pointers to objects of CMyClass.

 pCMyClass p;  // p is a simple pointer to a CMyClass object.
 PCMyClass q;  // q is a farLib smart pointer.

Example of using a simple pointer (type name starts with lower-case "p"):

pCFile myFile = new CFile("C:/myprojectdata/data.txt");

Example of using a smart pointer (type name starts with upper-case "P"):

PCFile myFile = new CFile("C:\myprojectdata\data.txt");

(note: slash and backslash work in file names for either platform)

The difference between your use of the two pointers is that you will have to manually delete the memory referenced by the simple pointer when it goes out of context, but you do not delete the memory referenced by the smart pointer. The smart pointer object will delete the memory through the magic of the C++ compiler.

Smart pointers are objects that contain only pointers to the objects they reference, so they are the same size as dumb pointers. The important thing that makes it all happen is that you derive your classes from CAtom or one of its children. There is one caveat: If you create two objects using smart pointers that point to each other, you will have to take the law into your own hands and break their unholy clinch.


 
Here is a list of the classes and tools in the library and a one-line description of each class.

CArgs
Parses and provides access to parameters on the command line.
CAtom
The base class to the library. Provides reference counting.
CBlock
Manages larger chunks of memory.
CBook
A very flexible many-many name-value oriented database.
CBookInfo
Manages a descriptive record associated with each book.
common
A collection of useful platform independent routines.
CFile
Comprehensive platform independent access to the file system.
CFindlist
Directory access tool.
CHash
Manages a hash access name-value file.
CHshList
In-memory name-value table.
CLclBook
Local implementation of the book paradigm.
CList
Simple flexible method of collecting objects.
misc
Some more platform independent routines.
COdb
Simplifies access to a book.
CProcess
Creates and runs other processes.
CRecord
Comprehensive text-based record management tool.
CRefs
Part of the book to support many-many relationships.
CSearch
Parses complex algerbraic search expressions to query the book.
CStrlist
Special form of the list to store strings (char-arrays).
CStrng
Yet another "standard" C++ string class. I never use it.
SysLog
A logging tool usable by multiple threads. Not derived from CAtom. Use DebugView.
farlibsample
A short program that uses some of the library.



A simple main file, called farlibsample.cpp, using the farLib library, is included in the library. If you use the Make file, you will need to add this file to it.



 Translations of this library are also available on request in C# and Java.



 The following license notification is attached to each file in the library.

/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is Paul Medlock.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 * Paul Medlock,
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */