I have different 256 character length records stored in a file. The
first character is the record identifier. I want to instantiate
different record objects. I cannot change the records stored in file as
it comes from a third party standard. I am planning to use the factory
method to create the objects.
Is there a faster way to construct this class other than the obvious
solution I am presenting below
class Record {
};
class EquityTradeRecord : public Record {
char OpId;
char TradeRefNo[12];
char SecurityId [12];
char Internal RefNo [9];
char BrokerId [9];
----------- and so on
public:
EquityTradeRecord (char *rec);
};
EquityTradeRecord::EquityTradeRecord (char *rec)
{
//First character record Id and not stored
OpId = rec[1];
strncpy (TradeRefNo, rec+2, 11);
TradeRefNo[11] = '\0';
//The fields are space padded and no null terminations
if (char *tmp = strchr (TradeRefNo, ' '))
tmp[0] = '\0';
strncpy (SecurityId, rec+13, 11);
SecurityId[11] = '\0';
//The fields are space padded and no null terminations
if (char *tmp = strchr (SecurityId, ' '))
tmp[0] = '\0';
// and so on
}