Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Sep 10, 2018
1 parent 3af425f commit 49d7098
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 19 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ CPP = $(MinGW64)/bin/g++
# CC = gcc.exe
# WINDRES = windres.exe
# RM = rm -f
OBJ = src/csar.o test/test_emplace.o test/test_json.o
LINKOBJ =
OBJ = src/csar.o
TESTOBJ = test/test_emplace.o test/test_json.o
LINKOBJ = src/json.o
LIBS = -lboost_program_options-mt -L $(MinGW64)/lib
INCS = -I $(MinGW64)/include -I include
CXXINCS = $(INCS)
Expand All @@ -26,13 +27,13 @@ SRC = $(SRCDIR)/$(NAME:.exe=.cpp)
all: all-before $(BIN) all-after

clean: clean-custom
${RM} $(OBJ) $(BIN)
${RM} $(OBJ) $(BIN) $(LINKOBJ)

$(BIN): $(SRC)
$(CPP) -o $@ $< $(LINKOBJ) $(LIBS)
$(BIN): $(OBJ) $(LINKOBJ)
$(CPP) -o $@ $^ $(LIBS)

src/csar.o: src/csar.cpp
$(CPP) -c src/csar.cpp -o src/csar.o $(CXXFLAGS)
src/%.o: src/%.cpp
$(CPP) -o $@ -c $< $(CXXFLAGS)

test/test_emplace.o: test/test_emplace.cpp
$(CPP) -c test/test_emplace.cpp -o test/test_emplace.o $(CXXFLAGS)
Expand Down
13 changes: 13 additions & 0 deletions include/json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "json.hpp"

using json = nlohmann::json;

class Task:public json
{
public:
void operator() ();
};

Task&& loadjson(std::string file_path);
26 changes: 14 additions & 12 deletions src/csar.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
#include <iostream>
#include <exception>
#include <boost/program_options.hpp>

struct NotImplementedError: public std::exception
{
};
#include "json.h"

namespace po = boost::program_options;

int main(int argc, char const *argv[])
{
po::options_description desc("Arguments: ");
po::options_description desc("语法: csar <input-file> [options]");
desc.add_options()
("help", "produce help messages")
("help,h", "produce help messages")
("input-file", po::value< std::string >(), "input file path")
("output", po::value< std::string >(), "output file path")
("output-file", po::value< std::string >(), "output file path")
;
po::positional_options_description p;
p.add("input-file", -1);
Expand All @@ -25,13 +21,19 @@ int main(int argc, char const *argv[])
po::notify(vm);

if (vm.count("help")) {
std::cout << "Usage: options_description [options]\n";
std::cout << desc << std::endl;
return 0;
}
if (vm.count("output"))

if (vm.count("input-file"))
{
// std::cout << desc["output"].as<std::string>() << std::endl;
auto infile = vm["input-file"].as<std::string>();
std::cout << "Read from file: " << infile << std::endl;
auto task = loadjson(infile);
task();
}
else
{
std::cout << desc << std::endl;
}
return 0;
}
22 changes: 22 additions & 0 deletions src/json.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "json.h"
#include <fstream>
#include <exception>
#include <iostream>

struct NotImplementedError: public std::exception
{
};

void Task::operator() ()
{
std::cout << "Running Task" << std::endl;
throw NotImplementedError();
}

Task&& loadjson(std::string file_path)
{
std::ifstream file(file_path);
Task s;
file >> *static_cast<json*>(&s);
return std::move(s);
}

0 comments on commit 49d7098

Please sign in to comment.