Add JSON submodule and state class. This is failing to compile properly on macOS, trying on Linux

This commit is contained in:
mmcwilliams 2024-04-16 10:25:59 -06:00
parent faf9570f98
commit 7d146cbab9
9 changed files with 106 additions and 2 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
build build
*.DS_Store

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "src/json"]
path = src/json
url = https://github.com/nlohmann/json.git

View File

@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED) find_package(GLUT REQUIRED)
find_package(OpenCV HINTS /usr/local/opt/opencv /usr/local/Cellar/opencv REQUIRED) find_package(OpenCV HINTS /usr/local/opt/opencv /usr/local/Cellar/opencv REQUIRED)
@ -14,6 +15,14 @@ set( NAME_SRC
src/main.cpp src/main.cpp
) )
ENABLE_TESTING()
ADD_SUBDIRECTORY( test )
set(UNIT_TEST state_test)
add_test(NAME ${UNIT_TEST} COMMAND ${UNIT_TEST})
add_custom_target(run_unit_test ALL
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS ${UNIT_TEST})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( fd ${NAME_SRC} ${NAME_HEADERS} ) add_executable( fd ${NAME_SRC} ${NAME_HEADERS} )

1
src/json Submodule

@ -0,0 +1 @@
Subproject commit 8c391e04fe4195d8be862c97f38cfe10e2a3472e

View File

@ -1,6 +1,10 @@
#include "image.h" #include "image.h"
#include "state.h"
int main(int argc, char** argv) using namespace std;
{
int main(int argc, char** argv) {
string action_load = "{\"action\" : 0 }";
json msg_data = json::parse(action_load);
MessageIn msgIn(msg_data);
} }

7
src/state.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "state.h"
MessageIn::MessageIn (json msgData) {
if (msgData.contains("action")) {
action = static_cast<Action>(msgData["action"]);
}
}

56
src/state.h Normal file
View File

@ -0,0 +1,56 @@
#ifndef STATE_h
#define STATE_h
#include "json/single_include/nlohmann/json.hpp"
#include <iostream>
using json = nlohmann::json;
using namespace std;
enum Action {
LOAD,
DISPLAY,
STOP
};
enum Mode {
RGB,
BW,
INVERT,
BW_INVERT,
RGB_CHANNELS,
INVERT_CHANNELS
};
class MessageIn {
private:
Action action;
string file;
Mode mode;
vector<uint64_t> exposure;
bool start;
public:
MessageIn(json msgJson);
Action getAction () { return action;}
};
/*
class MessageOut {
public:
MessageOut(Action a, bool s);
Action action;
bool success;
string toString();
};
class State {
public :
MessageIn active;
State();
void processMessage(string msgString);
void createMessage(Action action, bool success);
};
*/
#endif

2
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
ADD_EXECUTABLE( state_test state_test.cpp )
ADD_TEST( fd state_test )

21
test/state_test.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <iostream>
#include "../src/state.h"
void IS_TRUE(string name, bool x) {
if (!(x)) {
cout << "Failed test " << name << ":" << endl;
cout << __FUNCTION__ << " failed on line " << __LINE__ << endl;
exit(EXIT_FAILURE);
}
}
void test_message_in() {
//string action_load = "{\"action\" : 0 }";
//json msg_data = json::parse(action_load);
//MessageIn msgIn(msg_data);
//IS_TRUE("parses_action_load", msgIn.getAction() == LOAD);
}
int main(void) {
test_message_in();
}