This class provides a mechanism to store invoices in a directory tree. The structure of the tree is as follows:
This class provides public functions to
Example:
// ... InvoiceDir myDir("/home/invoices", 90); ofstream os = myDir.create("M1/Jan", "inv001.txt"); os << "Sample data" << endl; myDir.close(); // ... if (success) { myDir.confirm(); } else { myDir.deleteUnconfirm(); } // ...
Definition at line 178 of file invoicedir.h.
OSB_LIB::InvoiceDir::~InvoiceDir | ( | ) |
Destructor of the InvoiceDir class.
This destructor will destroy the mutex variable.
OSB_LIB::InvoiceDir::InvoiceDir | ( | const std::string & | basePath, | |
long | maxEntry | |||
) |
Constructor of the InvoiceDir class.
This constructor will initialize the 'dirBase_' and 'MAX_ENTRY' with the input provided. Besides that, it also initialize the mutex of this class.
basePath | Base directory (absolute path) of the invoice storage tree. | |
maxEntry | Maximum entry allowed in one directory. |
void OSB_LIB::InvoiceDir::close | ( | const OSB_DB::Session & | session, | |
const InvoiceInfo & | invInfo | |||
) |
Close the ostream and insert the invoice info in the DB.
This function will close the ostream that has been created by the this.create() function mentioned above. Also the info of the current invoice is written to the DB.
session | Active session of the user application. | |
invInfo | Contains details to be inserted in the DB. |
void OSB_LIB::InvoiceDir::confirm | ( | ) |
Accept all the newly written invoices.
This function will rename all the newly written files from 'xxxx-tmp' to 'xxxx'.
std::ostream& OSB_LIB::InvoiceDir::create | ( | const std::string & | dirPath, | |
const std::string & | fileName | |||
) |
Create, return an ostream for application to write to.
This function will create and return an ostream to the specially designed directory tree. The user application will write to this ostream.
dirPath | Relative path where invoices will be stored. | |
fileName | File system name for the invoice. |
const std::string& OSB_LIB::InvoiceDir::currentFile | ( | ) | [inline] |
Accessor to the private member currentFile_.
Definition at line 257 of file invoicedir.h.
References currentFile_.
void OSB_LIB::InvoiceDir::deleteCurrentFile | ( | ) |
Delete current file.
This function will close the ostream that has been created by the this.create() function mentioned above. Also the current temporary file will be deleted.
void OSB_LIB::InvoiceDir::deleteUnconfirm | ( | ) |
Delete all the invoices that are not yet confirmed.
This function will remove all the newly written file with extension 'xxxx-tmp' from the file system.
std::string OSB_LIB::InvoiceDir::i2a | ( | long | i | ) | [private] |
Transform a long integer to a string.
This function will transform a long integer as specified in its arg1 to a string and return it.
i | Long integer wanted to be transformed. |
void OSB_LIB::InvoiceDir::mkTree | ( | const std::string & | dirTree, | |
mode_t | mode | |||
) | [private] |
Build a directory tree.
This function will create a directory tree as specified in its arg1. All directories and subdirectories created will have the same access permission as specified in arg2. Access privilege should be enforced in the directory mask.
dirTree | The directory tree wanted to be built. | |
mode | The access permission for the directory tree. |
void OSB_LIB::InvoiceDir::padding | ( | std::string & | str, | |
char | pad, | |||
int | size | |||
) | [private] |
Padding a string variable value to have a constant length.
This function will add in a user defined character into a string variable to make sure that the string has the length that user needs. The padding characters are added in front of the original value.
str | String variable to be padded. | |
pad | Character used to do the padding operation. | |
size | The size of the string variable after padding. . |
const std::string& OSB_LIB::InvoiceDir::tmpExtension | ( | ) | [inline] |
Accessor to the private member tmpExtension_.
Definition at line 264 of file invoicedir.h.
References tmpExtension_.
std::string OSB_LIB::InvoiceDir::currentFile_ [private] |
Name of the current written file.
Definition at line 274 of file invoicedir.h.
Referenced by currentFile().
std::string OSB_LIB::InvoiceDir::dirBase_ [private] |
DirPathNumEntryRecord OSB_LIB::InvoiceDir::dirInfoRecord_ [static, private] |
std::vector<std::string> OSB_LIB::InvoiceDir::filesNotCommitted_ [private] |
long OSB_LIB::InvoiceDir::maxFileEntry_ [private] |
pthread_mutex_t OSB_LIB::InvoiceDir::mutex_ [static, private] |
std::ofstream OSB_LIB::InvoiceDir::os_ [private] |
int OSB_LIB::InvoiceDir::threadCounter_ [static, private] |
First thread will init the mutex.
Last thread will destroy the mutex.
Definition at line 287 of file invoicedir.h.
std::string OSB_LIB::InvoiceDir::tmpExtension_ [private] |
Temporary extension string.
Definition at line 277 of file invoicedir.h.
Referenced by tmpExtension().