Skip to content

Commit

Permalink
Add ashuffle namespace to everything.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkunz committed Apr 25, 2020
1 parent df90f32 commit c5d46e6
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "args.h"
#include "rule.h"

namespace ashuffle {
namespace {

constexpr char kHelpMessage[] =
Expand Down Expand Up @@ -265,3 +266,5 @@ std::variant<Options, ParseError> Options::Parse(
}

void PrintHelp(FILE* output) { fputs(kHelpMessage, output); }

} // namespace ashuffle
4 changes: 4 additions & 0 deletions src/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "rule.h"

namespace ashuffle {

struct ParseError {
enum Type {
kUnknown, // Initial error type, unknown error.
Expand Down Expand Up @@ -59,4 +61,6 @@ class Options {
// Print the help message on the given output stream.
void PrintHelp(FILE *output_stream);

} // namespace ashuffle

#endif
4 changes: 4 additions & 0 deletions src/ashuffle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void Die(Args... strs) {

} // namespace

namespace ashuffle {

/* 25 seconds is the default timeout */
static const int TIMEOUT = 25000;

Expand Down Expand Up @@ -502,3 +504,5 @@ struct mpd_connection *ashuffle_connect(const Options &options,
}
return mpd;
}

} // namespace ashuffle
5 changes: 5 additions & 0 deletions src/ashuffle.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "rule.h"
#include "shuffle.h"

namespace ashuffle {

extern const int WINDOW_SIZE;

// `MPD_PORT` environment variables. If a password is needed, no password can
Expand Down Expand Up @@ -44,4 +46,7 @@ struct shuffle_test_delegate {
// NULL during normal operations.
int shuffle_loop(struct mpd_connection* mpd, ShuffleChain* songs,
const Options& options, struct shuffle_test_delegate*);

} // namespace ashuffle

#endif
4 changes: 4 additions & 0 deletions src/getpass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void SetEcho(FILE *stream, bool echo_state, bool echo_nl_state) {

} // namespace

namespace ashuffle {

std::string GetPass(FILE *in_stream, FILE *out_stream,
std::string_view prompt) {
if (fwrite(prompt.data(), prompt.size(), 1, out_stream) != 1) {
Expand Down Expand Up @@ -63,3 +65,5 @@ std::string GetPass(FILE *in_stream, FILE *out_stream,

return result;
}

} // namespace ashuffle
4 changes: 4 additions & 0 deletions src/getpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
#include <string>
#include <string_view>

namespace ashuffle {

// GetPass obtains a password from the user. It writes the given prompt to
// `out_stream` and then waits for the user to type a line on `in_stream`
// which is then returned. Terminal echoing is disabled while the user is
// writing their password, to add additional privacy.
std::string GetPass(FILE *in_stream, FILE *out_stream, std::string_view prompt);

} // namespace ashuffle

#endif
2 changes: 2 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "ashuffle.h"
#include "shuffle.h"

using namespace ashuffle;

int main(int argc, const char *argv[]) {
std::variant<Options, ParseError> parse = Options::ParseFromC(argv, argc);
if (ParseError *err = std::get_if<ParseError>(&parse); err != nullptr) {
Expand Down
6 changes: 5 additions & 1 deletion src/rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "rule.h"

namespace ashuffle {

Rule::Status Rule::AddPattern(const std::string &field, std::string value) {
Pattern p;
p.tag = mpd_tag_name_iparse(field.data());
Expand All @@ -20,7 +22,7 @@ Rule::Status Rule::AddPattern(const std::string &field, std::string value) {
return Status::kOK;
}

bool Rule::Accepts(const struct mpd_song *song) const {
bool Rule::Accepts(const struct ::mpd_song *song) const {
assert(type_ == Rule::Type::kExclude &&
"only exclusion rules are supported");
for (const Pattern &p : patterns_) {
Expand All @@ -45,3 +47,5 @@ bool Rule::Accepts(const struct mpd_song *song) const {
}
return true;
}

} // namespace ashuffle
5 changes: 5 additions & 0 deletions src/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#include <string>
#include <vector>

#include <mpd/song.h>
#include <mpd/tag.h>

namespace ashuffle {

// Internal API.
struct Pattern {
enum mpd_tag_type tag;
Expand Down Expand Up @@ -58,4 +61,6 @@ class Rule {
Type type_;
};

} // namespace ashuffle

#endif
4 changes: 4 additions & 0 deletions src/shuffle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "shuffle.h"

namespace ashuffle {

void ShuffleChain::Empty() {
_window.clear();
_pool.clear();
Expand Down Expand Up @@ -39,3 +41,5 @@ std::vector<std::string> ShuffleChain::Items() {
items.insert(items.end(), _pool.begin(), _pool.end());
return items;
}

} // namespace ashuffle
4 changes: 4 additions & 0 deletions src/shuffle.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string>
#include <vector>

namespace ashuffle {

class ShuffleChain {
public:
// By default, create a new shuffle chain with a window-size of 1.
Expand Down Expand Up @@ -39,4 +41,6 @@ class ShuffleChain {
std::deque<std::string> _pool;
};

} // namespace ashuffle

#endif
2 changes: 2 additions & 0 deletions t/args_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "t/helpers.h"
#include "t/mpdclient_fake.h"

using namespace ashuffle;

template <typename... Args>
std::optional<ParseError> ParseOnly(Args... strs) {
std::vector<std::string> args = {strs...};
Expand Down
2 changes: 2 additions & 0 deletions t/ashuffle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "t/helpers.h"
#include "t/mpdclient_fake.h"

using namespace ashuffle;

void xclearenv() {
if (clearenv()) {
perror("xclearenv");
Expand Down
2 changes: 2 additions & 0 deletions t/rule_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "t/helpers.h"
#include "t/mpdclient_fake.h"

using namespace ashuffle;

static void test_basic() {
Rule rule;

Expand Down
2 changes: 2 additions & 0 deletions t/shuffle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "shuffle.h"

using namespace ashuffle;

void test_basic() {
ShuffleChain chain;
std::string test_str("test");
Expand Down

0 comments on commit c5d46e6

Please sign in to comment.