Skip to content

Commit

Permalink
closes #6
Browse files Browse the repository at this point in the history
Changes:
- add properties mechanism support in the LuaScripter ('endian' property only for now)
- code splitting and refactoring
- code comments
  • Loading branch information
HaronK committed Oct 25, 2014
1 parent 5970453 commit 478fd0c
Show file tree
Hide file tree
Showing 29 changed files with 1,081 additions and 384 deletions.
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "external/Selene"]
path = external/Selene
url = /home/oleg/Downloads/Programming/Languages/Lua/Selene
[submodule "external/sol"]
path = external/sol
url = /home/oleg/Downloads/Programming/Languages/Lua/sol
[submodule "external/Catch"]
path = external/Catch
url = /home/okhryptul/Downloads/Programming/Languages/Lua/Catch
[submodule "external/boost_endian"]
path = external/boost_endian
url = https://github.com/boostorg/endian.git
42 changes: 28 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,53 @@ add_definitions(-std=c++11)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})

find_package(Poco REQUIRED)
cmake_policy(SET CMP0015 NEW)

if(NOT Poco_FOUND)
message(FATAL_ERROR "Cannot find Poco package")
# ----------------------------------------------------------------------------------------
# Packages
# ----------------------------------------------------------------------------------------

# Boost
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.56.0 REQUIRED COMPONENTS program_options)

if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()

find_package(Lua REQUIRED)
# Poco
find_package(Poco REQUIRED)

if(NOT LUA_FOUND)
message(FATAL_ERROR "Cannot find Lua package")
if(NOT Poco_FOUND)
message(FATAL_ERROR "Cannot find Poco package")
endif()


# ----------------------------------------------------------------------------------------
set(BinaryDigger_PackageFolder "${BinaryDigger_BINARY_DIR}/package/")
set(BinaryDigger_PluginsFolder "${BinaryDigger_PackageFolder}/plugins/")
set(BD_PACKAGE_FOLDER "${BinaryDigger_BINARY_DIR}/package/")
set(BD_PLUGINS_FOLDER "${BD_PACKAGE_FOLDER}/plugins/")
set(BD_SCRIPTS_FOLDER "${BD_PACKAGE_FOLDER}/scripts/")

execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BinaryDigger_PluginsFolder})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BD_PLUGINS_FOLDER})
# ----------------------------------------------------------------------------------------

set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories("${BinaryDigger_SOURCE_DIR}/include"
"${BinaryDigger_SOURCE_DIR}/utils"
${LUA_INCLUDE_DIR}
include_directories("include"
"external/boost_endian/include"
"utils"
"default_plugin"
${Poco_INCLUDE_DIR})

link_directories(${Poco_LIBRARY_DIRS})
link_directories("default_plugin" ${Poco_LIBRARY_DIRS})

# Solving problem with linking unused static library.
# Source: http://stackoverflow.com/questions/17470350/c-cmake-how-to-add-a-linker-flag-to-an-unused-library-when-the-library-is-sp
SET(bd_default_plugin_FORCE_LINK -Wl,--whole-archive bd_default_plugin -Wl,--no-whole-archive)

# Build subdirectories.
add_subdirectory(external)
add_subdirectory(include)
add_subdirectory(default_plugin)
add_subdirectory(gui)
Expand All @@ -55,7 +69,7 @@ add_subdirectory(scripters)
add_subdirectory(tests)
add_subdirectory(tools)
add_subdirectory(utils)
add_subdirectory(server) # "${BinaryDigger_BINARY_DIR}/server"
add_subdirectory(server)

# installation
#install(FILES MathFunctions.h DESTINATION include)
51 changes: 51 additions & 0 deletions default_plugin/block_templ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* block_templ.h
*
* Created on: 25 жовт. 2014
* Author: oleg
*/

#ifndef BLOCK_TEMPL_H_
#define BLOCK_TEMPL_H_

#include "block_templ_base.h"

/**
* Base class for the template structures declared via BD_TEMPL_DECL or BD_TEMPL macros.
* Also it used directly for simple C datatypes (char, int, ... or plain structures).
*
* @param T Data type
* @param simple_type true if
*/
template<class T, bd_block_type _type = BD_TEMPL>
class BlockTempl : public BlockTemplBase
{
public:
BlockTempl(bd_block_io* _blob, bd_cstring _var_name, bd_u32 _count, BlockTemplBase* _parent, const bd_property_records &props)
: BlockTemplBase(_blob, _var_name, (bd_cstring) get_type_name<T>().c_str(), _type, sizeof(T), _count, _parent, props)
{
}

BlockTempl(bd_block_io* _block_io, bd_cstring _var_name, bd_cstring _type_name, bd_u32 _count, BlockTemplBase* _parent, const bd_property_records &props)
: BlockTemplBase(_block_io, _var_name, _type_name, _type, sizeof(T), _count, _parent, props)
{
}

inline T value()
{
return static_cast<T>(*this);
}

void apply() {}
};

// Simple type templates
#define BD_BLOCK_TYPE_DECL(name, tp) \
class name : public BlockTempl<name##_T, BD_##name> { \
public: name(bd_block_io* _block_io, bd_cstring _var_name, bd_u32 _count, BlockTemplBase* _parent, \
const bd_property_records &props) : \
BlockTempl(_block_io, _var_name, _count, _parent, props) {}};
BD_BLOCK_TYPES
#undef BD_BLOCK_TYPE_DECL

