-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubeReader.cpp
More file actions
100 lines (63 loc) · 1.64 KB
/
Copy pathCubeReader.cpp
File metadata and controls
100 lines (63 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "CubeReader.h"
CubeReader::CubeReader()
{
//ctor
}
CubeReader::~CubeReader()
{
//dtor
}
std::vector<std::string> CubeReader::operator()( std::vector< std::string > &vr )
{
std::size_t swp = 0;
std::vector< std::string > cube;
std::string str;
std::string temp;
int number;
for ( int i = 0; i < vr.size(); i++ )
{
str = vr[ i ];
swp = str.find( "\"" );
//std::cout << str << std::endl;
if ( swp != std::string::npos )
{
str.erase( swp, 1 );
swp = str.find( "\"" );
temp.assign( str, 0, swp );
str.erase( 0, swp+1 );
for ( int i = 0; i < 4; i++ )
{
swp = str.find( "," );
str.erase( 0, swp + 1 );
}
swp = str.find( "," );
str.erase( swp, std::string::npos );
temp += ";" + str;
cube.push_back( temp );
}
}
return cube;
}
std::vector<std::string> CubeReader::read(std::string filename)
{
///std::vector<Card> vCards;
std::vector< std::string > cube;
std::size_t swp = 0;
std::string str;
std::string temp;
int number;
std::ifstream infile;
infile.open(filename);
while(getline(infile,str))
{
if ( *str.begin() == '"' )
cube.push_back( str ); ///Write to cube1. unedited.
}
infile.close();
///Shuffle deck:
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gt ( seed );
srand ( gt() );
std::random_shuffle( cube.begin(), cube.end() );
return cube;
}