Skip to content

Commit

Permalink
put everything into a namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzziqersoftware committed Jul 28, 2024
1 parent 2130029 commit 1e2adf6
Show file tree
Hide file tree
Showing 56 changed files with 229 additions and 77 deletions.
4 changes: 4 additions & 0 deletions src/Arguments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using namespace std;

namespace phosg {

Arguments::ArgText::ArgText(std::string&& text)
: text(std::move(text)),
used(false) {}
Expand Down Expand Up @@ -71,3 +73,5 @@ void Arguments::parse(vector<string>&& args) {
}

const string Arguments::empty_string;

} // namespace phosg
18 changes: 10 additions & 8 deletions src/Arguments.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "Strings.hh"

using namespace std;
namespace phosg {

class Arguments {
public:
Expand All @@ -24,7 +24,7 @@ public:

template <typename RetT>
requires(std::is_same_v<RetT, std::string>)
std::vector<RetT> get_multi(const string& name) {
std::vector<RetT> get_multi(const std::string& name) {
std::vector<std::string> ret;
for (auto& value : this->get_values_multi(name)) {
ret.emplace_back(value.text);
Expand All @@ -34,7 +34,7 @@ public:
}
template <typename RetT>
requires(std::is_same_v<RetT, std::string>)
const RetT& get(const string& name, bool throw_if_missing = false) {
const RetT& get(const std::string& name, bool throw_if_missing = false) {
try {
auto& values = this->named.at(name);
if (values.empty()) {
Expand All @@ -47,7 +47,7 @@ public:
}
values[0].used = true;
return values[0].text;
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
if (throw_if_missing) {
throw std::out_of_range(Arguments::exc_prefix(name) + "argument is missing");
} else {
Expand All @@ -62,7 +62,7 @@ public:
auto& arg = this->positional.at(position);
arg.used = true;
return arg.text;
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
if (throw_if_missing) {
throw std::out_of_range(Arguments::exc_prefix(position) + "argument is missing");
} else {
Expand Down Expand Up @@ -155,17 +155,17 @@ private:

void parse(std::vector<std::string>&& args);

inline std::vector<ArgText>& get_values_multi(const string& name) {
inline std::vector<ArgText>& get_values_multi(const std::string& name) {
try {
return this->named.at(name);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
static std::vector<ArgText> empty_vec;
return empty_vec;
}
}

static inline std::string exc_prefix(const std::string& name) {
string ret = "(";
std::string ret = "(";
ret += name;
ret += ") ";
return ret;
Expand Down Expand Up @@ -241,3 +241,5 @@ private:
};

std::vector<std::string> split_args(const std::string& s);

} // namespace phosg
3 changes: 3 additions & 0 deletions src/ArgumentsTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "Encoding.hh"
#include "UnitTest.hh"

using namespace std;
using namespace phosg;

int main(int, char**) {
Arguments a("pos0 --named1 300 --named2=value2 4.0 --int3=40000 --float4=2.0");

Expand Down
1 change: 1 addition & 0 deletions src/BinDiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "JSON.hh"

using namespace std;
using namespace phosg;

void print_usage() {
fprintf(stderr, "\
Expand Down
4 changes: 4 additions & 0 deletions src/Containers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <unordered_set>
#include <vector>

namespace phosg {

template <typename V>
std::vector<V> set_to_vec(const std::set<V>& s) {
std::vector<V> ret;
Expand Down Expand Up @@ -83,3 +85,5 @@ std::vector<K> map_values_to_vec(const std::unordered_map<K, V>& s) {
}
return ret;
}

} // namespace phosg
4 changes: 4 additions & 0 deletions src/Encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using namespace std;

namespace phosg {

const char* DEFAULT_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const char* URLSAFE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";

Expand Down Expand Up @@ -131,3 +133,5 @@ string rot13(const void* vdata, size_t size) {
}
return ret;
}

} // namespace phosg
4 changes: 4 additions & 0 deletions src/Encoding.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "Platform.hh"
#include "Types.hh"

namespace phosg {

template <typename T>
constexpr uint8_t bits_for_type = sizeof(T) << 3;

Expand Down Expand Up @@ -465,3 +467,5 @@ std::string base64_decode(const void* data, size_t size, const char* alphabet =
std::string base64_decode(const std::string& data, const char* alphabet = nullptr);

std::string rot13(const void* data, size_t size);

} // namespace phosg
2 changes: 2 additions & 0 deletions src/EncodingTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "Encoding.hh"
#include "UnitTest.hh"

using namespace phosg;

int main(int, char**) {
expect_eq(0x0000, (sign_extend<uint16_t, uint8_t>(0x00)));
expect_eq(0x0001, (sign_extend<uint16_t, uint8_t>(0x01)));
Expand Down
Loading

0 comments on commit 1e2adf6

Please sign in to comment.