#endif /* BLOCK_TEMPL_H_ */
56 changes: 49 additions & 7 deletions default_plugin/block_templ_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#include "block_templ_base.h"

BlockTemplBase::BlockTemplBase(bd_block_io *_block_io, bd_cstring _name, bd_cstring _type_name, bd_block_type _type,
bd_u64 _size, bd_u32 _count, BlockTemplBase *_parent)
bd_u64 _size, bd_u32 _count, BlockTemplBase *_parent, const bd_property_records &props)
{
block_io = _block_io;
name = strdup(_name);
type_name = strdup(_type_name);
type = _type;
parent = _parent;
block_io = _block_io;
name = strdup(_name);
type_name = strdup(_type_name);
type = _type;
parent = _parent;
templ_properties = props;

children.child = 0;
children.count = 0;
Expand All @@ -41,7 +42,7 @@ BlockTemplBase::BlockTemplBase(bd_block_io *_block_io, bd_cstring _name, bd_cstr
for (auto i = 0; i < count; ++i)
{
// add single element
new BlockTemplBase(_block_io, _name, _type_name, _type, _size, 0, this);
new BlockTemplBase(_block_io, _name, _type_name, _type, _size, 0, this, props);
}

bd_u64 pos = getPosition();
Expand Down Expand Up @@ -122,6 +123,47 @@ std::string BlockTemplBase::getString() const
return result;
}

std::string BlockTemplBase::to_string()
{
if (is_array == BD_TRUE)
{
if (type == BD_CHAR)
return getString();
return "<array>";
}

switch (getType())
{
case BD_TEMPL:
return "<templ>";
#define BD_BLOCK_TYPE_DECL(name, tp) \
case BD_##name: { \
auto val = (tp) *this; \
return std::to_string(val); }
BD_BLOCK_TYPES
#undef BD_BLOCK_TYPE_DECL
}

return "<undef>";
}

bd_property BlockTemplBase::get_property(const std::string &name)
{
if (obj_properties.find(name) != obj_properties.end())
return obj_properties[name];

if (templ_properties.find(name) != templ_properties.end())
return templ_properties[name];

if (parent != nullptr)
return ((BlockTemplBase *) parent)->get_property(name);

if (default_property.find(name) != default_property.end())
return default_property[name];

return bd_property();
}

// --------------------------------------------------------------------------------------------------------------------

bool operator ==(const BlockTemplBase& val1, const char* val2)
Expand Down
Loading

0 comments on commit 478fd0c

Please sign in to comment.