I am using this struct to store data from a text file
Code:
struct sItem
{
short unsigned int Number;
sDate Date;
std::string Name;
std::string Memo;
std::string MainCatagory;
std::string SubCatagory;
long double Amount;
std::string Type;
};
the file uses tags to determine what data member each line belongs to like this : (CODE_TAG)(DATA)
Code:
<STMTTRN>
<TRNTYPE>DTSF
<DTPOSTED>20080331
<TRNAMT>1211.65
<NAME>SUBDT-TR
<MEMO>8105T
</STMTTRN>
Each line in the file is saved to a std::string and the tag is extracted to determine which data member the line should be saved to.
Code:
do {
read line into std::string temp;
extract first part of line into std::string Code_Tag;
extract the rest of the line into std::string Data;
using Code_Tag, determine what Data is and save it to the approperiate sItem member;
} while (NOT EOF)
I'm just not sure of the best method to do this. I could use a bunch of if...then statements like this
Code:
if (Code_Tag == "TRNTYPE") Item.Type = data;
if (Code_Tag == "NAME") Item.Name = data;
...
But I don't like the way that looks, and it seems like there would be too much over head with all the 'if...then' tests.
I could use a switch...case statement but VC Toolkit 2003 will not let me switch a std::string.
I have also tried enumerating the code tags like this
Code:
typedef enum CODE_TAGS
{
TAG_START = 0xff01,
TAG_TYPE = 0xff02,
TAG_DATE = 0xff03,
TAG_AMOUNT = 0xff04,
TAG_NAME = 0xff05,
TAG_MEMO = 0xff06,
TAG_ITEMNUM = 0xff07,
TAG_END = 0xff08
};
and just switching that, but then I have to convert each line from the std::string to the enum value. This seems to be just as much of a pain as the first idea.
Any thoughts / ideas on what the best way would be to go about doing this?