Professional Documents
Culture Documents
Class Account API
Class Account API
Class Account API
Lightening Cheque
application.
Marc Zonzon
Cheque management.
Contents
1 Date 1.1 1.2 1.3 1.4 1.5 ..................................................... BadDate Exception for bad dates. . . . . . . . . . . . . . . . . . . . . . . . BadFormat Exception for wrong format. . . . . . . . . . . . . . . . . OutputRange Output Range Exception. . . . . . . . . . . . . . . . . . now Tag for the Date constructor. . . . . . . . . . . . . . . . . . . . . . . constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.4 DateFmt The known date formats . . . . . . . . . . . . . 1.5.5 YearDigits Year is written on 2 or 4 digits . . . . . Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Input-Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4 4 5 5 5 6 7 7 9 10 13 13 15 33 36 37 38 41 42 42 44 45 49 50 53 53 56
Money . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TransactionData The TransactionData structure . . . . . . . Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Comparison of transactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.5 Accessors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.6 Modiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Account The account class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1 Typedefs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Constructors and destructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Transaction management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Accessors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5 Modiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . SecureInt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1 SecureInt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1.1 Overow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
July 1, 2003
Cheque management.
This small set of classes is aimed to provide an account management facility. The lightening cheque user interface is based on these class. The link between the account level and the UI is done by an account manager layer. Two base classes. The Transaction class group all data from a transaction. An object of the Account class, is a user account. Each user can have as many account as needed. They are not deemed to be true bank account. Four utilities classes: The Date class provide the date needed by transaction and account. The Money is an arithmetic class appropriate for money operations. (xed length, no unexpected rounding, oveow detection). The SecureInt class provides integer with overow detection, it is used by the Money class. The Test class provides the framework for testing each component.
July 1, 2003
Date
class Date
Public Members 1.1 struct BadDate 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 struct struct struct BadFormat OutputRange now constants. Constructors Accessors Input-Output Modiers
Exception for bad dates. . . . . . . . . Exception for wrong format. ... Output Range Exception. . . . . . . . Tag for the Date constructor. . . ................................ ................................ ................................ ................................ ................................
4 4 5 5 5 7 9 10 13 13
Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1
struct BadDate
Exception for bad dates.
Exception for bad dates. Used when the year, month, day do not match any valid date.
1.2
struct BadFormat
Exception for wrong format.
Exception for wrong format. Used when a string cannot be decoded as a date.
July 1, 2003
Date
1.3
struct OutputRange
Output Range Exception.
Output Range Exception. Exception thrown when trying to write on two digits a date which cannot be safely encoded.
1.4
struct now
Tag for the Date constructor.
Tag for the Date constructor. Provide a fake type used to ask for the present date.
1.5
constants.
const int centuryLim const int lwYear const int hiYear DateFmt YearDigits const DateFmt defaultFmt
The bound to infer a century from a two digits year . . . . . . . . . . . . . . . Lower allowed year. . . . . . . . . . . . . Higher allowed year. ...........
6 6 6 6 7 7
The known date formats . . . . . . . . Year is written on 2 or 4 digits . The default format . . . . . . . . . . . . .
July 1, 2003
Date
1.5.1
1.5.2
Lower allowed year. This value is set according to Unix timers length.
1.5.3
Higher allowed year. This value is set according to Unix timers length.
1.5.4
enum DateFmt
The known date formats
July 1, 2003
Date
1.5.5
enum YearDigits
Year is written on 2 or 4 digits
1.5.6
1.6
Constructors
Names 1.6.1 Date ( int y, int yday) throw( BadDate) Constructor with a day number in the year. . . . . . . . . . . . . . . . . . . . . . . . Date (now) Current date. . . . . . . . . . . . . . . . . . .
8 8 8 9
Date ( int y, int m, int d ) throw( BadDate ) year, month, day constructor. Date ( const Date &) copy constructor . . . . . . . . . . . . . . . Date ( std::string s, DateFmt fmt=defaultFmt) throw( BadFormat, BadDate) Scan a string to extract a date. .
July 1, 2003
Date
1.6.1
Constructor with a day number in the year. Parameters: y yday the year day within the year.
1.6.2
Date (now)
Current date.
Current date. You can initialize a date to the current day by saying Date today=now();
1.6.3
year, month, day constructor. Note that you cannot call Date(2005,09,08) because 09 and 08 are inexistent octal numbers, of course Date(2005,9,8) is ne.
July 1, 2003
Date
1.6.4
copy constructor
1.6.5
Scan a string to extract a date. Years lower than 100 are translated to the current or previous century according how they compare to the constant centuryLim. Throw a BadFormat exception if the string cannot be decoded and a BadDate exception if it is inexistent. Parameters: s fmt The string containing the date. The format used.
1.7
Accessors
10 10 10 10
July 1, 2003
Date
1.7.1
1.7.2
1.7.3
1.7.4
1.8
Input-Output
Names 1.8.1 std::string strDate (YearDigits ydigits=full, DateFmt fmt=defaultFmt ) const String representation of a date. std::ostream&
11
1.8.2
July 1, 2003
10
Date
put (std::ostream& os, YearDigits ydigits=full, DateFmt fmt=defaultFmt) const Put the date on the output stream os. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.8.3 std::ostream& put (std::ostream& os, DateFmt fmt) const Put the date on the output stream os. . . . . . . . . . . . . . . . . . . . . . . . . . . . . std::istream& get (std::istream& is, DateFmt fmt=defaultFmt) throw(BadDate) Get the date from input stream.
12
12
1.8.4
12
1.8.1
ydigits=full,
DateFmt
fmt=defaultFmt ) const
String representation of a date.
String representation of a date. Return Value: Parameters: a string containing the representation of the date. fmt The format used to print the string. ydigits The year is coded on 4 chars if ydigits isfull and 2 if it is abridged.
1.8.2
os,
YearDigits
ydig-
DateFmt
fmt=defaultFmt)
July 1, 2003
11
Date
Put the date on the output stream os. Parameters: yWidth fmt ydigits the number of digits for the year ( 2 or 4) The format used to print the string. Year on 4 digits ( full ) or 2 digits ( abridged )usually called via <<
1.8.3
Put the date on the output stream os. Call the previous method with the default of ydigits=full
1.8.4
is,
DateFmt
fmt=defaultFmt) throw(BadDate)
Get the date from input stream.
Get the date from input stream. Note that input error are either reported through an ios ag if the date cannot be read or with an exception if it is inexistent. Return Value: of th stream after the operation,you can test ios::failBite to know if the reading succeeded. is the input stream. BadDate is thrown when the date is inexistent state
Parameters: Exceptions:
July 1, 2003
12
Date
1.9
Relational operators
operator== ( const Date & ) const . . . . . . . . . . . . . . . operator!= ( const Date & ) const . . . . . . . . . . . . . . . . operator< ( const Date & ) const . . . . . . . . . . . . . . . . . .
13 13 13
1.9.1
1.9.2
1.9.3
1.10
Modiers
operator++ ()
pre-increment operator . . . . . . . . .
14 14
July 1, 2003
13
Date
14
1.10.1
Date& operator++ ()
pre-increment operator
pre-increment operator
1.10.2
post-increment operator
1.10.3
July 1, 2003
14
Money
Money
Names 2.1 2.2 typedef int SecureInt class Money Detection of overows. . . . . . . . . . 15
std::ostream& operator<< ( std::ostream & output, const Money &m ) throw() Output operator. . . . . . . . . . . . . . . . std::istream& operator>> ( std::istream &is, Money &m ) throw(Money::Overow) Intput operator. . . . . . . . . . . . . . . . .
32
2.3
32
Money
2.1
Names 2.1.1 2.1.2 2.1.3 static inline exceptions constants ................................ ................................ 16 18
bool module precondition () Precondition to build this class. Constructors Accessors operations. Input-Output ................................ ................................ ................................ ................................
19 20 22 24 28 30
July 1, 2003
15
Money
??
Detection of overows. Use SecureInt to represent the amount in cents as to allow the detection of overows. The Use of SecureInt is only done at an internal level and the user of Money dont need to know about it.
2.1.1
exceptions
Names 2.1.1.1 class 2.1.1.2 class 2.1.1.3 class
Exception
16 17
Overow : public Exception Exception for overows . . . . . . . . BadFormat : public Exception Exception for error in input of an amount of money . . . . . . . . . . . . . .
17
2.1.1.1
class Exception
base Money::Exception class
Inheritance
2.1.1.1 Exception 2.1.1.2 Overow 2.1.1.3 BadFormat
> >
July 1, 2003
16
Money
2.1.1.2
Inheritance
2.1.1.1 Exception 2.1.1.2 Overow
2.1.1.3
Inheritance
2.1.1.1 Exception 2.1.1.3 BadFormat
July 1, 2003
17
Money
2.1.2
constants
Names 2.1.2.1 typedef long int value type 2.1.2.2 static 2.1.2.3 static 2.1.2.4 static 2.1.2.5 static const Money max const Money min const int conv const int decades
An integer type to hold a Money value. . . . . . . . . . . . . . . . . . . . . . . . . . . Maximum for a Money . . . . . . . . . Minimum for a Money . . . . . . . . . multiplicand for cents to units. . The number of decimal positions. 19
18 18 19 19
2.1.2.1
An integer type to hold a Money value. value type is an integer type guaranteed to be as large as to be able to represent Money::max in cents.
2.1.2.2
July 1, 2003
18
Money
2.1.2.3
2.1.2.4
2.1.2.5
2.1.3
Precondition to build this class. The following assertion must be veried for the code to be valid. it is checked at the beginning of the object module. We check than a short int can be safely encoded as Money without taking care of overows.
July 1, 2003
19
Money
2.1.4
Constructors
Names 2.1.4.1 2.1.4.2 explicit Money () throw() A null amount of money . . . . . . . Money (long int n) throw(Overow) Initializer with a number of cents 21 Money (int i) throw(Overow) Initializer with a number of cents 21 Money (short i) throw() Initializer with short number of cents. . . . . . . . . . . . . . . . . . . . . . . . . . . Money (double d) throw(Overow) Initializer with a double. ....... 20
2.1.4.3 explicit
2.1.4.4 explicit
21 21
Money (std::string monstring) throw(BadFormat, Overow ) Constructor with a formated string. . . . . . . . . . . . . . . . . . . . . . . . . . Money (const char* monstring) throw(BadFormat, Overow ) Constructor with a formated string litteral . . . . . . . . . . . . . . . . . . .
22
2.1.4.7 explicit
22
2.1.4.1
Money () throw()
July 1, 2003
20
Money
2.1.4.2
2.1.4.3
2.1.4.4
Initializer with short number of cents. As value type is always larger than a short no Overow can be sent by this constructor.
2.1.4.5
Initializer with a double. Warning: Money(10.4) is 10 cents not 1040 cents. This function round its parameter, it is dierent from a cast from oatting to integral type.
July 1, 2003
21
Money
2.1.4.6
Constructor with a formated string. Money(1.1) 1 unit and 10 cents. Parameters: monstring string "xxxxx.xx" for an amount of money.An empty string stand for a null amount of money.
2.1.4.7
2.1.5
Accessors
Names 2.1.5.1 value type cents () const throw() Number of cents. . . . . . . . . . . . . . . . 2.1.5.2 value type units () const throw()
23
July 1, 2003
22
Money
Integer number of monetary units ................................ 2.1.5.3 value type value () const throw() The raw value . . . . . . . . . . . . . . . . . .
23 23
2.1.5.1
2.1.5.2
2.1.5.3
July 1, 2003
23
Money
2.1.6
operations.
Names 2.1.6.1 Money& 2.1.6.2 Money& operator= ( const Money &) throw() Assignement . . . . . . . . . . . . . . . . . . . operator = (std::string monstring) throw(BadFormat, Overow) Aectation from a string to Money. . . . . . . . . . . . . . . . . . . . . . . . . operator = (const char* monstring) throw(BadFormat, Overow) Aectation from a string litteral to Money . . . . . . . . . . . . . . . . . . . . . . . . . operator + (const Money &) const throw(Overow) sum of money . . . . . . . . . . . . . . . . . . operator += (const Money &) throw(Overow) . . operator - (const Money& ) const throw(Overow) dierence of money . . . . . . . . . . . . operator -= (const Money &) throw(Overow) . . . . operator - () const throw() Opposite amount . . . . . . . . . . . . . . . operator* (double) const throw(Overow) Multiply by a double. . . . . . . . . . . . operator*= (double) throw(Overow) . . . . . . . . . . . . . operator/ (const Money& ) const throw() Divide by an other amount of money. . . . . . . . . . . . . . . . . . . . . . . . . operator/= (double) throw(Overow) . . . . . . . . . . . . . operator/ (double) const throw(Overow) Divide by a real number. . . . . . . . 25
25
2.1.6.3 Money&
25
2.1.6.4 Money
26 26 26 26 27 27 27
2.1.6.5 Money& 2.1.6.6 Money 2.1.6.7 Money& 2.1.6.8 Money 2.1.6.9 Money 2.1.6.10Money& 2.1.6.11double
27 28 28
2.1.6.12Money& 2.1.6.13Money
The additive operations are with Money, the multiplicative operations are with real numbers i.e. double.
July 1, 2003
24
Money
2.1.6.1
Assignement
Assignement
2.1.6.2
monstring)
throw(BadFormat, Overow)
Aectation from a string to Money. Money(1.1) 1 unit and 10 cents. Parameters: monstring string "xxxxx.xx" for an amount of money.
2.1.6.3
char*
monstring)
throw(BadFormat, Overow)
July 1, 2003
25
Money
2.1.6.4
Money
&)
const
throw(Overow)
sum of money
sum of money
2.1.6.5
2.1.6.6
Money&
const
throw(Overow)
dierence of money
dierence of money
2.1.6.7
July 1, 2003
26
Money
2.1.6.8
Opposite amount
2.1.6.9
Multiply by a double. You obtain a money amount. It is how you compute interests.
2.1.6.10
2.1.6.11
Divide by an other amount of money. When you divide to amounts of money the result is an abstract real number, not a currency.
July 1, 2003
27
Money
2.1.6.12
2.1.6.13
2.1.7
comparison operators.
Names 2.1.7.1 bool 2.1.7.2 bool 2.1.7.3 bool 2.1.7.4 bool 2.1.7.5 operator== (const Money &) const throw() . . . . . operator!= (const Money &) const throw() . . . . . . . operator< (const Money &) const throw() . . . . . . . . operator> (const Money &) const throw() . . . . . . . . missing comparison operators They are generated by the <utility> header from STL. . . . isnull () const throw() Shortcut to test against zero . . . . iscredit () const throw() True for a positive amount . . . . . isdebit () const throw() True for a negative amount . . . . 29 29 29 29
29 29 30 30
July 1, 2003
28
Money
2.1.7.1
2.1.7.2
2.1.7.3
2.1.7.4
2.1.7.5
2.1.7.6
July 1, 2003
29
Money
2.1.7.7
2.1.7.8
2.1.8
Input-Output
Names 2.1.8.1 std::ostream& put (std::ostream& os, int width=0 ) const throw() put the Money on an output stream. . . . . . . . . . . . . . . . . . . . . . . . . 2.1.8.2 std::string strMoney ( int width) const throw() Convert type Money to a string. 2.1.8.3 std::istream& get (std::istream &is) throw(Overow) Read a Money. . . . . . . . . . . . . . . . . .
31 31
31
July 1, 2003
30
Money
2.1.8.1
put the Money on an output stream. usually called via << Return Value: Parameters: s The modied output stream. os the output stream. width, width of eld, 0 is the defaultand stand for unlimited.
2.1.8.2
Convert type Money to a string. use the format xxxxx.xx If the number is too large to t in ndigits the length is expanded. This method never truncate an amount of Money. so 0 is used for free length. Parameters: width total number of characters in the eld,
2.1.8.3
Read a Money.
July 1, 2003
31
Money
Parameters:
Exceptions:
input stream. The I/O ags of ismust be inspected with to know the result of the input. Overflow if the amount is bigger that thecapacity of Money Use the I/O ags to examine the resultof input. is
2.2
Output operator. operator version of the put method. the width is got from ios so you have to use the ags or manipulators if you want to set it.
2.3
Intput operator. operator version of the get method. Parameters: input stream. The I/O ags of ismust be inspected with to know the result of the input. m the money variable to get the amount on the stream. Overflow if the amount is bigger that thecapacity of Money Use the I/O ags to examine the resultof input. is
Exceptions:
July 1, 2003
32
TransactionData
struct TransactionData
The TransactionData structure
Members 3.1 3.2 3.3 3.4 3.5 3.6 3.7 string Date string string Money bool numM dateM descM categoryM amountM recM The number of the cheque. .... 33 34 34 34 34 35 The date of the transaction . . . . . The payee . . . . . . . . . . . . . . . . . . . . . . The category . . . . . . . . . . . . . . . . . . . The amount of transaction. Reconciled boolean. ... ............
TransactionData () A new transaction with empty data . . . . . . . . . . . . . . . . . . . . . . . . . . . TransactionData (const TransactionData& dataN) Copy constructor . . . . . . . . . . . . . . . TransactionData ( string numN, const Date dateN, string descN, string categoryN, Money amountN, bool recN ) Build a new TransactionData with all elds . . . . . . . . . . . . . . . . . . .
35 35
3.8 3.9
35
The TransactionData structure contains all transaction elds. It is used to gather data from the interface before creating or updating a Transaction
3.1
string numM
The number of the cheque.
The number of the cheque or any code for an other transaction. Some transaction doesnt have a true number. Either because this kind of transaction has no
July 1, 2003
33
TransactionData
number or more often because we dont know the id number that will be given by the bank.
3.2
Date dateM
The date of the transaction
string descM
The payee
The payee
3.4
string categoryM
The category
The category
3.5
Money amountM
The amount of transaction.
July 1, 2003
34
TransactionData
3.6
bool recM
Reconciled boolean.
rcM is true when the transaction as been reconciled with a bank transaction.
3.7
TransactionData ()
A new transaction with empty data
3.8
Copy constructor
3.9
TransactionData ( string numN, const Date dateN, string descN, string categoryN, Money amountN, bool recN )
Build a new TransactionData with all elds
July 1, 2003
35
Transaction
Public Members 4.1 4.2 4.3 Transaction () An empty transaction. ......... 36 37 Transaction (const TransactionData&) A transaction from its data . . . . Transaction ( string numN, const Date dateN, string descN, string categoryN, Money amountN, bool recN ) Straight constructor without using TransactionData . . . . . . . . . . . . . . Comparison of transactions. . . . . . . . . . . . . . . . . . . . . Accessors Modiers ................................ ................................
37 37 38 41
4.1
Transaction ()
An empty transaction.
An empty transaction. all elds are blank but the date (today).
July 1, 2003
36
Transaction
4.2
4.3
Transaction ( string numN, const Date dateN, string descN, string categoryN, Money amountN, bool recN )
Straight constructor without using TransactionData
4.4
Comparison of transactions.
Names 4.4.1 4.4.2 4.4.3 bool bool bool operator< ( const Transaction & ) const . . . . . . . . . . . operator== ( const Transaction & ) const . . . . . . . . operator> ( const Transaction & ) const . . . . . . . . . . . 38 38 38
Transactions compare by date then by number. The missing operators are generated by the STL.
July 1, 2003
37
Transaction
4.4.1
4.4.2
4.4.3
4.5
Accessors
Names 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 string string string bool Money Money Money Money num () const desc () const The number. . . . . . . . . . . . . . . . . . . . The payee . . . . . . . . . . . . . . . . . . . . . . 39 39 39 39 40 40 40
category () const The category . . . . . . . . . . . . . . . . . . . rec () const amount () const credit () const debit () const True if reconciled . . . . . . . . . . . . . . amount is a relative number . . . . ................................ ................................
40
July 1, 2003
38
Transaction
4.5.1
4.5.2
The payee
4.5.3
The category
4.5.4
True if reconciled
July 1, 2003
39
Transaction
4.5.5
4.5.6
4.5.7
4.5.8
The balance after this transaction. It depends not only on the amount of this transaction but also of all the preceding ones.
July 1, 2003
40
Transaction
4.6
Modiers
Names 4.6.1 4.6.2 4.6.3 void void recBalance (Money m) Set the record-Balance. rec (bool) ........ 41 41 ??
4.6.1
The record-Balance is computed by the account class. As the record balance can change even if the transaction doesnt it is declared const
4.6.2
Reconcile a transaction. It is the only modication you can do without reentering the whole data.
July 1, 2003
41
Account
class Account
The account class.
Public Members 5.1 5.2 5.3 5.4 5.5 Typedefs ................................ 42 44 45 49 50 Constructors and destructor . . . . . . . . . . . . . . . . . . . . Transaction management . . . . . . . . . . . . . . . . . . . . . . . Accessors. Modiers ................................ ................................
Protected Members 5.6 void adjustBalance (iterator it ) Adjust the balance after an update. ................................ adjustBalance () Adjust the balance after an update. ................................
52 52
5.7
void
The account class. is used to record the transactions on a specic account. A user can have many accounts. but in the present application we can suppose that the whole number of accounts is quite low (not more than 10) so the speed of creation and destruction is not our rst concern.
5.1
Typedefs
Names 5.1.1 5.1.2 5.1.3 typedef vector<Transaction> TransList typedef TransList::iterator iterator The container for transactions. Iterator type for transactions . . . 43 43
July 1, 2003
42
Account
44 44
5.1.1
The container for transactions. We have to choose some convenient type of container the requirements are as follow: The container must be accessible by number. It is because the UI return from menus by number of the selected item. The container is ordered. Because we want that the transaction list stay sorted by date and transaction number. We can suppose that the user will mainly enter transaction sequentially and that sorting is not very often necessary. But of course it would need to be checked. We can achieve this goal either by inserting transactions at their right place or by sorting transactions before to display them. When an account is moved by copy-destruction, the container is also copied and destroyed, it may be time consuming. The cause of moving accounts is that they are themselves placed in containers which can need to move them. It happens when they reclaim space because they dont have room to add new accounts.
5.1.2
July 1, 2003
43
Account
5.1.3
5.1.4
Blank account
Blank account
5.2
Names 5.2.1
Account ( string nameN, string descN, string notesN= ) Account with no transaction . . . . Account ( const Account & oldAccount) Copy constructor. . . . . . . . . . . . . . . ~Account () Destructor. ....................
44 45 45
5.2.2 5.2.3
5.2.1
July 1, 2003
44
Account
5.2.2
Copy constructor. The transaction container is copied. Depending on the container this may imply a copy of each transaction.
5.2.3
~Account ()
Destructor.
5.3
Transaction management
Names 5.3.1 5.3.2 5.3.3 5.3.4 void void void void push back ( const Transaction & ) Add a new transaction. erase (iterator) sort () ........ 46 46 47
update ( iterator it, const TransactionData &x ) Change the data of the transaction it. . . . . . . . . . . . . . . . . . . . . . . . . . . . . size () const begin () end () the number of transactions . . . . . First transaction. . . . . . . . . . . . . . . Iterator past the end of transactions. . . . . . . . . . . . . . . . . . . . . . . . . . .
47 47 47 48
July 1, 2003
45
Account
5.3.8 5.3.9
iterator iterator
last ()
Last transaction. . . . . . . . . . . . . . . .
48 48 48
transaction (int i)Iterator on the transaction numb. ................................ empty () const Predicate true if no transaction.
5.3.10 bool
An account is a transaction container and manager. As we want to keep private the base container we import all necessary operations.
5.3.1
Add a new transaction. The transaction is added at the end of the container. The record balance is xed as the account balance. The lastNbr is modied if this transaction is numbered. The sorting of transactions is presently done later.
5.3.2
Delete a transaction.
July 1, 2003
46
Account
5.3.3
void sort ()
Sort all transactions.
Change the data of the transaction it. precondition: begin() it < end().
5.3.5
iterator begin ()
First transaction.
First transaction. This iterator can be dereferenced only if begin()<end(), otherwise the account is empty.
July 1, 2003
47
Account
5.3.7
iterator end ()
Iterator past the end of transactions.
5.3.8
iterator last ()
Last transaction.
July 1, 2003
48
Account
5.4
Accessors.
Names 5.4.1 5.4.2 5.4.3 5.4.4 5.4.5 string string Money Money int name () const desc () const balance () const Account name . . . . . . . . . . . . . . . . . . Account description . . . . . . . . . . . . Balance of the account. ........ 49 49 50 50 50
bankBalance () const Bank balance of the account. . . . lastNbr () const higher number of a transaction .
5.4.1
Account name
Account name
5.4.2
Account description
Account description
July 1, 2003
49
Account
5.4.3
5.4.4
5.4.5
5.5
Modiers
Names 5.5.1 5.5.2 void void name ( string newname ) Account name modier . . . . . . . . . desc (string newdesc ) 51
July 1, 2003
50
Account
Account description modier . . . 5.5.3 5.5.4 void void lastNbr (int n) set the recorded last number . . . .
51 51 52
5.5.1
5.5.2
5.5.3
July 1, 2003
51
Account
5.5.4
Set the last number to the argument if numeric. The last number is unchanged if s is not numeric. Parameters: s any string, when it is a numeric string it replacesthe last number.
5.6
Adjust the balance after an update. Parameters: it is the rst modied transaction
5.7
void adjustBalance ()
Adjust the balance after an update.
Adjust the balance after an update. All transactions are inspected to compute the balance.
July 1, 2003
52
SecureInt.
SecureInt.
Names 6.1 6.2 class SecureInt ................................ 53 std::ostream& operator << (std::ostream & os, SecureInt i) throw() ................................ std::istream& operator >> (std::istream & is, SecureInt& i) throw(SecureInt::Overow) ................................
67
6.3
67
6.1
class SecureInt
Public Members 6.1.1 6.1.2 6.1.3 class Overow ................................ ................................ 56 56 typedef long value type static inline
56 56 56 57 57
const bool odd word error odd word error. const int bhalf size const value type max value const value type
July 1, 2003
53
SecureInt.
min value 6.1.9 static const SecureInt max const SecureInt min
57 57 58 58 58 58 58 59 59 59 59 59 59 60 60 60 60 60 60 61 61 61 61 61 62 62 62 62
SecureInt (value type i=0) throw(Overow) . . . . . . . . SecureInt (int i) throw(Overow) . . . . . . . . . . . . . . . . . . SecureInt (short i) throw(Overow) . . . . . . . . . . . . . . . . SecureInt (double d) throw(Overow) Floating-integral conversions. ..
6.1.15 SecureInt 6.1.16 SecureInt 6.1.17 SecureInt 6.1.18 SecureInt 6.1.19 SecureInt 6.1.20 SecureInt 6.1.21 SecureInt 6.1.22 SecureInt 6.1.23 SecureInt 6.1.24 SecureInt 6.1.25 SecureInt 6.1.26 double
operator + (SecureInt i) const throw(Overow) . . operator - (SecureInt i) const throw(Overow) . . . operator * (SecureInt i) const throw(Overow) . . . operator / (SecureInt i) const throw() . . . . . . . . . . . . operator% (SecureInt i) const throw() . . . . . . . . . . . . operator + (int i) const throw(Overow) . . . . . . . . . operator - (int i) const throw(Overow) . . . . . . . . . . operator * (int i) const throw(Overow) . . . . . . . . . . operator / (int i) const throw() . . . . . . . . . . . . . . . . . . operator% (int i) const throw() . . . . . . . . . . . . . . . . . . operator - () const throw() . . . . . . . . . . . . . . . . . . . . . . . . operator * (double d) const throw() product by a double. . . . . . . . . . . . .
6.1.27 SecureInt& operator = (const SecureInt& i) throw() . . . . . . . . . . 6.1.28 SecureInt& operator = (int i) throw(Overow) aectation of an int. . . . . . . . . . . . 6.1.29 SecureInt& operator = (short i) throw(Overow) . . . . . . . . . . . . . 6.1.30 SecureInt& operator = (value type i) throw(Overow) . . . . . . . . 6.1.31 SecureInt& operator = (double d) throw(Overow) . . . . . . . . . . . 6.1.32 SecureInt& operator += (SecureInt i) throw(Overow) . . . . . . . 6.1.33 SecureInt& operator -= (SecureInt i) throw(Overow) . . . . . . . . 6.1.34 SecureInt& operator *= (SecureInt i) throw(Overow) . . . . . . . . 6.1.35 SecureInt& operator /= (SecureInt i) throw() . . . . . . . . . . . . . . . .
July 1, 2003
54
SecureInt.
6.1.36 SecureInt& operator += (int i) throw(Overow). . . . . . . . . . . . . . 6.1.37 SecureInt& operator -= (int i) throw(Overow) . . . . . . . . . . . . . . . 6.1.38 SecureInt& operator *= (int i) throw(Overow) . . . . . . . . . . . . . . 6.1.39 SecureInt& operator /= (int i) throw() . . . . . . . . . . . . . . . . . . . . . . . 6.1.40 SecureInt& operator *= (double d) throw(Overow) product of current value by a double; Equivalent to * then = . . . . . 6.1.41 SecureInt& operator/= (double) throw(Overow) division of current value by a double; Equivalent to / then = . . . . . 6.1.42 bool 6.1.43 bool 6.1.44 bool 6.1.45 bool 6.1.46 bool 6.1.47 bool 6.1.48 bool 6.1.49 bool 6.1.50 bool 6.1.51 bool 6.1.52 bool 6.1.53 bool 6.1.54 SecureInt 6.1.55 SecureInt 6.1.56 double operator == (SecureInt i) const throw() . . . . . . . . . . operator == (value type i) const throw() . . . . . . . . . operator == (int i) const throw() . . . . . . . . . . . . . . . . operator!= (SecureInt i) const throw() . . . . . . . . . . . operator!= (value type i) const throw() . . . . . . . . . . operator!= (int i) const throw() . . . . . . . . . . . . . . . . . . operator< (SecureInt i) const throw() . . . . . . . . . . . . . operator< (value type i) const throw() . . . . . . . . . . . . operator< (int i) const throw() . . . . . . . . . . . . . . . . . . . operator> (SecureInt i) const throw() . . . . . . . . . . . . . operator> (value type i) const throw() . . . . . . . . . . . . operator> (int i) const throw() . . . . . . . . . . . . . . . . . . . operator/ (const SecureInt& ) const throw(). . . . . . operator/ (long i ) const throw() . . . . . . . . . . . . . . . . . operator/ (double) const throw() . . . . . . . . . . . . . . . . .
62 62 63 63
63
63 63 64 64 64 64 64 64 65 65 65 65 65 65 66 66 66 66
6.1.57 std::ostream& put (std::ostream & os) const throw() . . . . . . . . . . . . . . 6.1.58 std::istream& get (std::istream & is) throw(Overow) . . . . . . . . . . . . . 6.1.59 template< class Target> Target cast to () const throw() cast to an other arithmetic type. 6.1.60 template<class T>static bool rangeOK (T i) Range predicate. ...............
66 67
July 1, 2003
55
SecureInt.
6.1.1
class Overow
6.1.2
6.1.3
Precondition to build this class. The following assertion must be veried for the code to be valid. it is checked at the beginning of the object module.
6.1.4
6.1.5
odd word error. I suppose that a word has always an even size, so I make sure to fail if some strange CPU is using odd side for a word.
July 1, 2003
56
SecureInt.
6.1.6
6.1.7
Maximum value
6.1.8
Minimum value
6.1.9
Maximum SecureInt
July 1, 2003
57
SecureInt.
6.1.10
Minimum SecureInt
6.1.11
6.1.12
6.1.13
6.1.14
Floating-integral conversions. In respect to others Floating-integral conversions The double d is truncated to produce a SecureInt value.
July 1, 2003
58
SecureInt.
6.1.15
i)
const
6.1.16
6.1.17
6.1.18
6.1.19
6.1.20
July 1, 2003
59
SecureInt.
6.1.21
6.1.22
6.1.23
6.1.24
6.1.25
6.1.26
July 1, 2003
60
SecureInt.
6.1.27
6.1.28
aectation of an int. It is very usefull to have an aectation of a smaller int type because it can be down without conversion. We dont know on which machine int and short are smaller than value type; so we cannot exclude an Overow.
6.1.29
6.1.30
6.1.31
July 1, 2003
61
SecureInt.
6.1.32
6.1.33
6.1.34
6.1.35
6.1.36
6.1.37
July 1, 2003
62
SecureInt.
6.1.38
6.1.39
6.1.40
6.1.41
6.1.42
July 1, 2003
63
SecureInt.
6.1.43
6.1.44
6.1.45
6.1.46
6.1.47
6.1.48
July 1, 2003
64
SecureInt.
6.1.49
6.1.50
6.1.51
6.1.52
6.1.53
6.1.54
July 1, 2003
65
SecureInt.
6.1.55
6.1.56
6.1.57
6.1.58
6.1.59
cast to an other arithmetic type. The cast is done by the standard static cast and can cause a truncation if the target type is smaller than value type
July 1, 2003
66
SecureInt.
6.1.60
Range predicate. Check if a value from an other numeric type can be safely encoded as a SecureInt. Allow to try before use instead of using exceptions.
6.2
6.3
July 1, 2003
67