generated from Trianta/cpp-unity-template
dev #7
@ -0,0 +1,40 @@
|
||||
#include "generator.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void Generator::SetArguments(int argc, char* argv[]) {
|
||||
std::string tempStr;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
tempStr.assign(argv[i]);
|
||||
if (tempStr == "-i") {
|
||||
setup.isFileSet = true;
|
||||
++i;
|
||||
setup.filename.assign(argv[i]);
|
||||
}
|
||||
if (tempStr == "-k") {
|
||||
setup.isPrefixSet = true;
|
||||
++i;
|
||||
setup.prefixLength = std::stoi(argv[i]);
|
||||
}
|
||||
if (tempStr == "-n") {
|
||||
setup.isOutputSet = true;
|
||||
++i;
|
||||
setup.outputLength = std::stoi(argv[i]);
|
||||
}
|
||||
if (tempStr == "-h") {
|
||||
PrintUsage();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
if (!setup.isFileSet) { std::cerr << "[Setup - Error] Filename not specified" << std::endl; }
|
||||
if (!setup.prefixLength) { std::cerr << "[Setup - Error] Prefix length not specified" << std::endl; }
|
||||
if (!setup.outputLength) { std::cerr << "[Setup - Error] Output length not specified" << std::endl; }
|
||||
if (!setup.isFileSet || !setup.isPrefixSet || !setup.isOutputSet) { PrintUsage(); }
|
||||
}
|
||||
|
||||
void PrintUsage(void) {
|
||||
std::cout << "Usage: markov -i input_file -k prefix_length -n output_length" << std::endl;
|
||||
std::cout << " -i: Direct path to input file for basis" << std::endl;
|
||||
std::cout << " -k: Prefix length for Markov chain" << std::endl;
|
||||
std::cout << " -n: Length of output to be generated (words)" << std::endl;
|
||||
std::cout << " -h: Prints this usage text" << std::endl;
|
||||
}
|
@ -1,13 +1,26 @@
|
||||
#ifndef GENERATOR_HPP
|
||||
#define GENERATOR_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
void PrintUsage(void);
|
||||
|
||||
struct ArgumentList {
|
||||
std::string filename = "";
|
||||
bool isFileSet = false;
|
||||
int prefixLength = 0;
|
||||
bool isPrefixSet = false;
|
||||
int outputLength = 0;
|
||||
bool isOutputSet = false;
|
||||
};
|
||||
|
||||
struct Generator {
|
||||
public:
|
||||
Generator(void);
|
||||
Generator(void) = default;
|
||||
~Generator(void) = default;
|
||||
void SetArguments(int argc, char* argv[]);
|
||||
private:
|
||||
int prefixLength = 0;
|
||||
int outputLength = 0;
|
||||
ArgumentList setup;
|
||||
};
|
||||
|
||||
#endif // !GENERATOR_HPP
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include "generator.hpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc == 1) {
|
||||
PrintUsage();
|
||||
exit(0);
|
||||
}
|
||||
Generator markovChain;
|
||||
markovChain.SetArguments(argc, argv);
|
||||
return 0;
|
||||
|
7210
test/aces-up.txt
Normal file
7210
test/aces-up.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user