MCPcopy Create free account
hub / github.com/dhbloo/rapfi / database

Method database

Rapfi/command/database.cpp:251–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249} // namespace
250
251void Command::database(int argc, char *argv[])
252{
253 std::unique_ptr<DBStorage> dbStorage;
254 std::istringstream commandStream;
255
256 auto options = makeDBCreationOptions("rapfi database");
257 options.add_options() //
258 ("commands",
259 "Database commands (seperate multiple commands with ';')",
260 cxxopts::value<std::string>()->default_value("")) //
261 ("h,help", "Print database usage");
262
263 try {
264 auto args = options.parse(argc, argv);
265
266 if (args.count("help")) {
267 std::cout << options.help() << std::endl;
268 std::exit(EXIT_SUCCESS);
269 }
270
271 { // Load database command sequences
272 std::string commands = args["commands"].as<std::string>();
273 std::replace(commands.begin(), commands.end(), ';', '\n');
274 if (!commands.empty()) {
275 commands.push_back('\n');
276 commandStream = std::istringstream(std::move(commands));
277 }
278 }
279
280 dbStorage = createDBStorage(args);
281 }
282 catch (const std::exception &e) {
283 ERRORL("database command: " << e.what());
284 std::exit(EXIT_FAILURE);
285 }
286
287 std::istream &is =
288 commandStream.peek() == std::istringstream::traits_type::eof() ? std::cin : commandStream;
289 std::unique_ptr<Board> board = std::make_unique<Board>(15);
290 Rule rule = FREESTYLE;
291
292 for (;;) {
293 std::string cmd;
294 is >> cmd;
295
296 // Stop the command loop when reaching EOF
297 if (is.eof())
298 break;
299 else if (!is)
300 is.clear();
301
302 upperInplace(cmd);
303
304 if (cmd == "QUIT")
305 break;
306 else if (cmd == "PUTBOARD") {
307 std::string ruleStr;
308 std::string posStr;

Callers

nothing calls this directly

Calls 15

makeDBCreationOptionsFunction · 0.85
createDBStorageFunction · 0.85
constructDBKeyFunction · 0.85
printDBQueryFunction · 0.85
parseDBRecordFunction · 0.85
parseDBKeyFunction · 0.85
databaseToCSVFileFunction · 0.85
nowFunction · 0.85
importLibToDatabaseFunction · 0.85
add_optionsMethod · 0.80
default_valueMethod · 0.80

Tested by

no test coverage detected