OSB_LIB::InvoiceDir Class Reference

Collaboration diagram for OSB_LIB::InvoiceDir:

Collaboration graph
[legend]
List of all members.

Detailed Description

InvoiceDir is used to store invoices on the file system.

This class provides a mechanism to store invoices in a directory tree. The structure of the tree is as follows:

  1. User defined base directory where all invoices will be kept.
  2. User defined layers of sorting directories.
  3. A directory named with a sequential number.
  4. The invoices are stored in these sequence directories.

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.

Public Member Functions

Private Member Functions

Private Attributes

Static Private Attributes


Constructor & Destructor Documentation

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.

Parameters:
basePath Base directory (absolute path) of the invoice storage tree.
maxEntry Maximum entry allowed in one directory.


Member Function Documentation

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.

Parameters:
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.

Parameters:
dirPath Relative path where invoices will be stored.
fileName File system name for the invoice.
Returns:
The ostream created with this function is returned.

const std::string& OSB_LIB::InvoiceDir::currentFile (  )  [inline]

Accessor to the private member currentFile_.

Returns:
const string ref 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.

Parameters:
i Long integer wanted to be transformed.
Returns:
String object of the input long integer value.

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.

Parameters:
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.

Parameters:
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_.

Returns:
const string ref to the private member tmpExtension_.

Definition at line 264 of file invoicedir.h.

References tmpExtension_.


Member Data Documentation

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]

Base directory that all invoices are kept.

Definition at line 268 of file invoicedir.h.

DirPathNumEntryRecord OSB_LIB::InvoiceDir::dirInfoRecord_ [static, private]

Keeping the information of all invoice directories.

Definition at line 293 of file invoicedir.h.

std::vector<std::string> OSB_LIB::InvoiceDir::filesNotCommitted_ [private]

Keeping the name of all unconfirmed files.

Definition at line 280 of file invoicedir.h.

long OSB_LIB::InvoiceDir::maxFileEntry_ [private]

Maximum number of files in one directory.

Definition at line 271 of file invoicedir.h.

pthread_mutex_t OSB_LIB::InvoiceDir::mutex_ [static, private]

Protect the shared directory map.

Definition at line 290 of file invoicedir.h.

std::ofstream OSB_LIB::InvoiceDir::os_ [private]

ofstream that is for the user application to write to.

Definition at line 283 of file invoicedir.h.

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().


The documentation for this class was generated from the following file:
Generated on Sat Sep 2 14:10:20 2006 for OSB Library by  doxygen 1.4.7