Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

SplitsDB.h

Go to the documentation of this file.
00001 /** Code to access the database containing the Splits information
00002 
00003     $Revision: 1.8 $
00004     Last updated: $Date: 2002/09/20 12:21:31 $
00005     
00006     Copyright (C) 2001-2002 Vlad Mereuta <dizzy@users.sourceforge.net>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00021 
00022 #ifndef __SPLITS_DB__
00023 #define __SPLITS_DB__
00024 
00025 #include "Database.h"
00026 
00027 /// type of the Splits database
00028 #define SPLITSDB_TYPE   'DATA'
00029 /// db name
00030 #define SPLITSDB_NAME   "FreeCoins-Splits"
00031 
00032 ///the packed structure of a split 
00033 typedef struct {
00034     /// UID of the transaction that the split belongs to
00035     UInt32      trans_uid;
00036     /// UID of the affected account
00037     UInt32      acc_uid;
00038     /// signed amount by which the account is affected
00039     UInt32      amount;
00040     /// line number for sorting purposes
00041     UInt8       line_no;
00042 } packedSplitStructure;
00043 
00044 ///unpacked structure of a Split
00045 typedef struct {
00046     /// UID of the transaction that the split belongs to
00047     UInt32      trans_uid;
00048     /// UID of the affected account
00049     UInt32      acc_uid;
00050     /// signed amount by which the account is affected
00051     Int32      amount;
00052     /// line number for sorting purposes
00053     UInt8       line_no;
00054 } splitStructure;
00055 
00056 ///class to manipulate the splits database
00057 class SplitsDB : public Database <splitStructure, packedSplitStructure>
00058 {
00059  public:
00060     /// unpacks a Split record
00061     void    unpackRecord (splitStructure* spl, packedSplitStructure* packed_spl) DB_SECTION2;
00062     /// packs a Split record
00063     void    packRecord (splitStructure* spl, MemHandle db_entry) DB_SECTION2;
00064     /// initialize the database
00065     SplitsDB() DB_SECTION2;
00066     /** locate the first split that belongs to the given transaction
00067         @param trans_uid UID of the transaction
00068         @return the index of the first split within the transaction */
00069     UInt16 locateFirstSplit(UInt32 trans_uid) DB_SECTION2;
00070  
00071     /** set a record to cleared, update the affected account's cleared balance
00072         @param id id of the record to be set  */
00073     void    clearRecord(UInt16 id) DB_SECTION2;
00074 
00075     /** set a record to uncleared and update the affected account's cleared
00076         balance
00077         @param id id of the record to be set */
00078     void    unclearRecord(UInt16 id) DB_SECTION2;
00079 
00080     /** creates a new record and update the balance of the involved account.
00081         The transaction that the split belongs to is responsible for keeping
00082         the number of splits it has up to date.
00083         @param s pointer to the structure containing the split data
00084         @param cleared indicates if this split affects the cleared balance
00085         @return id of the newly created record  */
00086     UInt16  newRecord(splitStructure* s, Boolean cleared) DB_SECTION2;
00087     
00088     /** deletes a record, given its id. The balance of the affected account
00089         is updated.
00090         The transaction that the split belonged to is responsible for keeping
00091         the number of splits it has up to date.
00092         @param id the id of the record to be deleted
00093         @param keep_balance if true then the balances of the account involved in the split will *not* be changed. Use only when necessary, as this
00094         results in unbalanced accounts      */
00095     bool deleteRecord(UInt16 id, Boolean keep_balance = false) DB_SECTION2;
00096 
00097     /** Compares two packed split structures.
00098         For parameters see the PalmOS reference */
00099     static Int16    compareRecords(packedSplitStructure* rec1,packedSplitStructure* rec2,Int16 other,SortRecordInfoPtr sr1,SortRecordInfoPtr sr2,MemHandle app_info) DB_SECTION2;
00100 };
00101 
00102 ///reference through which this database can be accessed
00103 extern SplitsDB* splits_db;
00104 
00105 #endif

Generated on Thu Jan 16 23:11:12 2003 for FreeCoins by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002