Skip to content

Commit

Permalink
for issue #80
Browse files Browse the repository at this point in the history
  • Loading branch information
NevilClavain committed Aug 3, 2023
1 parent d0032b7 commit 12ab03f
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 125 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ ALL_BUILD.vcxproj*
/CORE_maths/CMakeFiles/
/CORE_maths/*.sln
/CORE_maths/*.vcxproj*
/CORE_parser/CMakeFiles/
/CORE_parser/*.sln
/CORE_parser/*.vcxproj*
/CEGUIWrapper_project/CMakeFiles/
/CEGUIWrapper_project/*.sln
/CEGUIWrapper_project/*.vcxproj*
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ add_subdirectory(drawspacecore_project)

add_subdirectory(CORE_logger)
add_subdirectory(CORE_maths)
add_subdirectory(CORE_parser)

add_subdirectory(CEGUIWrapper_project)
add_subdirectory(Plugins/d3d11_project)
Expand Down
42 changes: 42 additions & 0 deletions CORE_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*-LIC_BEGIN-*-
#
# DrawSpace Rendering engine
# Emmanuel Chaumont Copyright (c) 2013-2023
#
# This file is part of DrawSpace.
#
# DrawSpace is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DrawSpace is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DrawSpace. If not, see <http://www.gnu.org/licenses/>.
#
# -*-LIC_END-*-

cmake_minimum_required(VERSION 3.0)
project(CORE_parser)

include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${physfs_include_dir})

file(
GLOB_RECURSE
source_files
${CMAKE_SOURCE_DIR}/CORE_parser/src/*.h
${CMAKE_SOURCE_DIR}/CORE_parser/src/*.cpp
)


add_definitions( -D_FROMCMAKE )

add_library(CORE_parser ${source_files})



162 changes: 81 additions & 81 deletions src/parser.cpp → CORE_parser/src/parser.cpp
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
/* -*-LIC_BEGIN-*- */
/*
*
* DrawSpace Rendering engine
* Emmanuel Chaumont Copyright (c) 2013-2023
*
* This file is part of DrawSpace.
*
* DrawSpace is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DrawSpace is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DrawSpace. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -*-LIC_END-*- */

#include <vector>
#include "parser.h"
#include "file.h"


using namespace DrawSpace;
using namespace DrawSpace::Utils;

static std::vector<dsstring> split(const std::string& s, const std::string& seperators)
{
std::vector<std::string> output;
std::string::size_type prev_pos{ 0 };
std::string::size_type pos{ 0 };

while ((pos = s.find(seperators, pos)) != std::string::npos)
{
std::string substring(s.substr(prev_pos, pos - prev_pos));

output.push_back(substring);
prev_pos = ++pos;
}

output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word
return output;
}

