| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /*
- Copyright (c) 2019 tevador
- This file is part of RandomX.
- RandomX is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- RandomX is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with RandomX. If not, see<http://www.gnu.org/licenses/>.
- */
- #pragma once
- #include <cstring>
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- constexpr char hexmap[] = "0123456789abcdef";
- inline void outputHex(std::ostream& os, const char* data, int length) {
- for (int i = 0; i < length; ++i) {
- os << hexmap[(data[i] & 0xF0) >> 4];
- os << hexmap[data[i] & 0x0F];
- }
- }
- inline void dump(const char* buffer, uint64_t count, const char* name) {
- std::ofstream fout(name, std::ios::out | std::ios::binary);
- fout.write(buffer, count);
- fout.close();
- }
- inline void readOption(const char* option, int argc, char** argv, bool& out) {
- for (int i = 0; i < argc; ++i) {
- if (strcmp(argv[i], option) == 0) {
- out = true;
- return;
- }
- }
- out = false;
- }
- inline void readIntOption(const char* option, int argc, char** argv, int& out, int defaultValue) {
- for (int i = 0; i < argc - 1; ++i) {
- if (strcmp(argv[i], option) == 0 && (out = atoi(argv[i + 1])) > 0) {
- return;
- }
- }
- out = defaultValue;
- }
- inline void readInt(int argc, char** argv, int& out, int defaultValue) {
- for (int i = 0; i < argc; ++i) {
- if (*argv[i] != '-' && (out = atoi(argv[i])) > 0) {
- return;
- }
- }
- out = defaultValue;
- }
|