There are two basic methods for creating, copying, or assigning a bank in Trybos: assign() which performs a copy-by-value, and assign_ref() which performs a copy-by-reference. In a copy-by-value, memory is allocated for a new, distinct bank and the values from one bank are copied into the newly-allocated memory. In a copy-by-reference, no new memory is allocated; only the pointers to the information in one bank are copied to pointers to the same information in the new bank. In general, banks which are stored in a record (called recorded banks) are manipulated with assign_ref(), and those which are not stored in a record (called unrecorded banks) are manipulated by assign(). This is largely an optimization issue, but one which has a side-effects. If one alters the values in a recorded bank, one changes the record data seen by other. If one alters the values in an unrecorded bank, others do not see the changes occurring to a record.
Consider an example of creating a fixed-size, mono-type "LRID" bank. This will be an instance of the class LRID_Bank. An instance of this class can be constructed on the heap (an unrecorded bank) or inside a record (a recorded bank). Since there is no extra information required to determine the size of an LRID_Bank, the unrecorded bank constructor just takes the bank number as an argument, while the recorded bank constructor must also have the record involved as an argument.
explicit LRID_Bank(const TRY_Bank_Number& number) ; // New unrecorded Bank
explicit LRID_Bank(const TRY_Bank_Number& number, // New recorded Bank
const TRY_Abstract_Record *p_record) ;
Both constructors set the bank header and type information, but do not set any default values for the user data section of the bank. Each of these constructors would take more arguments if the bank size varied.
In addition to these, there are constructors which take record iterators as arguments in order to convert from iterators to a full-fledged bank. These constructors are the same for variable-sized banks.
explicit LRID_Bank(const TRY_Record_Iter_Any& my_iter) ; // == assign_ref() explicit LRID_Bank(const TRY_Record_Iter_Same& my_iter) ; // == assign_ref()
There are also constructors taking a generic bank or another LRID bank as arguments as well as an assignment operator. They do not change form for variable-sized banks. The assign() and assign_ref() methods are used to avoid replicating code between several constructors and the assignment operator. The behavior of assign() varies according to whether the arguments are related to a recorded bank or not. Constructing a bank which is recorded, or initializing with a bank which is recorded, only causes a copy of the pointers to the data, not the data itself. Hence, any change to data values in such a bank object will cause the recorded bank data to also change. If the user wishes to force a particular behavior, alternatives to the assign method are also provided which specifically copy data into new memory (a ``deep'' copy) or simply copy pointers to the data (a ``shallow'' copy).
void assign(const LRID_Bank& my_bank) ; // copy by value void assign_ref(const LRID_Bank& my_bank) ; // copy by reference explicit LRID_Bank(const LRID_Bank& my_bank) ; // Copy constructor LRID_Bank& operator =(const LRID_Bank& my_bank) ; // Assignment