Skip to content

Commit

Permalink
further namespace updates
Browse files Browse the repository at this point in the history
  • Loading branch information
astro-friedel committed Nov 1, 2023
1 parent a667569 commit 0f0de1d
Show file tree
Hide file tree
Showing 30 changed files with 119 additions and 121 deletions.
2 changes: 0 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
* Re-structure so that top namespace in C++ is YggInterface
* Move C++ interface into src directory
* Automated documentation using doxygen
* Fill in missing docs
* Fix handling of multiple connections in ZMQ socket (restricted to ZMQ_PAIR to simplify testing)
Expand Down
2 changes: 1 addition & 1 deletion src/YggInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "datatypes/dtype_t.h"

// TODO: Allow use of ygglog_error as function in C
using namespace communication::utils;
using namespace YggInterface::utils;

#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/YggInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define WITH_GLOBAL_SCOPE(COMM) global_scope_comm_on(); COMM; global_scope_comm_off()


using namespace communication::communicator;
using namespace YggInterface::communicator;

/*!
@brief Input communicator that can be used to receive messages from
Expand Down
2 changes: 1 addition & 1 deletion src/rapidjson
2 changes: 1 addition & 1 deletion src/utils/Address.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Address.hpp"
#include <algorithm>

using namespace communication::utils;
using namespace YggInterface::utils;

Address::Address(const std::string &adr): _key(-1), _valid(false) {
address(adr);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define COMM_ADDRESS_SIZE 500

namespace communication {
namespace YggInterface {
namespace utils {
static std::string blank;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/logging.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "logging.hpp"
#include "tools.hpp"

namespace communication {
namespace YggInterface {
namespace utils {

int YggdrasilLogger::_ygg_error_flag = 0;
Expand Down
18 changes: 9 additions & 9 deletions src/utils/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#endif
#endif

namespace communication {
namespace YggInterface {
namespace utils {

class YggdrasilLogger {
Expand Down Expand Up @@ -50,12 +50,12 @@ namespace utils {
}
}

#define ygglog_error communication::utils::YggdrasilLogger("ERROR", 40, true)
#define ygglog_info communication::utils::YggdrasilLogger("INFO", 20)
// #define ygglog_debug communication::utils::YggdrasilLogger("DEBUG", 10)
#define ygglog_debug communication::utils::YggdrasilLogger("DEBUG", 40)
#define ygglog_error YggInterface::utils::YggdrasilLogger("ERROR", 40, true)
#define ygglog_info YggInterface::utils::YggdrasilLogger("INFO", 20)
// #define ygglog_debug YggInterface::utils::YggdrasilLogger("DEBUG", 10)
#define ygglog_debug YggInterface::utils::YggdrasilLogger("DEBUG", 40)

#define ygglog_error_c(...) ygglog_error << communication::utils::string_format(__VA_ARGS__) << std::endl
#define ygglog_debug_c(...) ygglog_debug << communication::utils::string_format(__VA_ARGS__) << std::endl
#define ygglog_info_c(...) ygglog_info << communication::utils::string_format(__VA_ARGS__) << std::endl
#define ygglog_throw_error_c(...) communication::utils::ygglog_throw_error(communication::utils::string_format(__VA_ARGS__))
#define ygglog_error_c(...) ygglog_error << YggInterface::utils::string_format(__VA_ARGS__) << std::endl
#define ygglog_debug_c(...) ygglog_debug << YggInterface::utils::string_format(__VA_ARGS__) << std::endl
#define ygglog_info_c(...) ygglog_info << YggInterface::utils::string_format(__VA_ARGS__) << std::endl
#define ygglog_throw_error_c(...) YggInterface::utils::ygglog_throw_error(YggInterface::utils::string_format(__VA_ARGS__))
2 changes: 1 addition & 1 deletion src/utils/regex.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <memory>
#include "regex.hpp"

namespace communication {
namespace YggInterface {
namespace utils {

/*!
Expand Down
2 changes: 1 addition & 1 deletion src/utils/regex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <iostream>
#define FMT_LEN 100

namespace communication {
namespace YggInterface {
namespace utils {

size_t find_match(const std::regex &regex, const std::string &to_match,
Expand Down
12 changes: 6 additions & 6 deletions src/utils/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ extern "C" {
}
#endif // RAPIDJSON_FORCE_IMPORT_ARRAY
// #endif // RAPIDJSON_YGGDRASIL_PYTHON
using namespace communication::utils;
using namespace YggInterface::utils;

int communication::utils::split_head_body(const char *buf,
int YggInterface::utils::split_head_body(const char *buf,
const char **head,
size_t *headsiz) {
// Split buffer into head and body
Expand Down Expand Up @@ -63,7 +63,7 @@ int communication::utils::split_head_body(const char *buf,
}

template <typename ValueT>
std::string communication::utils::document2string(ValueT& rhs,
std::string YggInterface::utils::document2string(ValueT& rhs,
const char* indent) {
rapidjson::StringBuffer sb;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb, 0, strlen(indent));
Expand All @@ -72,7 +72,7 @@ std::string communication::utils::document2string(ValueT& rhs,
return std::string(sb.GetString());
}

long communication::utils::copyData(char*& dst, const size_t dst_len,
long YggInterface::utils::copyData(char*& dst, const size_t dst_len,
const char* src, const size_t src_len,
bool allow_realloc) {
if ((src_len + 1) > dst_len) {
Expand Down Expand Up @@ -791,7 +791,7 @@ Header::Header(bool own_data) :
}
}
Header::Header(const char* buf, const size_t &len,
communication::communicator::Comm_t* comm) :
YggInterface::communicator::Comm_t* comm) :
Header() {
Metadata* meta = NULL;
int comm_flags = 0;
Expand Down Expand Up @@ -935,7 +935,7 @@ long Header::copyData(const char* msg, const size_t msg_siz) {
} else {
bool allow_realloc = ((flags & HEAD_FLAG_ALLOW_REALLOC) &&
(offset == 0));
ret = communication::utils::copyData(dst, size_buff - offset,
ret = YggInterface::utils::copyData(dst, size_buff - offset,
msg, msg_siz, allow_realloc);
if (allow_realloc && ((ret + 1) > static_cast<long>(size_buff))) {
data[0] = dst;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
static_cast<rapidjson::SizeType>(strlen(var))


namespace communication {
namespace YggInterface {
namespace communicator {
class Comm_t;
}
}


namespace communication {
namespace YggInterface {
namespace utils {

/*!
Expand Down Expand Up @@ -194,7 +194,7 @@ class Header : public Metadata {
public:
Header(bool own_data=false);
Header(const char* buf, const size_t &len,
communication::communicator::Comm_t* comm);
YggInterface::communicator::Comm_t* comm);
Header(char*& buf, const size_t &len, bool allow_realloc);
~Header() override;
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "tools.hpp"

#define YGG_THREAD_MUTEX(name) \
std::mutex communication::utils::name ## _mutex;
std::mutex YggInterface::utils::name ## _mutex;
YGG_THREAD_MUTEX(init)
YGG_THREAD_MUTEX(clean)
YGG_THREAD_MUTEX(client)
Expand Down
6 changes: 3 additions & 3 deletions src/utils/tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

#include "logging.hpp"

namespace communication {
namespace YggInterface {
namespace utils {

// template<typename T, std::enable_if_t<!std::is_floating_point<T>::value &&
Expand Down Expand Up @@ -290,11 +290,11 @@ static int global_thread_id = -1;
#define YGG_THREADING_ACTIVE 1
#define YGG_THREAD_SAFE_BEGIN(name) \
_Pragma(STRINGIFY(omp critical (name))) { \
const std::lock_guard<std::mutex> name ## _lock(communication::utils::name ## _mutex);
const std::lock_guard<std::mutex> name ## _lock(YggInterface::utils::name ## _mutex);
#else // _OPENMP
#define YGG_THREAD_SAFE_BEGIN(name) \
{ \
const std::lock_guard<std::mutex> name ## _lock(communication::utils::name ## _mutex);
const std::lock_guard<std::mutex> name ## _lock(YggInterface::utils::name ## _mutex);
#endif // _OPENMP
#define YGG_THREAD_SAFE_END \
}
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void init_sublib_contents() {
void init_sublib_contents() {}
#endif

namespace communication {
namespace YggInterface {
namespace mock {

#ifdef ELF_AVAILABLE
Expand Down
10 changes: 5 additions & 5 deletions test/unittest/mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ extern char sublib_contents[256];
#endif

#define ELFHOOK(x) elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), #x, \
(void*)communication::mock::x);
(void*)YggInterface::mock::x);
#define ELFHOOK_ALT(x) elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), #x, \
(void*)communication::mock::alt_ ## x);
(void*)YggInterface::mock::alt_ ## x);

#define ELFHOOK_PARAM(x, y) elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), #x, \
(void*)communication::mock::y);
(void*)YggInterface::mock::y);
#define ELFREVERT(x,y) y = elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), #x, y);

#define ELFHOOK_ARGS(x, a) elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), std::string(#x) + "|" + std::string(#a), \
(void*)communication::mock::x);
(void*)YggInterface::mock::x);

#define ELFREVERT_ARGS(x, a, y) y = elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), std::string(#x) + "|" + std::string(#a), \
y);
Expand Down Expand Up @@ -74,7 +74,7 @@ extern char sublib_contents[256];
ELFREVERT(func ## _orig, dummy_func_ ## func); \
ELFREVERT(func, *original_func_ ## func)

namespace communication {
namespace YggInterface {
namespace mock {

#ifdef ELF_AVAILABLE
Expand Down
22 changes: 11 additions & 11 deletions test/unittest/tests/communicators/clientcommtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#ifdef COMM_BASE

using namespace communication;
using namespace communication::communicator;
using namespace communication::mock;
using namespace YggInterface;
using namespace YggInterface::communicator;
using namespace YggInterface::mock;

namespace communication {
namespace YggInterface {
namespace testing {
class ClientComm_tester : public ClientComm {
private:
Expand Down Expand Up @@ -96,21 +96,21 @@ class ClientComm_tester : public ClientComm {

TEST(ClientComm, constructor) {
std::string name = "MyComm";
communication::testing::ClientComm_tester cc(name);
communication::testing::ClientComm_tester cc1("");
YggInterface::testing::ClientComm_tester cc(name);
YggInterface::testing::ClientComm_tester cc1("");
}

TEST(ClientComm, send) {
std::string name = "MyComm";
communication::testing::ClientComm_tester cc(name);
YggInterface::testing::ClientComm_tester cc(name);
std::string msg = "This is a test message";
EXPECT_TRUE(cc.addSignon());
EXPECT_GE(cc.send(msg.c_str(), msg.size()), 0);
}

TEST(ClientComm, sendLarge) {
std::string name = "MyComm";
communication::testing::ClientComm_tester cc(name);
YggInterface::testing::ClientComm_tester cc(name);
cc.addWorkers();
std::string msg(cc.getMaxMsgSize(), 'A');
EXPECT_TRUE(cc.addSignon());
Expand All @@ -129,7 +129,7 @@ TEST(ClientComm, sendLarge) {

TEST(ClientComm, recv) {
std::string name = "MyComm";
communication::testing::ClientComm_tester cc(name);
YggInterface::testing::ClientComm_tester cc(name);
std::string req_send = "REQUEST";
std::string res_send = "RESPONSE";
std::string req_recv;
Expand Down Expand Up @@ -204,7 +204,7 @@ TEST(ClientComm, async) {

TEST(ClientComm, recvLarge) {
std::string name = "MyComm";
communication::testing::ClientComm_tester cc(name);
YggInterface::testing::ClientComm_tester cc(name);
std::string bigMsg(cc.getMaxMsgSize(), 'A');
std::string req_send = "REQUEST" + bigMsg;
std::string res_send = "RESPONSE" + bigMsg;
Expand All @@ -225,7 +225,7 @@ TEST(ClientComm, recvLarge) {

TEST(ClientComm, call) {
std::string name = "MyComm";
communication::testing::ClientComm_tester cc(name);
YggInterface::testing::ClientComm_tester cc(name);
cc.addSchema("{\"type\": \"string\"}");
std::string req_send = "REQUEST1";
std::string res_send = "RESPONSE1";
Expand Down
4 changes: 2 additions & 2 deletions test/unittest/tests/communicators/commbasetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "communicators/CommBase.hpp"
#include "rapidjson/document.h"

using namespace communication;
using namespace communication::communicator;
using namespace YggInterface;
using namespace YggInterface::communicator;

class Comm_tTest: public Comm_t {
public:
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/tests/communicators/commheadtest.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../../unittest.hpp"
#include "utils/serialization.hpp"

using namespace communication::utils;
using namespace YggInterface::utils;

// TODO: Add tests for HEADER

Expand Down
2 changes: 1 addition & 1 deletion test/unittest/tests/communicators/commtest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define DO_RPC_SIGNON \
{ \
std::string msg_cli = YGG_CLIENT_SIGNON; \
communication::utils::Header header(msg_cli.c_str(), \
YggInterface::utils::Header header(msg_cli.c_str(), \
msg_cli.size(), &sComm); \
EXPECT_TRUE(sComm.create_header_send(header)); \
size_t len = header.format(); \
Expand Down
6 changes: 3 additions & 3 deletions test/unittest/tests/communicators/defaultcommtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "../../mock.hpp"
#include "commtest.hpp"

using namespace communication;
using namespace communication::communicator;
using namespace communication::mock;
using namespace YggInterface;
using namespace YggInterface::communicator;
using namespace YggInterface::mock;

TEST(DefaultCommu, checkTypeErrors) {
DefaultComm x("", SEND);
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/tests/communicators/interfacetest_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "communicators/comms.hpp"
#include "commtest.hpp"

using namespace communication::communicator;
using namespace YggInterface::communicator;

#define INIT_INPUT_BASE(cls, cls_args, alt, alt_args) \
alt sComm alt_args; \
Expand Down
6 changes: 3 additions & 3 deletions test/unittest/tests/communicators/ipccommtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "commtest.hpp"


using namespace communication;
using namespace communication::communicator;
using namespace communication::mock;
using namespace YggInterface;
using namespace YggInterface::communicator;
using namespace YggInterface::mock;

class IPCComm_tester : public IPCComm {
public:
Expand Down
6 changes: 3 additions & 3 deletions test/unittest/tests/communicators/mpicommtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "../../mock.hpp"
#include "commtest.hpp"

using namespace communication;
using namespace communication::communicator;
using namespace communication::mock;
using namespace YggInterface;
using namespace YggInterface::communicator;
using namespace YggInterface::mock;

#if defined(MPIINSTALLED) && defined(MPI_COMM_WORLD)

Expand Down
Loading

0 comments on commit 0f0de1d

Please sign in to comment.