Initial version

This commit is contained in:
Simon Rozman 2016-02-29 11:10:04 +01:00
parent 4e605240ed
commit f86db20527
8 changed files with 527 additions and 0 deletions

20
build/stdex.props Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<stdexVersion>10</stdexVersion>
</PropertyGroup>
<PropertyGroup>
<OutDir>..\..\..\output\$(Platform).$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>STDEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<BuildMacro Include="stdexVersion">
<Value>$(stdexVersion)</Value>
</BuildMacro>
</ItemGroup>
</Project>

107
build/stdex.vcxproj Normal file
View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.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>
<ItemGroup>
<ClCompile Include="..\src\stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\stdex\common.h" />
<ClInclude Include="..\include\stdex\idrec.h" />
<ClInclude Include="..\src\stdafx.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\res\stdex.rc" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{518777CC-0A59-4415-A12A-82751ED75343}</ProjectGuid>
<RootNamespace>stdex</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<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="..\..\..\include\Win32.props" />
<Import Project="..\..\..\include\Debug.props" />
<Import Project="stdex.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="..\..\..\include\x64.props" />
<Import Project="..\..\..\include\Debug.props" />
<Import Project="stdex.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="..\..\..\include\Win32.props" />
<Import Project="..\..\..\include\Release.props" />
<Import Project="stdex.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="..\..\..\include\x64.props" />
<Import Project="..\..\..\include\Release.props" />
<Import Project="stdex.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetName>$(ProjectName)$(stdexVersion)ud_vc$(PlatformToolsetVersion)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetName>$(ProjectName)$(stdexVersion)ud_vc$(PlatformToolsetVersion)_$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetName>$(ProjectName)$(stdexVersion)u_vc$(PlatformToolsetVersion)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetName>$(ProjectName)$(stdexVersion)u_vc$(PlatformToolsetVersion)_$(Platform)</TargetName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\stdex\common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\stdex\idrec.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\res\stdex.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

57
include/stdex/common.h Normal file
View File