void Parser::run(const dsstring& p_filepath, const dsstring& p_separators, const ParserCallback& p_callback)
{
long line_count{ 0 };

File file(p_filepath, File::OPENEXISTINGTEXT);
constexpr int lineMaxSize{ 1024 };

char line[lineMaxSize];

while (file.Gets(line, lineMaxSize))
{
line_count++;
// supprimer le retour chariot en fin de ligne
if (0x0a != line[0])
{
const auto len{ strlen(line) };

if (0x0a == line[len - 1])
{
line[len - 1] = 0x00;
}

const dsstring current_line(line);
if (current_line != "")
{
const auto words{ split(current_line, p_separators)};

p_callback(current_line, line_count, words);
}
}
}
/* -*-LIC_BEGIN-*- */
/*
*
* DrawSpace Rendering engine
* Emmanuel Chaumont Copyright (c) 2013-2023
*
* This file is part of DrawSpace.
*
* DrawSpace is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DrawSpace is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DrawSpace. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -*-LIC_END-*- */

#include <vector>
#include "parser.h"
#include "file.h"


using namespace DrawSpace;
using namespace DrawSpace::Utils;

static std::vector<dsstring> split(const std::string& s, const std::string& seperators)
{
std::vector<std::string> output;
std::string::size_type prev_pos{ 0 };
std::string::size_type pos{ 0 };

while ((pos = s.find(seperators, pos)) != std::string::npos)
{
std::string substring(s.substr(prev_pos, pos - prev_pos));

output.push_back(substring);
prev_pos = ++pos;
}

output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word
return output;
}

void Parser::run(const dsstring& p_filepath, const dsstring& p_separators, const ParserCallback& p_callback)
{
long line_count{ 0 };

File file(p_filepath, File::OPENEXISTINGTEXT);
constexpr int lineMaxSize{ 1024 };

char line[lineMaxSize];

while (file.Gets(line, lineMaxSize))
{
line_count++;
// supprimer le retour chariot en fin de ligne
if (0x0a != line[0])
{
const auto len{ strlen(line) };

if (0x0a == line[len - 1])
{
line[len - 1] = 0x00;
}

const dsstring current_line(line);
if (current_line != "")
{
const auto words{ split(current_line, p_separators)};

p_callback(current_line, line_count, words);
}
}
}
}
86 changes: 43 additions & 43 deletions src/parser.h → CORE_parser/src/parser.h
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
/* -*-LIC_BEGIN-*- */
/*
*
* DrawSpace Rendering engine
* Emmanuel Chaumont Copyright (c) 2013-2023
*
* This file is part of DrawSpace.
*
* DrawSpace is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DrawSpace is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DrawSpace. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -*-LIC_END-*- */

#pragma once

#include <vector>
#include <functional>
#include "ds_types.h"

namespace DrawSpace
{
namespace Parser
{
using ParserCallback = std::function<void(const dsstring&, long, const std::vector<dsstring>&)>;

void run(const dsstring& p_filepath,
const dsstring& p_separators,
const ParserCallback& p_callback
);
}
}

/* -*-LIC_BEGIN-*- */
/*
*
* DrawSpace Rendering engine
* Emmanuel Chaumont Copyright (c) 2013-2023
*
* This file is part of DrawSpace.
*
* DrawSpace is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DrawSpace is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DrawSpace. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -*-LIC_END-*- */

#pragma once

#include <vector>
#include <functional>
#include "ds_types.h"

namespace DrawSpace
{
namespace Parser
{
using ParserCallback = std::function<void(const dsstring&, long, const std::vector<dsstring>&)>;

void run(const dsstring& p_filepath,
const dsstring& p_separators,
const ParserCallback& p_callback
);
}
}

1 change: 1 addition & 0 deletions drawspacecore_project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ include_directories(${st_tree_include_dir})
include_directories(${CMAKE_SOURCE_DIR}/CORE_logger/src)
include_directories(${CMAKE_SOURCE_DIR}/CORE_maths/src)


file(
GLOB_RECURSE
source_files
Expand Down
1 change: 1 addition & 0 deletions lua_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/CORE_logger/src)
include_directories(${CMAKE_SOURCE_DIR}/CORE_maths/src)


file(
GLOB_RECURSE
source_files
Expand Down
1 change: 1 addition & 0 deletions lua_extensions/fpsmvt_luaext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ link_directories(${bullet_lib_dir})
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/CORE_logger/src)
include_directories(${CMAKE_SOURCE_DIR}/CORE_maths/src)

include_directories(${CMAKE_SOURCE_DIR}/lua_core/src)

file(
Expand Down
3 changes: 2 additions & 1 deletion rt_project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ project(rt)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/CORE_logger/src)
include_directories(${CMAKE_SOURCE_DIR}/CORE_maths/src)
include_directories(${CMAKE_SOURCE_DIR}/CORE_parser/src)

include_directories(${jsonjsmn_include_dir})
link_directories(${jsonjsmn_lib_dir})
Expand All @@ -49,7 +50,7 @@ file(
)

add_executable(rt WIN32 ${source_files})
target_link_libraries(rt physfs jsmn BulletDynamics_vs2017 BulletCollision_vs2017 LinearMath_vs2017 drawspace_core CORE_logger CORE_maths)
target_link_libraries(rt physfs jsmn BulletDynamics_vs2017 BulletCollision_vs2017 LinearMath_vs2017 drawspace_core CORE_logger CORE_maths CORE_parser)

install(TARGETS rt CONFIGURATIONS Debug RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/apps/Debug)
install(TARGETS rt CONFIGURATIONS Release RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/apps/Release)
Expand Down

0 comments on commit 12ab03f

Please sign in to comment.