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 | #ifndef GENERATOR_HPP | ||||||
| #define 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 { | struct Generator { | ||||||
| public: | public: | ||||||
|     Generator(void); |     Generator(void) = default; | ||||||
|  |     ~Generator(void) = default; | ||||||
|     void SetArguments(int argc, char* argv[]); |     void SetArguments(int argc, char* argv[]); | ||||||
| private: | private: | ||||||
|     int prefixLength = 0; |     ArgumentList setup; | ||||||
|     int outputLength = 0; |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| #endif // !GENERATOR_HPP
 | #endif // !GENERATOR_HPP
 | ||||||
|  | |||||||
| @ -1,6 +1,10 @@ | |||||||
| #include "generator.hpp" | #include "generator.hpp" | ||||||
| 
 | 
 | ||||||
| int main(int argc, char* argv[]) { | int main(int argc, char* argv[]) { | ||||||
|  |     if (argc == 1) {  | ||||||
|  |         PrintUsage();  | ||||||
|  |         exit(0);  | ||||||
|  |     } | ||||||
|     Generator markovChain; |     Generator markovChain; | ||||||
|     markovChain.SetArguments(argc, argv); |     markovChain.SetArguments(argc, argv); | ||||||
|     return 0; |     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