VR-Exchange 2.2 API Documentation
include/broker/csvFileRdr.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 *********************************************************************/
5 #pragma once
6 
7 #include <fstream>
8 
9 #include <vl/hostStructs.h>
10 #include <vlutil/vlFilename.h>
11 
12 
13 // trainerutil
14 // need creator fcn typedef
15 #include "broker/csvFileEntry.h"
16 
17 class DtCsvFileReader;
18 
19 // class DtCsvFileReader:
20 // Reads in and parses a csv file. Children classes will hold the parsed entries in sorted lists or
21 // hash lists.
22 
23 // to use:
24 // a. construct
25 // b. open a stream.
26 // c. read and parse lines
27 // d. close
28 // e. destruct
29 
30 typedef DtCsvFileReader* (*DtCsvFileReaderCreatorFcn)();
31 
32 class DT_DLL_BROKER DtCsvFileReader
33 {
34 public:
35 
36  // default constructor
38 
39  // Full-featured constructor
40  DtCsvFileReader(const DtString & fileName);
41 
42 private:
43 
44  // copy constructor
45  DtCsvFileReader(const DtCsvFileReader& orig);
46 
47  // assignment operator
48  DtCsvFileReader& operator=(const DtCsvFileReader& orig);
49 
50 public:
51  // destructor
52  virtual ~DtCsvFileReader();
53 
54  // virtual bool openStream(const DtString & fileName);
55  virtual bool openStream();
56  virtual bool openStream(const DtString & fileName);
57  virtual void closeStream();
58 
59  // status
60  virtual bool isEOF() const;
61  virtual bool isOpen();
62 
63  // name
64  virtual void setFilename(const DtString& name);
65  virtual const DtString& filename() const;
66 
67  // Fills up line with a row from the table
68 
69  virtual bool readLine( DtString& line );
70 
71  // Used to read and parse the rest of the table.
72  // Derived Readers should create a derived DtCsvFileEntry
73  // and pass that into parseLine.
74  // The default simply reads a line and returns a generic
75  // DtCsvFileEntry, containing a list of token strings.
76  virtual DtCsvFileEntry* readAndParseNextLine(
77  DtCsvFileEntryCreatorFcn pEntryCreatorFcn);
78 
79  // Parses the line and stores data in the entry
80  virtual void parseLine(DtCsvFileEntry* pEntry,DtString& line );
81 
82  // static creator fcns
83 public:
84  static DtCsvFileReader* creator();
85 
86 
87 
88 protected:
89 
90  DtFilename myFilename;
91  std::ifstream myInfile;
92 
93 };
94 
95 

Document ID: Generated on Mon Apr 15 17:15:50 EDT 2013 from SVN revision 126154
Copyright © 2005-2012 VT MÄK. All Rights Reserved (www.mak.com)