delete private cmd_parse and json_tools, jsoncpp

This commit is contained in:
hyzboy 2019-11-29 18:21:11 +08:00
parent 96a41488b5
commit c3d81daa94
7 changed files with 3 additions and 184 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "jsoncpp"]
path = jsoncpp
url = https://github.com/open-source-parsers/jsoncpp.git

View File

@ -7,19 +7,15 @@ add_definitions(-DUNICODE -D_UNICODE)
include_directories("DevIL Windows SDK/include")
link_directories("DevIL Windows SDK/lib/x64/unicode/Release")
add_subdirectory(jsoncpp)
include_directories(jsoncpp/include)
set(SOURCE_FILE main.cpp config.cpp json_tools.cpp cmd_parse.cpp pixel_format.cpp)
set(HEADER_FILE config.h json_tools.h cmd_parse.h pixel_format.h)
set(SOURCE_FILE main.cpp config.cpp pixel_format.cpp)
set(HEADER_FILE config.h pixel_format.h)
SOURCE_GROUP("Header Files" FILES ${HEADER_FILE})
SOURCE_GROUP("Source Files" FILES ${SOURCE_FILE})
add_executable(TexConv ${SOURCE_FILE} ${HEADER_FILE})
target_link_libraries(TexConv PRIVATE DevIL jsoncpp_lib)
target_link_libraries(TexConv PRIVATE DevIL)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

View File

@ -1,73 +0,0 @@
#include"cmd_parse.h"
cmd_parse::cmd_parse(int argc,char **argv)
{
for(int i=0;i<argc;i++)
args.push_back(std::string(argv[i]));
}
int cmd_parse::Find(const std::string &flag)const
{
const int count=(const int)args.size();
for(int i=0;i<count;i++)
if(strncmp(flag.c_str(),args[i].c_str(),flag.length())==0)
return i;
return -1;
}
bool cmd_parse::GetInteger(const std::string &flag,int *result)const
{
int index=Find(flag);
if(index==-1)return(false);
const std::string &str=args[index];
if(str.length()>flag.length())
{
*result=atoi(str.c_str()+flag.length());
}
else
{
*result=atoi(str.c_str());
}
return(true);
}
bool cmd_parse::GetString(const std::string &flag,std::string &result)const
{
int index=Find(flag);
const char *p=nullptr;
if(index==-1)return(false);
const std::string &str=args[index];
if(str.length()>flag.length())
{
p=str.c_str()+flag.length();
}
else
{
p=args[index+1].c_str();
}
if(*p=='"') //有引号
{
auto len=strchr(p+1,L'"')-p;
if(len>1)
result.append(p+1,len-1);
else
result=p+1;
}
else //无引号
{
result=p;
}
return(true);
}

View File

@ -1,24 +0,0 @@
#pragma once
#include<string>
#include<vector>
using stringlist=std::vector<std::string>;
/**
*
*/
class cmd_parse ///命令行参数解晰辅助类
{
stringlist args;
public:
cmd_parse(int argc,char **argv);
virtual ~cmd_parse()=default;
int Find(const std::string &)const; ///<查找一个指定字串开头的参数是否存在
bool GetInteger(const std::string &,int *)const; ///<取得一个数值参数
bool GetString(const std::string &,std::string &)const; ///<取得一个字符串参数
};//class CmdParse

View File

@ -1,69 +0,0 @@
#include<string>
#include<sstream>
#include<iostream>
#include<json/json.h>
#include<hgl/filesystem/FileSystem.h>
using namespace std;
const std::string JsonToString(const Json::Value &jv_root)
{
Json::StreamWriterBuilder builder;
Json::StreamWriter *writer=builder.newStreamWriter();
JSONCPP_OSTRINGSTREAM result;
writer->write(jv_root,&result);
delete writer;
return std::string(result.str());
}
bool ParseJson(Json::Value &root,const char *txt,const int size,std::string *error_info)
{
Json::CharReaderBuilder builder;
Json::CharReader *reader=builder.newCharReader();
const bool result=reader->parse(txt,txt+size,&root,error_info);
delete reader;
return result;
}
bool LoadJson(Json::Value &root,const os_char *filename)
{
char *txt;
int size;
size=hgl::filesystem::LoadFileToMemory(filename,(void **)&txt);
if(size<=0)
{
std::cerr<<"load json file failed,filename: "<<filename<<std::endl;
return(false);
}
bool result;
std::string error_info;
result=ParseJson(root,txt,size,&error_info);
delete[] txt;
if(!result)
{
std::cerr<<"parse json file failed,filename: "<<filename<<std::endl;
return(false);
}
return(true);
}
bool SaveJson(const Json::Value &root,const os_char *filename)
{
const std::string txt=JsonToString(root);
return hgl::filesystem::SaveMemoryToFile(filename,txt.c_str(),txt.size());
}

View File

@ -1,7 +0,0 @@
#pragma once
#include<json/json.h>
#include<hgl/type/DataType.h>
bool LoadJson(Json::Value &root,const os_char *filename);
bool SaveJson(const Json::Value &root,const os_char *filename);

@ -1 +0,0 @@
Subproject commit 9e0d70aa66e6ba993dd05723ca64c26ab00f3572