@ -0,0 +1,57 @@
/*
Copyright 2016 Amebis
This file is part of stdex.
stdex 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.
stdex 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 stdex. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vector>
///
/// Public function calling convention
///
#ifdef STDEX
#define STDEX_API __declspec(dllexport)
#else
#define STDEX_API __declspec(dllimport)
#endif
#define STDEX_NOVTABLE __declspec(novtable)
//
// Product version as a single DWORD
// Note: Used for version comparison within C/C++ code.
//
#define STDEX_VERSION 0x01000000
//
// Product version by components
// Note: Resource Compiler has limited preprocessing capability,
// thus we need to specify major, minor and other version components
// separately.
//
#define STDEX_VERSION_MAJ 1
#define STDEX_VERSION_MIN 0
#define STDEX_VERSION_REV 0
#define STDEX_VERSION_BUILD 0
//
// Human readable product version and build year for UI
//
#define STDEX_VERSION_STR "1.0"
#define STDEX_BUILD_YEAR_STR "2016"

263
include/stdex/idrec.h Normal file
View File

@ -0,0 +1,263 @@
/*
Copyright 2016 Amebis
This file is part of stdex.
stdex 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.
stdex 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 stdex. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common.h"
#include <ios>
namespace stdex {
namespace idrec {
///
/// Skips current record data
///
/// \param[in] stream Input stream
///
/// \returns
/// - true when successful
/// - false otherwise
///
template <class T_SIZE, unsigned int ALIGN, class T_STREAM>
inline bool ignore(T_STREAM& stream)
{
T_SIZE size;
// Read record size.
stream.read(&size, sizeof(size));
if (stream.fail()) return false;
// Skip the record data.
size += (T_SIZE)(ALIGN - size) % ALIGN;
stream.ignore(size);
if (stream.fail()) return false;
return true;
}
///
/// Finds record data
///
/// \param[in] stream Input stream
/// \param[in] id Record ID
/// \param[in] end Position limit. Default is -1 (no limit).
///
/// \returns
/// - true when found
/// - false otherwise
///
template <class T_ID, class T_SIZE, unsigned int ALIGN, class T_STREAM>
inline bool find(T_STREAM& stream, T_ID id, std::streamoff end = (std::streamoff)-1)
{
T_ID _id;
while (end == (std::streamoff)-1 || stream.tellg() < end) {
stream.read(&_id, sizeof(_id));
if (stream.fail()) return false;
if (_id == id) {
// The record was found.
return true;
} else
ignore<T_SIZE, ALIGN, T_STREAM>(stream);
}
return false;
}
///
/// Writes record header
///
/// \param[in] stream Output stream
/// \param[in] id Record ID
///
/// \returns Position of the record header start in \p stream. Save for later \c close call.
///
template <class T_ID, class T_SIZE, class T_STREAM>
inline std::streamoff open(T_STREAM& stream, T_ID id)
{
std::streamoff start = stream.tellp();
// Write ID.
if (stream.fail()) return (std::streamoff)-1;
stream.write(&id, sizeof(id));
// Write 0 as a placeholder for data size.
if (stream.fail()) return (std::streamoff)-1;
stream.write(&(T_SIZE)0, sizeof(T_SIZE));
return start;
}
///
/// Updates record header
///
/// \param[in] stream Output stream
/// \param[in] start Start position of the record in \p stream
///
/// \returns Position of the record end in \p stream
///
template <class T_ID, class T_SIZE, unsigned int ALIGN, class T_STREAM>
inline std::streamoff close(T_STREAM& stream, std::streamoff start)
{
std::streamoff end = stream.tellp();
T_SIZE
size = (T_SIZE)(end - start - sizeof(T_ID) - sizeof(T_SIZE)),
remainder = (T_SIZE)(ALIGN - size) % ALIGN; // Number of bytes we need to add, to keep the data integral number of ALIGN blocks long
if (remainder) {
// Append padding.
static const unsigned char padding[ALIGN] = {};
stream.write(padding, remainder);
end += remainder;
}
// Update the data size.
if (stream.fail()) return (std::streamoff)-1;
stream.seekp(start + sizeof(T_ID));
stream.write(&size, sizeof(size));
stream.seekp(end);
return end;
}
///
/// Helper struct for read/write of records to/from memory
///
template <class T, class T_ID, class T_SIZE, unsigned int ALIGN>
struct STDEX_API record
{
///
/// Constructs the struct
///
inline record( T &_data) : data( _data) {}
inline record(const T &_data) : data((T&)_data) {}
///
/// Assignment operator
///
/// \param[in] r Source record
///
/// \returns A const reference to this struct
///
inline const record<T, T_ID, T_SIZE, ALIGN>& operator =(const record<T, T_ID, T_SIZE, ALIGN> &r)
{
data = r.data;
return *this;
}
///
/// Writes record header
///
/// \param[in] stream Output stream
///
/// \returns Position of the record header start in \p stream. Save for later \c close call.
///
template <class T_STREAM>
static inline std::streamoff open(T_STREAM& stream)
{
return open<T_ID, T_SIZE, T_STREAM>(stream, id);
}
///
/// Updates record header
///
/// \param[in] stream Output stream
/// \param[in] start Start position of the record in \p stream
///
/// \returns Position of the record end in \p stream
///
template <class T_STREAM>
static inline std::streamoff close(T_STREAM& stream, std::streamoff start)
{
return close<T_ID, T_SIZE, ALIGN, T_STREAM>(stream, start);
}
///
/// Finds record data
///
/// \param[in] stream Input stream
/// \param[in] end Position limit. Default is -1 (no limit).
///
/// \returns
/// - true when found
/// - false otherwise
///
template <class T_STREAM>
static inline bool find(T_STREAM& stream, std::streamoff end = (std::streamoff)-1)
{
return find<T_ID, T_SIZE, ALIGN, T_STREAM>(stream, id, end);
}
static const T_ID id; ///< Record id
T &data; ///< Record data reference
};
};
};
template <class T, class T_ID, class T_SIZE, unsigned int ALIGN, class T_STREAM>
inline T_STREAM& operator <<(T_STREAM& stream, const stdex::idrec::record<T, T_ID, T_SIZE, ALIGN> r)
{
// Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway.
if (stream.fail()) return stream;
std::streamoff start = r.open(stream);
if (stream.fail()) return stream;
stream << r.data;
if (stream.fail()) return stream;
r.close(stream, start);
return stream;
}
template <class T, class T_ID, class T_SIZE, unsigned int ALIGN, class T_STREAM>
inline T_STREAM& operator >>(T_STREAM& stream, stdex::idrec::record<T, T_ID, T_SIZE, ALIGN> r)
{
// Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway.
// Read data size.
T_SIZE size;
stream.read(size, sizeof(size));
if (stream.fail()) return stream;
// Read data.
std::streamoff start = stream.tellg();
{
ROmejenaDatoteka _stream(&stream, start, size);
_stream >> r.data;
}
size += (T_SIZE)(ALIGN - size) % ALIGN;
stream.seekg(start + size);
return stream;
}

BIN
res/stdex.rc Normal file

Binary file not shown.

20
src/stdafx.cpp Normal file
View File

@ -0,0 +1,20 @@
/*
Copyright 2016 Amebis
This file is part of stdex.
stdex 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.
stdex 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 stdex. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"

22
src/stdafx.h Normal file
View File

@ -0,0 +1,22 @@
/*
Copyright 2016 Amebis
This file is part of stdex.
stdex 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.
stdex 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 stdex. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "../include/stdex/idrec.h"