Skip to content

Commit c87575c

Browse files
authored
Merge pull request #8 from SPauly/bug6
fixed #6
2 parents 46ae080 + d112293 commit c87575c

File tree

5 files changed

+50
-41
lines changed

5 files changed

+50
-41
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "(gdb) Starten",
99
"type": "cppdbg",
1010
"request": "launch",
11-
"program": "${workspaceFolder}/.vscode/GetIntoCPPAgain.exe",
11+
"program": "${workspaceFolder}/GetIntoCPPAgain.exe",
1212
"args": [],
1313
"stopAtEntry": true,
1414
"cwd": "${fileDirname}",

GetIntoCPPAgain.exe

13.2 KB
Binary file not shown.

src/CSVParser.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,35 @@ namespace csv
44
{
55
//class Row
66

7-
Row::Row(std::string_view _row){
7+
Row::Row(std::string_view _row)
8+
{
89
m_StartIterator = 0;
910
m_ItemIteratorPos = 0;
10-
11+
1112
do
1213
{
1314
m_ItemIteratorPos = _row.find_first_of(",", m_StartIterator);
14-
m_data.push_back(_row.substr(m_StartIterator, m_ItemIteratorPos-m_StartIterator));
15+
m_data.push_back(std::string(_row.substr(m_StartIterator, m_ItemIteratorPos - m_StartIterator)));
1516
m_StartIterator = m_ItemIteratorPos + 1;
1617
} while (m_ItemIteratorPos != std::string::npos);
17-
1818
};
1919

2020
Row::~Row(){};
2121

2222
void Row::add_value(std::string_view _value){
23-
m_data.push_back(_value);
23+
m_data.push_back(std::string(_value));
2424
};
2525

26-
std::string_view Row::getvalue(_HEADER_TYPE& _header) const {
26+
std::string_view Row::getvalue(_HEADER_TYPE &_header) const
27+
{
2728
return m_data.at(_header);
2829
};
2930
//end class Row
3031

3132
//class Header : public Row
32-
33-
Header::Header(std::string_view _row) : Row(_row)
34-
{
33+
34+
Header::Header(std::string_view _row) : Row(_row)
35+
{
3536
_header_size = m_data.size();
3637
_header_ptr = m_data.data();
3738
};
@@ -45,15 +46,16 @@ namespace csv
4546
//open csv file
4647
m_INPUT_FILE.open(*PATH_ptr, std::ios::out);
4748
m_INPUT_FILE.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit);
48-
49+
4950
//init header of file
50-
std::string* tmp_line = new std::string;
51+
std::string *tmp_line = new std::string;
5152
tmp_line->clear();
5253
std::getline(m_INPUT_FILE, *tmp_line);
5354
_ptr_header = new Header(*tmp_line);
5455

5556
//init m_content
56-
while(m_INPUT_FILE.good()){
57+
while (m_INPUT_FILE.good())
58+
{
5759
tmp_line->clear();
5860
std::getline(m_INPUT_FILE, *tmp_line);
5961
m_content.push_back(Row(*tmp_line));
@@ -73,22 +75,26 @@ namespace csv
7375
_csvgood = false;
7476
}
7577

76-
#ifdef _DEBUG
77-
void CSVParser::print_csv(){
78-
for(_HEADER_TYPE i = 0; i < _ptr_header->_header_size; i++ ){
79-
std::cout<<_ptr_header->getvalue(i);
80-
std::cout<<",";
78+
#ifdef _DEBUG
79+
void CSVParser::print_csv()
80+
{
81+
for (_HEADER_TYPE i = 0; i < _ptr_header->_header_size; i++)
82+
{
83+
std::cout << _ptr_header->getvalue(i);
84+
std::cout << ",";
8185
}
82-
std::cout<<std::endl;
83-
for(_HEADER_TYPE i = 0; i < m_content.size(); i++){
84-
for(_HEADER_TYPE i2 = 0; i2 < _ptr_header->_header_size; i2++ ){
85-
std::cout<<m_content.at(i2).getvalue(i);
86-
std::cout<<",";
86+
std::cout << std::endl;
87+
for (_HEADER_TYPE i = 0; i < m_content.size(); i++)
88+
{
89+
for (_HEADER_TYPE i2 = 0; i2 < _ptr_header->_header_size; i2++)
90+
{
91+
std::cout << m_content.at(i).getvalue(i2);
92+
std::cout << ",";
8793
}
88-
std::cout<<std::endl;
94+
std::cout << std::endl;
8995
}
9096
}
91-
#endif
97+
#endif
9298
//end CSVParser
9399

94100
} // namespace csv

src/CSVParser.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,60 @@
33
#include <string_view>
44
#include <fstream>
55
#include <vector>
6+
7+
#ifdef _DEBUG
68
#include <iostream>
9+
#endif
710

811
#define _DEBUG
912

1013
namespace csv
1114
{
1215
using _HEADER_TYPE = signed int;
1316

14-
class Row
17+
class Row
1518
{
1619
public:
17-
Row()= delete;
20+
Row() = delete;
1821
Row(std::string_view);
1922
~Row();
2023

2124
void add_value(std::string_view);
22-
std::string_view getvalue(_HEADER_TYPE&) const;
25+
std::string_view getvalue(_HEADER_TYPE &) const;
26+
2327
protected:
24-
std::vector<std::string_view> m_data;
28+
std::vector<std::string> m_data;
29+
2530
private:
2631
std::string::size_type m_StartIterator;
2732
std::string::size_type m_ItemIteratorPos;
2833
};
2934

30-
class Header : public Row {
35+
class Header : public Row
36+
{
3137
public:
3238
Header() = delete;
3339
Header(std::string_view);
3440

35-
public:
41+
public:
3642
_HEADER_TYPE _header_size;
37-
std::string_view* _header_ptr;
38-
43+
std::string *_header_ptr;
3944
};
4045

41-
4246
class CSVParser
4347
{
4448
public:
4549
CSVParser() = delete;
46-
CSVParser(const std::string*);
50+
CSVParser(const std::string *);
4751
~CSVParser();
4852

49-
//create debug print function here
50-
#ifdef _DEBUG
53+
#ifdef _DEBUG
5154
void print_csv();
52-
#endif
53-
55+
#endif
56+
5457
public:
5558
bool _csvgood;
56-
Header* _ptr_header;
59+
Header *_ptr_header;
5760

5861
private:
5962
std::ifstream m_INPUT_FILE;

src/login.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class User { //holds the user and is responsible for login, logout and activity
88
private:
99
csv::CSVParser *mptr_csv_parser; //stores one csv parser for all instances
1010
bool m_login_flag = false; //flag to indicate wheather user is logged in or not
11-
bool m_user_request(const std::string *, const std::string *); //deals with authentification of the user
11+
bool m_user_request(const std::string* , const std::string* ); //deals with authentification of the user
1212
public:
1313
User();
1414
~User();

0 commit comments

Comments
 (0)