gb.hpp - Namespaced Types

This commit is contained in:
gingerBill 2015-10-18 12:18:54 +01:00
parent 0c7b9852d8
commit 89941d395a
6 changed files with 1346 additions and 537 deletions

224
.gitignore vendored Normal file
View File

@ -0,0 +1,224 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Project Specific
misc/
*.sublime*
test.*

View File

@ -6,7 +6,7 @@ library | latest version | category | languages | description
----------------|----------------|----------|-----------|------------- ----------------|----------------|----------|-----------|-------------
**gb_string.h** | 0.93 | strings | C, C++ | A better string library for C & C++ **gb_string.h** | 0.93 | strings | C, C++ | A better string library for C & C++
**gb_ini.h** | 0.91 | misc | C, C++ | A simple ini file loader library for C & C++ **gb_ini.h** | 0.91 | misc | C, C++ | A simple ini file loader library for C & C++
**gb.hpp** | 0.13a | misc | C++11 | (Experimental) A C++11 helper library without STL geared towards game development **gb.hpp** | 0.15 | misc | C++11 | (Experimental) A C++11 helper library without STL geared towards game development
## FAQ ## FAQ

1536
gb.hpp

File diff suppressed because it is too large Load Diff

29
gb.sln Normal file
View File

@ -0,0 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{911E67C6-3D85-4FCE-B560-20A9C3E3FF48}") = "gb", "bin\gb.exe", "{5548FA62-E3AA-4E84-85B2-4CF1D02FE804}"
ProjectSection(DebuggerProjectSystem) = preProject
PortSupplier = 00000000-0000-0000-0000-000000000000
Executable = W:\gb\bin\gb.exe
RemoteMachine = BILL-PC
StartingDirectory = W:\gb
Environment = Default
LaunchingEngine = 00000000-0000-0000-0000-000000000000
UseLegacyDebugEngines = No
LaunchSQLEngine = No
AttachLaunchAction = No
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5548FA62-E3AA-4E84-85B2-4CF1D02FE804}.Debug|x64.ActiveCfg = Debug|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

87
src/main.cpp Normal file
View File

@ -0,0 +1,87 @@
#include "../gb.hpp"
struct Global_Allocators
{
gb::Heap_Allocator heap = {};
gb::Allocator* default_allocator = &heap;
};
global Global_Allocators g_allocators;
gb::Allocator& default_allocator()
{
return *g_allocators.default_allocator;
}
int main(int argc, char** argv)
{
// "Use" variables
argc; argv;
using namespace gb;
{
const u8 bytes[4] = {0x00, 0x20, 0xa7, 0x44};
f32 a = reinterpret_cast<const f32&>(bytes);
printf("%f\n", a);
const f32 f = 1337.0f;
u8* fb = (u8*)(&f);
printf("0x%x%x%x%x\n", fb[0], fb[1], fb[2], fb[3]);
}
#if 1
{
auto table = make_hash_table<f32>(default_allocator());
hash_table::set(table, 123, 321.0f);
hash_table::set(table, 456, 654.0f);
#define PGET(key, d) printf("%7d : %7f \n", key, hash_table::get(table, (key), (f32)(d)))
PGET(123, 0);
PGET(456, 0);
PGET(789, 0);
#undef PGET
}
{
String hello = string::make(default_allocator(), "Hello");
String world = string::make(default_allocator(), ", world!", 8);
defer(string::free(hello));
defer(string::free(world));
string::append(hello, world);
printf("%s\n", hello);
}
for (u32 i = 0; i < 8; i++)
{
u64 bins[10] = {};
auto gen = random::make_mt19937_64(random::next(random::make_random_device()));
for (usize i = 0; i < 200000; i++)
{
u64 result = random::uniform_u64_distribution(gen, 0, 9);
bins[result]++;
}
for (usize i = 0; i < 10; i++)
{
printf("%2d : ", i);;
u32 a = (u32)(bins[i] / 1000);
for (u32 i = 0; i < a; i++)
printf("*");
printf("\n");
}
time_sleep(seconds(1));
}
#endif
while (getchar() != '\n')
;
return 0;
}

5
src/unity_build.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "main.cpp"
#define GB_IMPLEMENTATION
#include "../gb.hpp"