Commit b73fa348 by guanghui.cui

支持多人识别

parent 2115f608
#TBB library
include_directories(${TBB_ROOT_DIR}/include)
# Local libraries
include_directories(${LandmarkDetector_SOURCE_DIR}/include)
include_directories(../../lib/local/LandmarkDetector/include)
add_executable(FaceLandmarkVidMulti FaceLandmarkVidMulti.cpp)
target_link_libraries(FaceLandmarkVidMulti LandmarkDetector)
target_link_libraries(FaceLandmarkVidMulti dlib)
target_link_libraries(FaceLandmarkVidMulti ${OpenCV_LIBS} ${Boost_LIBRARIES} ${TBB_LIBRARIES})
install (TARGETS FaceLandmarkVidMulti DESTINATION bin)
#ifndef BASEDEFINE_H
#define BASEDEFINE_H
#include <iostream>
#include <vector>
struct sReqCertificate
{
std::string Image_file;
std::string member_tel;
std::string member_name;
std::string authentication_channel;
std::string union_id;
};
struct sUserInfo
{
std::string confidence;
std::string memberTel;
std::string memberName;
std::string authenticationChannel;
std::string unionId;
};
struct sServerResponse
{
std::string success;
std::string errorMessage;
std::vector<sUserInfo> vecUser;
};
#endif
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C3FAF36F-44BC-4454-87C2-C5106575FE50}</ProjectGuid>
<RootNamespace>FaceLandmarkVidMulti</RootNamespace>
<ProjectName>FaceLandmarkVidMulti</ProjectName>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\lib\3rdParty\dlib\dlib.props" />
<Import Project="..\..\lib\3rdParty\OpenCV3.1\openCV3.1.props" />
<Import Project="..\..\lib\3rdParty\boost\boost_d.props" />
<Import Project="..\..\lib\3rdParty\tbb\tbb_d.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\lib\3rdParty\dlib\dlib.props" />
<Import Project="..\..\lib\3rdParty\OpenCV3.1\openCV3.1.props" />
<Import Project="..\..\lib\3rdParty\boost\boost_d.props" />
<Import Project="..\..\lib\3rdParty\tbb\tbb_d.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\lib\3rdParty\boost\boost.props" />
<Import Project="..\..\lib\3rdParty\dlib\dlib.props" />
<Import Project="..\..\lib\3rdParty\tbb\tbb.props" />
<Import Project="..\..\lib\3rdParty\OpenCV3.1\openCV3.1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\lib\3rdParty\boost\boost.props" />
<Import Project="..\..\lib\3rdParty\dlib\dlib.props" />
<Import Project="..\..\lib\3rdParty\tbb\tbb.props" />
<Import Project="..\..\lib\3rdParty\OpenCV3.1\openCV3.1.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetName>FaceLandmarkVidMulti</TargetName>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetName>FaceLandmarkVidMulti</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetName>FaceLandmarkVidMulti</TargetName>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetName>FaceLandmarkVidMulti</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(SolutionDir)\lib\local\LandmarkDetector\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(SolutionDir)\lib\local\LandmarkDetector\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(SolutionDir)\lib\local\LandmarkDetector\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(SolutionDir)\lib\local\LandmarkDetector\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="FaceLandmarkVidMulti.cpp" />
<ClCompile Include="jsonAnalysis.cpp" />
<ClCompile Include="utility\iniOperation.cpp" />
<ClCompile Include="utility\utilCommonAPI.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\lib\local\LandmarkDetector\LandmarkDetector.vcxproj">
<Project>{bdc1d107-de17-4705-8e7b-cdde8bfb2bf8}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CommonStruct.h" />
<ClInclude Include="jsonAnalysis.h" />
<ClInclude Include="utility\iniOperation.h" />
<ClInclude Include="utility\utilCommonAPI.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="FaceLandmarkVidMulti.cpp" />
<ClCompile Include="utility\iniOperation.cpp">
<Filter>utility</Filter>
</ClCompile>
<ClCompile Include="utility\utilCommonAPI.cpp">
<Filter>utility</Filter>
</ClCompile>
<ClCompile Include="jsonAnalysis.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="utility">
<UniqueIdentifier>{3271a844-b793-4e80-bce9-b5bf97041b45}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="utility\iniOperation.h">
<Filter>utility</Filter>
</ClInclude>
<ClInclude Include="utility\utilCommonAPI.h">
<Filter>utility</Filter>
</ClInclude>
<ClInclude Include="CommonStruct.h" />
<ClInclude Include="jsonAnalysis.h" />
</ItemGroup>
</Project>
\ No newline at end of file
// json.cpp : 定义控制台应用程序的入口点。
//
#include "jsonAnalysis.h"
#include <iostream>
std::string GetReqCertificateJson(sReqCertificate &req)
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.Key("Image_file");
writer.String(req.Image_file.data());
writer.Key("member_tel");
writer.String(req.member_tel.data());
writer.Key("member_name");
writer.String(req.member_name.data());
writer.Key("authentication_channel");
writer.String(req.authentication_channel.data());
writer.Key("union_id");
writer.String(req.union_id.data());
writer.EndObject();
return buffer.GetString();
}
std::string GetIdentityUserJson(const char* photo)
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.Key("Image_file");
writer.String(photo);
writer.EndObject();
return buffer.GetString();
}
sServerResponse GetServerResultData(const char* json)
{
sServerResponse res;
rapidjson::Document document; // 定义一个Document对象
document.Parse(json); // 解析,Parse()无返回值,也不会抛异常
if (document.HasParseError()) // 通过HasParseError()来判断解析是否成功
{
std::cout<<"HasParseError11"<<std::endl;
}
else
{
rapidjson::Value& msg = document["success"];
res.success=msg.GetString();
if ("yes" == res.success) {
if (document.HasMember("results")) {
rapidjson::Value& results = document["results"];
if (results.IsArray()) {
for (unsigned int i = 0; i<results.Size(); i++) {
sUserInfo user;
rapidjson::Value& objValue = results[i];
if (objValue.HasMember("confidence")) {
rapidjson::Value& confidence = objValue["confidence"];
user.confidence = confidence.GetString();
}
if (objValue.HasMember("memberTel")) {
rapidjson::Value& memberTel = objValue["memberTel"];
user.memberTel = memberTel.GetString();
}
if (objValue.HasMember("memberName")) {
rapidjson::Value& memberName = objValue["memberName"];
user.memberName = memberName.GetString();
}
if (objValue.HasMember("authenticationChannel")) {
rapidjson::Value& authenticationChannel = objValue["authenticationChannel"];
user.authenticationChannel = authenticationChannel.GetString();
}
if (objValue.HasMember("unionId")) {
rapidjson::Value& unionId = objValue["unionId"];
user.unionId = unionId.GetString();
}
res.vecUser.push_back(user);
}
}
}
}
else if ("no" == res.success) {
if (document.HasMember("errorMessage")) {
rapidjson::Value& errorMessage = document["errorMessage"];
res.errorMessage = errorMessage.GetString();
}
}
}
return res;
}
int SocketRequestJson(const char* json)
{
int result = 0;
rapidjson::Document document; // 定义一个Document对象
document.Parse(json); // 解析,Parse()无返回值,也不会抛异常
if (document.HasParseError()) // 通过HasParseError()来判断解析是否成功
{
// 可通过GetParseError()取得出错代码,
// 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// 函数GetErrorOffset()返回出错发生的位置
//LOG_ERROR("GetTakeawayPrintInfo JSON parse error: (%d:%d)", document.GetParseError(), document.GetErrorOffset())
//return false;
}
else
{
rapidjson::Value& fm_cmd = document["fm_cmd"];
result = fm_cmd.GetInt();
}
return result;
}
std::string GetSocketResultJson(const int statuscode, const char* msg, const char* phone)
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.Key("statusCode");
writer.Int(statuscode);
writer.Key("msg");
writer.String(msg);
writer.Key("member_id");
writer.String(phone);
writer.EndObject();
return buffer.GetString();
}
\ No newline at end of file
#ifndef JSON_H
#define JSON_H
#include <map>
#include "../rapidjson/rapidjson.h"
#include "../rapidjson/document.h"
#include "../rapidjson/reader.h"
#include "../rapidjson/writer.h"
#include "../rapidjson/stringbuffer.h"
#include "CommonStruct.h"
//#pragma warning(disable:4003)
using namespace rapidjson;
std::string GetReqCertificateJson(sReqCertificate &req);
std::string GetIdentityUserJson(const char* photo);
sServerResponse GetServerResultData(const char* json);
int SocketRequestJson(const char* json);
std::string GetSocketResultJson(const int statuscode, const char* msg, const char* phone);
#endif
///////////////////////////////////////////////////////////////
// Name: ZIni
// Version: 0.1
// Author: zhaobinjie
// Email: zhaobinjie1984@163.com
// Date: 2010-04-29
//
// Description:
// This class provides static functions for writing and
// reading INI files.
///////////////////////////////////////////////////////////////
#include "iniOperation.h"
#include <fstream>
#include <sstream>
#include <cctype>
#include <cstdlib>
bool ZIni::writeString(std::string strSectName,
std::string strKeyName,
std::string strValue,
std::string strFileName)
{
// open INI file
std::ifstream fsIni(strFileName.c_str(),
std::ios_base::in);
// open INI.bak file
std::ofstream fsIniBak((strFileName + ".zbk").c_str(),
std::ios_base::out | std::ios_base::trunc);
// file opened successfully
if (fsIni && fsIniBak)
{
// search section
std::string strLine = "";
std::string strSection = std::string("[") + strSectName + "]";
bool bWritten = false;
while (getline(fsIni, strLine))
{
// remain the others
fsIniBak << strLine << std::endl;
// section found
if (!bWritten && 0 == strSection.compare(trim(strLine)))
{
// search key
while (getline(fsIni, strLine))
{
std::string strTemp = trim(strLine);
// write value to the end of this section
if (strTemp.length() > 0 && '[' == strTemp[0])
{
fsIniBak << strKeyName << " = " << strValue
<< std::endl;
fsIniBak << strLine << std::endl;
bWritten = true;
break;
}
// replace the origin value
if (strTemp.length() > strKeyName.length() &&
0 == strTemp.compare(0,
strKeyName.length(), strKeyName) &&
'=' == strTemp[strKeyName.length()])
{
fsIniBak << strKeyName << " = " << strValue
<< std::endl;
bWritten = true;
break;
}
// remain the others
fsIniBak << strLine << std::endl;
}
// write value
if (!bWritten)
{
fsIniBak << strKeyName << " = " << strValue << std::endl;
bWritten = true;
}
}
}
// write value
if (!bWritten)
{
fsIniBak << strSection << std::endl;
fsIniBak << strKeyName << " = " << strValue << std::endl;
}
// close file stream
fsIni.close();
fsIniBak.close();
}
else
{
return false;
}
// open INI.zbk file
std::ifstream fsIniBakNew((strFileName + ".zbk").c_str(),
std::ios_base::in);
// open INI file
std::ofstream fsIniNew(strFileName.c_str(),
std::ios_base::out | std::ios_base::trunc);
// file opened successfully
if (fsIniBakNew && fsIniNew)
{
std::string strLine = "";
while (getline(fsIniBakNew, strLine))
{
fsIniNew << strLine << std::endl;
}
// close file stream
fsIniBakNew.close();
fsIniNew.close();
}
else
{
return false;
}
return true;
}
bool ZIni::writeInt(std::string strSectName,
std::string strKeyName,
int iValue,
std::string strFileName)
{
// convert int to string
std::stringstream ssValue;
ssValue << iValue;
return writeString(strSectName, strKeyName, ssValue.str(), strFileName);
}
bool ZIni::writeDouble(std::string strSectName,
std::string strKeyName,
double fValue,
std::string strFileName)
{
// convert double to string
std::stringstream ssValue;
ssValue << fValue;
return writeString(strSectName, strKeyName, ssValue.str(), strFileName);
}
std::string ZIni::readString(std::string strSectName,
std::string strKeyName,
std::string strDefault,
std::string strFileName)
{
// open INI file
std::ifstream fsIni(strFileName.c_str(), std::ios_base::in);
// file opened successfully
if (fsIni)
{
// search section
std::string strLine = "";
std::string strSection = std::string("[") + strSectName + "]";
while (getline(fsIni, strLine))
{
// section found
if (0 == strSection.compare(trim(strLine)))
{
// search key
while (getline(fsIni, strLine))
{
std::string strTemp = trim(strLine);
// end of this section
if (strTemp.length() > 0 && '[' == strTemp[0])
{
return strDefault;
}
if (strTemp.length() > strKeyName.length() + 1 &&
0 == strTemp.compare(0,
strKeyName.length(), strKeyName) &&
'=' == strTemp[strKeyName.length()])
{
return (strTemp.substr(strKeyName.length() + 1));
}
}
}
}
}
// read failed
return strDefault;
}
int ZIni::readInt(std::string strSectName,
std::string strKeyName,
int iDefault,
std::string strFileName)
{
// converting between int and string
std::stringstream ssDefault;
ssDefault << iDefault;
return atoi(readString(strSectName, strKeyName,
ssDefault.str(), strFileName).c_str());
}
double ZIni::readDouble(std::string strSectName,
std::string strKeyName,
double fDefault,
std::string strFileName)
{
// converting between double and string
std::stringstream ssDefault;
ssDefault << fDefault;
return atof(readString(strSectName, strKeyName,
ssDefault.str(), strFileName).c_str());
}
//消除字串两段的空格,字串中间的保留
std::string ZIni::trim(std::string &strInput)
{
std::string str(strInput);
if(str.empty())
return str;
str = str.substr(str.find_first_not_of(' '),str.find_last_not_of(' ')+1);
std::string::size_type pos_equations = str.find_first_of('=');
if(pos_equations != std::string::npos)
{
if(pos_equations > 0 && str[pos_equations-1] == ' ')
str.erase(pos_equations-1,1);
pos_equations = str.find_first_of('=');
if(pos_equations < str.size() && str[pos_equations+1] == ' ')
str.erase(pos_equations+1,1);
}
return str;
}
\ No newline at end of file
///////////////////////////////////////////////////////////////
// Name: ZIni
// Version: 0.1
// Author: zhaobinjie
// Email: zhaobinjie1984@163.com
// Date: 2010-04-29
//
// Description:
// This class provides static functions for writing and
// reading INI files.
///////////////////////////////////////////////////////////////
#ifndef ZINI_H
#define ZINI_H
#include <string>
class ZIni
{
public:
ZIni() {}
virtual ~ZIni() {}
public:
// return if succeed or not
static bool writeString(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
std::string strValue, // in. value to be write
std::string strFileName // in. INI file name
);
// return if succeed or not
static bool writeInt(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
int iValue, // in. value to be write
std::string strFileName // in. INI file name
);
// return if succeed or not
static bool writeDouble(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
double fValue, // in. value to be write
std::string strFileName // in. INI file name
);
// return the got string
static std::string readString(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
std::string strDefault, // in. defaut value if read failed
std::string strFileName // in. INI file name
);
// return the got int
static int readInt(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
int iDefault, // in. defaut value if read failed
std::string strFileName // in. INI file name
);
// return the got double
static double readDouble(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
double fDefault, // in. defaut value if read failed
std::string strFileName // in. INI file name
);
private:
static std::string trim(std::string &strInput);
};
#endif //ZINI_H
#include "utilCommonAPI.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <stdarg.h>
#define WIN32
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
//函数名: GetProcDir()
//功 能: 获取当前程序的路径
std::string GetProcDir()
{
std::string strDir;
#ifdef WIN32
char exeFullPath[MAX_PATH]; // Full path
GetModuleFileNameA(NULL, exeFullPath, MAX_PATH);
strDir = exeFullPath; // Get full path of the file
int pos = strDir.find_last_of('\\', strDir.length());
strDir = strDir.substr(0, pos+1); // Return the directory without the file name
#else
char szBuffer[256];
int npos = 0;
npos = readlink( "/proc/self/exe", szBuffer, 256 );
if ( npos < 0 || npos >= 256 )
{
printf( "readlink failed.\n" );
return strDir;
}
szBuffer[npos] = '\0';
char *ptr = NULL;
char c = '/';
ptr = strrchr(szBuffer,c);
if(ptr != NULL)
*(ptr +1) = 0;
strDir = szBuffer;
#endif
return strDir;
}
#ifdef WIN32
std::string UnicodeToAscii(const std::wstring& wstr) {
// 预算-缓冲区中多字节的长度
int ansiiLen = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
// 给指向缓冲区的指针变量分配内存
char *pAssii = (char*)malloc(sizeof(char)*ansiiLen);
// 开始向缓冲区转换字节
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, pAssii, ansiiLen, nullptr, nullptr);
std::string ret_str = pAssii;
free(pAssii);
return ret_str;
}
std::wstring Utf8ToUnicode(const std::string& str) {
// 预算-缓冲区中宽字节的长度
int unicodeLen = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
// 给指向缓冲区的指针变量分配内存
wchar_t *pUnicode = (wchar_t*)malloc(sizeof(wchar_t)*unicodeLen);
// 开始向缓冲区转换字节
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, pUnicode, unicodeLen);
std::wstring ret_str = pUnicode;
free(pUnicode);
return ret_str;
}
#endif // WIN32
#include <string>
//函数名: GetProcDir()
//功 能: 获取当前程序的路径
std::string GetProcDir();
#ifdef WIN32
#else
void OutputDebugString(const char* lpOutputString);
#endif
#ifdef WIN32
#else //LINUX
#define _DO_NOT_HAVE_S
#endif //WIN32
#ifdef _DO_NOT_HAVE_S //如果没有_s版的函数,则启动如下的替换宏
//#define sprintf_s(buffer,size,format, ...) sprintf(buffer,format,__VA_ARGS__)
#include <stdio.h>
#include <stdarg.h>
int sprintf_s(
char *buffer,
size_t sizeOfBuffer,
const char *format ,...); //这个比较特殊,需要真的去实现
#define memcpy_s(dest,num,src,count) memcpy(dest,src,count)
#define fprintf_s fprintf
#define _strdate_s(buf,num) _strdate(buf)
#define strcat_s(dest,num,src) strcat(dest,src)
#define fopen_s(pf,name,mode) *pf=fopen(name,mode)
#define strncpy_s(dest,num,src,count) strncpy(dest,src,count)
#define localtime_s(tm,time) *tm=*localtime(time)
#define _strdup strdup
#else
#define mkdir(pathname,mode) _mkdir(pathname)
#endif
#ifdef WIN32
std::string UnicodeToAscii(const std::wstring& wstr);
std::wstring Utf8ToUnicode(const std::string& str);
#endif // WIN32
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment