Added sharedRegex library

This commit is contained in:
Anonymous
2014-01-15 23:49:15 -07:00
parent 2dc66d4398
commit 99e4eb6b8c
19 changed files with 411 additions and 0 deletions
+1
View File
@@ -15,6 +15,7 @@ find_package(Iconv REQUIRED)
find_package(JNI REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(Oracle REQUIRED)
find_package(PCRE REQUIRED)
find_package(Perl REQUIRED)
find_package(STLPort REQUIRED)
find_package(ZLib REQUIRED)
+29
View File
@@ -0,0 +1,29 @@
find_path(PCRE_ROOT
NAMES include/pcre.h
)
find_path(PCRE_INCLUDE_DIR pcre.h
HINTS
$ENV{PCRE_ROOT}
PATH_SUFFIXES include
PATHS
${PCRE_ROOT}
${PCRE_INCLUDEDIR}
)
find_library(PCRE_LIBRARY
NAMES pcre libpcre
PATH_SUFFIXES lib
HINTS
$ENV{PCRE_ROOT}
${PCRE_ROOT}
${PCRE_LIBRARYDIR}
)
# handle the QUIETLY and REQUIRED arguments and set OPENAL_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR)
mark_as_advanced(PCRE_ROOT PCRE_INCLUDE_DIR PCRE_LIBRARY)
+1
View File
@@ -20,6 +20,7 @@ add_subdirectory(sharedNetworkMessages)
add_subdirectory(sharedObject)
add_subdirectory(sharedPathfinding)
add_subdirectory(sharedRandom)
add_subdirectory(sharedRegex)
add_subdirectory(sharedSkillSystem)
add_subdirectory(sharedSynchronization)
add_subdirectory(sharedTerrain)
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 2.8)
project(sharedRegex)
if(WIN32)
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public)
add_subdirectory(src)
@@ -0,0 +1 @@
#include "../../src/shared/ConfigSharedRegex.h"
@@ -0,0 +1 @@
#include "../../src/shared/FirstSharedRegex.h"
@@ -0,0 +1,7 @@
#if defined(PLATFORM_WIN32)
#include "../../src/win32/RegexServices.h"
#elif defined(PLATFORM_LINUX)
#include "../../src/linux/RegexServices.h"
#else
#error unsupported platform
#endif
@@ -0,0 +1 @@
#include "../../src/shared/SetupSharedRegex.h"
@@ -0,0 +1,39 @@
set(SHARED_SOURCES
shared/ConfigSharedRegex.cpp
shared/ConfigSharedRegex.h
shared/FirstSharedRegex.h
shared/SetupSharedRegex.cpp
shared/SetupSharedRegex.h
)
if(WIN32)
set(PLATFORM_SOURCES
win32/FirstSharedRegex.cpp
win32/RegexServices.cpp
win32/RegexServices.h
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/win32)
else()
set(PLATFORM_SOURCES
linux/RegexServices.cpp
linux/RegexServices.h
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/linux)
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/shared
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
${PCRE_INCLUDE_DIR}
)
add_library(sharedRegex STATIC
${SHARED_SOURCES}
${PLATFORM_SOURCES}
)
@@ -0,0 +1,26 @@
// ======================================================================
//
// RegexServices.cpp
// Copyright 2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#include "sharedRegex/FirstSharedRegex.h"
#include "sharedRegex/RegexServices.h"
// ======================================================================
void *RegexServices::allocateMemory(size_t byteCount)
{
return new char[byteCount];
}
// ----------------------------------------------------------------------
void RegexServices::freeMemory(void *pointer)
{
delete [] reinterpret_cast<char *>(pointer);
}
// ======================================================================
@@ -0,0 +1,25 @@
// ======================================================================
//
// RegexServices.h
// Copyright 2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_RegexServices_H
#define INCLUDED_RegexServices_H
// ======================================================================
class RegexServices
{
public:
static void *allocateMemory(size_t byteCount);
static void freeMemory(void *pointer);
};
// ======================================================================
#endif
@@ -0,0 +1,42 @@
// ======================================================================
//
// ConfigSharedRegex.cpp
// copyright 2004 Sony Online Entertainment
//
// ======================================================================
#include "sharedRegex/FirstSharedRegex.h"
#include "sharedRegex/ConfigSharedRegex.h"
#include "sharedFoundation/ConfigFile.h"
// ======================================================================
#define KEY_BOOL(a,b) (ms_ ## a = ConfigFile::getKeyBool("SharedRegex", #a, (b)))
// ======================================================================
namespace ConfigSharedRegexNamespace
{
bool ms_sample;
}
using namespace ConfigSharedRegexNamespace;
// ======================================================================
void ConfigSharedRegex::install()
{
KEY_BOOL(sample, false);
}
// ----------------------------------------------------------------------
bool ConfigSharedRegex::getSample()
{
return ms_sample;
}
// ======================================================================
@@ -0,0 +1,24 @@
// ======================================================================
//
// ConfigSharedRegex.h
// Copyright 2004, Sony Online Entertainment Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_ConfigSharedRegex_H
#define INCLUDED_ConfigSharedRegex_H
// ======================================================================
class ConfigSharedRegex
{
public:
static void install();
static bool getSample();
};
// ======================================================================
#endif
@@ -0,0 +1,18 @@
// ======================================================================
//
// FirstSharedRegex.h
// Copyright 2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_FirstSharedRegex_H
#define INCLUDED_FirstSharedRegex_H
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
// ======================================================================
#endif
@@ -0,0 +1,70 @@
// ======================================================================
//
// SetupSharedRegex.cpp
// Copyright 2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#include "sharedRegex/FirstSharedRegex.h"
#include "sharedRegex/SetupSharedRegex.h"
#include "sharedDebug/InstallTimer.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedRegex/ConfigSharedRegex.h"
#include "sharedRegex/RegexServices.h"
#include "pcre.h"
// ======================================================================
namespace SetupSharedRegexNamespace
{
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void remove();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool s_installed;
void *(*s_oldMalloc)(size_t);
void (*s_oldFree)(void*);
}
using namespace SetupSharedRegexNamespace;
// ======================================================================
void SetupSharedRegexNamespace::remove()
{
DEBUG_FATAL(!s_installed, ("SetupSharedRegex not installed."));
s_installed = false;
//-- Restore malloc and free functions.
pcre_malloc = s_oldMalloc;
pcre_free = s_oldFree;
}
// ======================================================================
void SetupSharedRegex::install()
{
InstallTimer const installTimer("SetupSharedRegex::install");
DEBUG_FATAL(s_installed, ("SetupSharedRegex already installed."));
ConfigSharedRegex::install();
//-- Save old malloc and free functions.
s_oldMalloc = pcre_malloc;
s_oldFree = pcre_free;
//-- Hook up PCRE malloc and free to our memory manager.
pcre_malloc = &RegexServices::allocateMemory;
pcre_free = &RegexServices::freeMemory;
s_installed = true;
ExitChain::add(remove, "SetupSharedRegex");
}
// ======================================================================
@@ -0,0 +1,24 @@
// ======================================================================
//
// SetupSharedRegex.h
// Copyright 2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_SetupSharedRegex_H
#define INCLUDED_SetupSharedRegex_H
// ======================================================================
class SetupSharedRegex
{
public:
static void install();
};
// ======================================================================
#endif
@@ -0,0 +1,9 @@
// ======================================================================
//
// FirstSharedRegex.cpp
// Copyright 2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#include "sharedRegex/FirstSharedRegex.h"
@@ -0,0 +1,57 @@
// ======================================================================
//
// RegexServices.cpp
// Copyright 2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#include "sharedRegex/FirstSharedRegex.h"
#include "sharedRegex/RegexServices.h"
// ======================================================================
static void * __cdecl localAllocate(size_t size, uint32 owner, bool array, bool leakTest)
{
return MemoryManager::allocate(size, owner, array, leakTest);
}
static __declspec(naked) void * regexAllocate(size_t)
{
_asm
{
// setup local call stack
push ebp
mov ebp, esp
// MemoryManager::alloc(size, [return address], false, true)
push 1
push 0
mov eax, dword ptr [ebp+4]
push eax
mov eax, dword ptr [ebp+8]
push eax
call localAllocate
add esp, 12
mov esp, ebp
pop ebp
ret
}
}
// ----------------------------------------------------------------------
void *RegexServices::allocateMemory(size_t byteCount)
{
return regexAllocate(byteCount);
}
// ----------------------------------------------------------------------
void RegexServices::freeMemory(void *pointer)
{
MemoryManager::free(pointer, false);
}
// ======================================================================
@@ -0,0 +1,25 @@
// ======================================================================
//
// RegexServices.h
// Copyright 2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_RegexServices_H
#define INCLUDED_RegexServices_H
// ======================================================================
class RegexServices
{
public:
static void *allocateMemory(size_t byteCount);
static void freeMemory(void *pointer);
};
// ======================================================================
#endif