c ++ – Multiline text reader

I'm trying to learn C ++ myself by writing a simple multiline text reader that indicates the length of each line. What can I do better now that I have something that "works"?

conventions:

  • variables and members are declared const, if I found that possible
  • the variables are written in camel affair
  • private members are prefixed by m_
  • members of the public are written in PascalCase

Please note that I will usually ignore comments about conventions because the style used is something I conform to in all my personal projects, in order to maintain some kind of consistency between languages. This advice is always appreciated for times when I could work in a team accustomed to a more idiomatic C ++ style.

Code:

#understand 
#understand 
#understand 
#understand 
#understand 

#define DATA_BUFFER_SIZE 4096
#define DELIMIT_CHAR & # 39;, & # 39;
#define QUOTE_CHAR "# & # 39;
#define SOURCE_FILE_PATH "C: / Users / Kittoes / OneDrive / ByteTerrace / Test Data / CSV / Validation.csv"

struct FileBuffer {
public:
char * const BufferData;
size_t const BufferLength;
FILE * const FilePointer;
size_t NumBytesRead;
size_t NumBytesUsed;

FileBuffer (char * const bufferData, size_t bufferLength, FILE * const filePointer): BufferData (bufferData), BufferLength (bufferLength), FilePointer (filePointer), NumBytesRead (0), NumBytesUsed (0) {}
};

struct LineReader {
private:
FileBuffer * const m_fileBuffer;
char const m_quoteChar;

bool FillBuffer () const {
return (m_fileBuffer-> NumBytesUsed = 0, m_fileBuffer-> NumBytesRead = fread (m_fileBuffer-> BufferData, 1, m_fileBuffer-> BufferLength, m_fileBuffer-> FilePointer));
}
NextChar char () const {
if ((m_fileBuffer-> NumBytesUsed < m_fileBuffer->NumBytesRead) || FillBuffer ()) {
return m_fileBuffer-> BufferData[m_fileBuffer->NumBytesUsed];
}
other {
return  0 & # 39 ;;
}
}

public:
LineReader (FileBuffer * const fileBuffer, char const quoteChar): m_fileBuffer (fileBuffer), m_quoteChar (quoteChar) {}

int operator () () const {
FileBuffer * const fileBuffer = m_fileBuffer;
const char * const BufferData = fileBuffer-> BufferData;
bool isQuotedSequence = false;
int lineLength = 0;
constant character quoteChar = m_quoteChar;

while ((fileBuffer-> NumBytesUsed < fileBuffer->NumBytesRead) || FillBuffer ()) {
char const currentChar = BufferData[fileBuffer->NumBytesUsed++];
lineLength ++;

if (quoteChar == currentChar) {
if (quoteChar == NextChar ()) {
lineLength ++;
fileBuffer-> NumBytesUsed ++;
}
other {
isQuotedSequence =! isQuotedSequence;
}
}

if (isQuotedSequence) {
Carry on;
}

if (& # 39;  n == currentChar) {
return lineLength;
}

if (== currentChar) {
if (### NextChar ()) {
lineLength ++;
fileBuffer-> NumBytesUsed ++;
}

return lineLength;
}
}

return ((lineLength == 0)? -1: lineLength);
}
};

int main () {
dataBuffer char[DATA_BUFFER_SIZE];
const char * const fileName = SOURCE_FILE_PATH;
FILE * FilePointer;

if (NULL! = (FilePointer = fopen (filename, "r")))) {
FileBuffer fileBuffer = FileBuffer (dataBuffer, DATA_BUFFER_SIZE, FilePointer);
LineReader const lineReader = LineReader (& fileBuffer, QUOTE_CHAR);
int result;
int totalLength = 0;

while (-1! = (result = lineReader ())) {
fprintf (stdout, "Length:% d  n", result);
total length + = result;
}

fclose (FilePointer);
fprintf (stdout, "Total length:% d  n", total length);
}
other {
fprintf (stderr, "can not open file% s:% s  n", filename, strerror (errno));
}

printf ("Press the ENTER key to continue ...  n");
getchar ();

returns 0;
}