Initial commit

This commit is contained in:
Stillkill committed 2026-03-08 15:26:08 -05:00
commit b0e73a61aa
16345 files changed
+3104967

No files matched your search

@@ -0,0 +1,409 @@
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cell/spurs.h>
#include "C4JSpursJob.h"
#include "C4JThread_SPU.h"
// #include "PS3\SPU_Tasks\SPUMemTools\SPUMemTools.h"
using namespace cell::Spurs::JobQueue;
static const unsigned int NUM_SUBMIT_JOBS = 128;
#define DMA_ALIGNMENT (128)
#define JOBHEADER_SYMBOL(JobName) _binary_jqjob_##JobName##_jobbin2_jobheader
C4JSpursJobQueue* C4JSpursJobQueue::m_pMainJobQueue = NULL;
uint16_t C4JSpursJobQueue::Port::s_jobTagBitmask = 0;
C4JSpursJobQueue::Port* C4JSpursJobQueue::Port::s_allocatedPorts[16] = {NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL };
bool C4JSpursJobQueue::Port::s_initialised;
CRITICAL_SECTION C4JSpursJobQueue::Port::s_lock;
C4JSpursJobQueue::C4JSpursJobQueue()
{
int ret;
cell::Spurs::Spurs* spurs = C4JThread_SPU::getSpurs2();
//E create job descriptor pool
const CellSpursJobQueueJobDescriptorPool poolDescriptor = {
0, 0, NUM_SUBMIT_JOBS, 0, 0, 0, 0, 0
};
unsigned int sizeOfJobDescriptorPool =
CELL_SPURS_JOBQUEUE_JOB_DESCRIPTOR_POOL_SIZE(0, 0, NUM_SUBMIT_JOBS, 0, 0, 0, 0, 0);
pPool = (uint8_t*)memalign(DMA_ALIGNMENT, sizeOfJobDescriptorPool);
//E create jobQueue
pJobQueue = (JobQueue<JOB_QUEUE_DEPTH>*)memalign(CELL_SPURS_JOBQUEUE_ALIGN, sizeof(JobQueue<JOB_QUEUE_DEPTH>));
assert(pJobQueue != NULL);
ret = JobQueue<JOB_QUEUE_DEPTH>::create( pJobQueue,
spurs,
"SampleJobQueue",
5, //numSpus
8, // priority
(void*)pPool,
&poolDescriptor,
4, // maxGrab
false, // submitWithEntryLock
false, // doBusyWaiting
false, //isHaltOnError
true, // autoPrxLoad
1 ); //uint8_t maxNumJobsOnASpu = CELL_SPURS_JOBQUEUE_DEFAULT_MAX_NUM_JOBS_ON_SPU,
assert(ret == CELL_OK);
(void)ret;
}
C4JSpursJobQueue::Port::Port(const char* portName)
{
m_portName = portName;
if(!s_initialised)
InitializeCriticalSection(&s_lock);
s_initialised = true;
EnterCriticalSection(&s_lock);
m_pPort2 = (Port2*)memalign(CELL_SPURS_JOBQUEUE_PORT2_ALIGN, CELL_SPURS_JOBQUEUE_PORT2_SIZE);
assert(m_pPort2);
int ret = Port2::create(m_pPort2, C4JSpursJobQueue::getMainJobQueue().pJobQueue);
assert(ret == CELL_OK);
m_jobTag = getFreeJobTag();
m_bDestroyed = false;
LeaveCriticalSection(&s_lock);
}
C4JSpursJobQueue::Port::~Port()
{
EnterCriticalSection(&s_lock);
releaseJobTag(m_jobTag);
if(!m_bDestroyed)
{
int ret = m_pPort2->destroy();
assert(ret == CELL_OK);
}
free(m_pPort2);
LeaveCriticalSection(&s_lock);
}
void C4JSpursJobQueue::Port::submitJob(C4JSpursJob* pJob)
{
if(m_bDestroyed)
return;
int ret;
//E submit job
ret = m_pPort2->copyPushJob(&pJob->m_job256.header, sizeof(CellSpursJob256), sizeof(CellSpursJob256), m_jobTag,
CELL_SPURS_JOBQUEUE_FLAG_SYNC_JOB);
if(ret != CELL_OK)
app.DebugPrintf("copyPushJob failed with error 0x%08x\n", ret);
assert(ret == CELL_OK);
}
void C4JSpursJobQueue::Port::waitForCompletion()
{
if(m_bDestroyed)
return;
int ret;
ret = m_pPort2->sync(0);
assert(ret == CELL_OK);
(void)ret; // remove unused var warning
}
bool C4JSpursJobQueue::Port::hasCompleted()
{
if(m_bDestroyed)
return true;
int ret;
ret = m_pPort2->sync(CELL_SPURS_JOBQUEUE_FLAG_NON_BLOCKING);
if(ret == CELL_SPURS_JOB_ERROR_AGAIN)
return false;
assert(ret == CELL_OK);
return true;
}
void C4JSpursJobQueue::Port::submitSync()
{
if(m_bDestroyed)
return;
int status;
status = m_pPort2->pushSync(1u << m_jobTag, 0);
assert(status == CELL_OK);
(void)status; // remove unused var warning
}
int C4JSpursJobQueue::Port::getFreeJobTag()
{
for(int i=0;i<16;i++)
{
if((s_jobTagBitmask & (1<<i)) == 0)
{
s_jobTagBitmask |= (1<<i);
s_allocatedPorts[i] = this;
return i;
}
}
assert(0);
return 0;
}
void C4JSpursJobQueue::Port::releaseJobTag( int tag )
{
s_jobTagBitmask &= ~(1<<tag);
s_allocatedPorts[tag] = NULL;
}
void C4JSpursJobQueue::Port::destroyAll()
{
// bit hacky, but the texture blit port seems to stall on destroy if we don't have this
// presumably because it uses a non-blocking sync
extern C4JSpursJobQueue::Port* g_texBlitJobQueuePort;
if(g_texBlitJobQueuePort)
{
g_texBlitJobQueuePort->waitForCompletion();
}
for(int i=0;i<16;i++)
{
if(s_allocatedPorts[i])
{
s_allocatedPorts[i]->m_bDestroyed = true;
int ret = s_allocatedPorts[i]->m_pPort2->destroy();
assert(ret == CELL_OK);
}
}
#ifndef _CONTENT_PACKAGE
printf("C4JSpursJobQueue::Port::destroyAll\n");
#endif
}
void C4JSpursJobQueue::shutdown()
{
Port::destroyAll();
int ret = pJobQueue->shutdown();
assert(ret == CELL_OK);
int exitCode;
ret = pJobQueue->join(&exitCode);
assert(ret == CELL_OK && exitCode == CELL_OK);
free(pJobQueue);
free(pPool);
#ifndef _CONTENT_PACKAGE
printf("C4JSpursJobQueue::shutdown\n");
#endif
}
C4JSpursJob::C4JSpursJob()
{
__builtin_memset(&m_job256, 0, sizeof(CellSpursJob256));
}
C4JSpursJob_CompressedTile::C4JSpursJob_CompressedTile(TileCompressData_SPU* pDataIn, unsigned char* pDataOut)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(CompressedTile);
//E create job
m_job256.header = JOBHEADER_SYMBOL(CompressedTile);
m_job256.header.sizeStack = (64*1024)>>4;
m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
m_job256.workArea.userData[1] = (uintptr_t)pDataOut;
}
C4JSpursJob_ChunkUpdate::C4JSpursJob_ChunkUpdate(ChunkRebuildData* pDataIn, ChunkRebuildData* pDataOut)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(ChunkUpdate);
//E create job
m_job256.header = JOBHEADER_SYMBOL(ChunkUpdate);
m_job256.header.sizeStack = (60*1024)>>4;
m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
m_job256.workArea.userData[1] = (uintptr_t)pDataOut;
assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
}
C4JSpursJob_LevelRenderer_cull::C4JSpursJob_LevelRenderer_cull(LevelRenderer_cull_DataIn* pDataIn)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(LevelRenderer_cull);
//E create job
m_job256.header = JOBHEADER_SYMBOL(LevelRenderer_cull);
m_job256.header.sizeStack = (200*1024)>>4; // this is extremely tight, global flags take up 164K
m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
}
C4JSpursJob_LevelRenderer_zSort::C4JSpursJob_LevelRenderer_zSort(LevelRenderer_cull_DataIn* pDataIn)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(LevelRenderer_zSort);
//E create job
m_job256.header = JOBHEADER_SYMBOL(LevelRenderer_zSort);
m_job256.header.sizeStack = (200*1024)>>4; // this is extremely tight, global flags take up 164K
m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
}
C4JSpursJob_LevelRenderer_FindNearestChunk::C4JSpursJob_LevelRenderer_FindNearestChunk(LevelRenderer_FindNearestChunk_DataIn* pDataIn)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(LevelRenderer_FindNearestChunk);
//E create job
m_job256.header = JOBHEADER_SYMBOL(LevelRenderer_FindNearestChunk);
m_job256.header.sizeStack = (200*1024)>>4; // this is extremely tight, global flags take up 164K
m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
}
// C4JSpursJob_Renderer_TextureUpdate::C4JSpursJob_Renderer_TextureUpdate(Renderer_TextureUpdate_DataIn* pDataIn)
// : C4JSpursJob()
// {
// extern const CellSpursJobHeader JOBHEADER_SYMBOL(Renderer_TextureUpdate);
// int ret;
// //E create job
// m_job256.header = JOBHEADER_SYMBOL(Renderer_TextureUpdate);
// m_job256.header.sizeStack = (200*1024)>>4;
// m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
//
// assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
//
// }
//
C4JSpursJob_Texture_blit::C4JSpursJob_Texture_blit(Texture_blit_DataIn* pDataIn)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(Texture_blit);
//E create job
m_job256.header = JOBHEADER_SYMBOL(Texture_blit);
m_job256.header.sizeStack = (200*1024)>>4;
m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
}
C4JSpursJob_CompressedTileStorage_compress::C4JSpursJob_CompressedTileStorage_compress(CompressedTileStorage_compress_dataIn* pDataIn)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(CompressedTileStorage_compress);
//E create job
m_job256.header = JOBHEADER_SYMBOL(CompressedTileStorage_compress);
m_job256.header.sizeStack = (200*1024)>>4;
m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
}
/*
C4JSpursJob_CompressedTileStorage_getData::C4JSpursJob_CompressedTileStorage_getData(unsigned char* pIdxAndData, int dataSize, unsigned char* pDst, unsigned int retOffset)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(CompressedTileStorage_getData);
int ret;
//E create job
m_job256.header = JOBHEADER_SYMBOL(CompressedTileStorage_getData);
m_job256.header.sizeStack = (200*1024)>>4;
m_job256.workArea.userData[0] = (uintptr_t)pIdxAndData;
m_job256.workArea.userData[1] = (uintptr_t)dataSize;
m_job256.workArea.userData[2] = (uintptr_t)pDst;
m_job256.workArea.userData[3] = (uintptr_t)retOffset;
assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
} */
// C4JSpursJob_GameRenderer_updateLightTexture::C4JSpursJob_GameRenderer_updateLightTexture(GameRenderer_updateLightTexture_dataIn* pDataIn)
// : C4JSpursJob()
// {
// extern const CellSpursJobHeader JOBHEADER_SYMBOL(GameRenderer_updateLightTexture);
// int ret;
// //E create job
// m_job256.header = JOBHEADER_SYMBOL(GameRenderer_updateLightTexture);
// m_job256.header.sizeStack = (200*1024)>>4;
// m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
//
// assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
//
// }
C4JSpursJob_PerlinNoise::C4JSpursJob_PerlinNoise(PerlinNoise_DataIn* pDataIn)
: C4JSpursJob()
{
extern const CellSpursJobHeader JOBHEADER_SYMBOL(PerlinNoise);
//E create job
m_job256.header = JOBHEADER_SYMBOL(PerlinNoise);
m_job256.header.sizeStack = (200*1024)>>4;
m_job256.workArea.userData[0] = (uintptr_t)pDataIn;
assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
}
// C4JSpursJob_MemSet::C4JSpursJob_MemSet(void* pMem, int numBytes, uint8_t val)
// : C4JSpursJob()
// {
// extern const CellSpursJobHeader JOBHEADER_SYMBOL(SPUMemTools);
// int ret;
// //E create job
// m_job256.header = JOBHEADER_SYMBOL(SPUMemTools);
// m_job256.header.sizeStack = (200*1024)>>4;
// m_job256.workArea.userData[0] = (uintptr_t)e_SPUMemToolsFunc_MemSet;
// m_job256.workArea.userData[1] = (uintptr_t)pMem;
// m_job256.workArea.userData[2] = (uintptr_t)numBytes;
// m_job256.workArea.userData[3] = (uintptr_t)val;
//
// assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
// }
// C4JSpursJob_RLECompress::C4JSpursJob_RLECompress(void* pSrc, int srcSize, void* pDst, int* pDstSize)
// : C4JSpursJob()
// {
// extern const CellSpursJobHeader JOBHEADER_SYMBOL(RLECompress);
// int ret;
// //E create job
// m_job256.header = JOBHEADER_SYMBOL(RLECompress);
// m_job256.header.sizeStack = (200*1024)>>4;
// m_job256.workArea.userData[0] = (uintptr_t)pSrc;
// m_job256.workArea.userData[1] = (uintptr_t)srcSize;
// m_job256.workArea.userData[2] = (uintptr_t)pDst;
// m_job256.workArea.userData[3] = (uintptr_t)pDstSize;
//
// assert(cellSpursJobQueueCheckJob(&m_job256, 256, 256) == CELL_OK);
// }
//
@@ -0,0 +1,205 @@
#pragma once
#include <cell/spurs.h>
#define JOBHEADER_SYMBOL(JobName) _binary_jqjob_##JobName##_jobbin2_jobheader
// class C4JSpursJobEventQueue
// {
// C4JThread* m_pollingThread;
// sys_event_port_t m_basicEventPort;
// sys_event_queue_t m_basicEventQueue;
//
// typedef int (C4JSpursJobEventQueueFunc)(uint64_t data1, uint64_t data2);
//
// int eventPoll(void* lpParam)
// {
// sys_event_t event;
// do
// {
// sys_event_queue_receive(m_basicEventQueue, &event, 0);
// C4JSpursJobEventQueueFunc* func = (C4JSpursJobEventQueueFunc*)event.data1;
// func(event.data2, event.data3);
// } while(1);
// return 0;
// }
//
// void CompressedTileStorage::compress_SPUSendEvent(int upgradeBlock/*=-1*/)
// {
// if(g_pCompressSPUThread == NULL)
// {
// sys_event_port_create(&g_basicEventPort, SYS_EVENT_PORT_LOCAL, SYS_EVENT_PORT_NO_NAME);
// sys_event_queue_attribute_t queue_attr = {SYS_SYNC_PRIORITY, SYS_PPU_QUEUE};
// sys_event_queue_create(&g_basicEventQueue, &queue_attr, SYS_EVENT_QUEUE_LOCAL, 127);
// sys_event_port_connect_local(g_basicEventPort, g_basicEventQueue);
//
// g_pCompressSPUThread = new C4JThread(compress_SPUEventPoll, this, "compress_SPU");
// g_pCompressSPUThread->Run();
// }
//
// sys_event_port_send(g_basicEventPort, (std::uint64_t)this, upgradeBlock, 0);
// }
//
// };
class C4JSpursJob
{
public:
CellSpursJob256 m_job256;
C4JSpursJob();
};
class TileCompressData_SPU;
class C4JSpursJob_CompressedTile : public C4JSpursJob
{
public:
C4JSpursJob_CompressedTile();
C4JSpursJob_CompressedTile(TileCompressData_SPU* pDataIn, unsigned char* pDataOut);
};
class ChunkRebuildData;
class C4JSpursJob_ChunkUpdate : public C4JSpursJob
{
public:
C4JSpursJob_ChunkUpdate();
C4JSpursJob_ChunkUpdate(ChunkRebuildData* pDataIn, ChunkRebuildData* pDataOut);
};
class LevelRenderer_cull_DataIn;
class C4JSpursJob_LevelRenderer_cull : public C4JSpursJob
{
public:
C4JSpursJob_LevelRenderer_cull();
C4JSpursJob_LevelRenderer_cull(LevelRenderer_cull_DataIn* pDataIn);
};
class C4JSpursJob_LevelRenderer_zSort : public C4JSpursJob
{
public:
C4JSpursJob_LevelRenderer_zSort();
C4JSpursJob_LevelRenderer_zSort(LevelRenderer_cull_DataIn* pDataIn);
};
class LevelRenderer_FindNearestChunk_DataIn;
class C4JSpursJob_LevelRenderer_FindNearestChunk : public C4JSpursJob
{
public:
C4JSpursJob_LevelRenderer_FindNearestChunk();
C4JSpursJob_LevelRenderer_FindNearestChunk(LevelRenderer_FindNearestChunk_DataIn* pDataIn);
};
// class Renderer_TextureUpdate_DataIn;
// class C4JSpursJob_Renderer_TextureUpdate : public C4JSpursJob
// {
// public:
// C4JSpursJob_Renderer_TextureUpdate();
// C4JSpursJob_Renderer_TextureUpdate(Renderer_TextureUpdate_DataIn* pDataIn);
// };
class Texture_blit_DataIn;
class C4JSpursJob_Texture_blit : public C4JSpursJob
{
public:
C4JSpursJob_Texture_blit();
C4JSpursJob_Texture_blit(Texture_blit_DataIn* pDataIn);
};
class CompressedTileStorage_compress_dataIn;
class C4JSpursJob_CompressedTileStorage_compress : public C4JSpursJob
{
public:
C4JSpursJob_CompressedTileStorage_compress();
C4JSpursJob_CompressedTileStorage_compress(CompressedTileStorage_compress_dataIn* pDataIn);
};
class C4JSpursJob_CompressedTileStorage_getData : public C4JSpursJob
{
public:
C4JSpursJob_CompressedTileStorage_getData();
C4JSpursJob_CompressedTileStorage_getData(unsigned char* pIdxAndData, int dataSize, unsigned char* pDst, unsigned int retOffset);
};
// class GameRenderer_updateLightTexture_dataIn;
// class C4JSpursJob_GameRenderer_updateLightTexture : public C4JSpursJob
// {
// public:
// C4JSpursJob_GameRenderer_updateLightTexture();
// C4JSpursJob_GameRenderer_updateLightTexture(GameRenderer_updateLightTexture_dataIn* pDataIn);
// };
class PerlinNoise_DataIn;
class C4JSpursJob_PerlinNoise : public C4JSpursJob
{
public:
C4JSpursJob_PerlinNoise();
C4JSpursJob_PerlinNoise(PerlinNoise_DataIn* pDataIn);
};
// class C4JSpursJob_MemSet : public C4JSpursJob
// {
// public:
// C4JSpursJob_MemSet();
// C4JSpursJob_MemSet(void* pMem, int numBytes, uint8_t val);
// };
// class C4JSpursJob_RLECompress : public C4JSpursJob
// {
// public:
// C4JSpursJob_RLECompress();
// C4JSpursJob_RLECompress(void* pSrc, int srcSize, void* pDst, int* pDstSize);
// };
class C4JSpursJobQueue
{
public:
class Port
{
static bool s_initialised;
static CRITICAL_SECTION s_lock;
static uint16_t s_jobTagBitmask;
static Port* s_allocatedPorts[16];
cell::Spurs::JobQueue::Port2* m_pPort2;
int m_jobTag;
bool m_bDestroyed;
const char* m_portName;
int getFreeJobTag();
void releaseJobTag(int tag);
public:
Port(const char* portName);
~Port();
static void destroyAll();
void submitJob(C4JSpursJob* pJob);
void waitForCompletion();
bool hasCompleted();
void submitSync();
};
private:
static const unsigned int JOB_QUEUE_DEPTH = 256;
static C4JSpursJobQueue* m_pMainJobQueue;
uint8_t *pPool;
cell::Spurs::JobQueue::JobQueue<JOB_QUEUE_DEPTH> *pJobQueue;
public:
static C4JSpursJobQueue& getMainJobQueue() {if(m_pMainJobQueue == NULL) m_pMainJobQueue = new C4JSpursJobQueue; return *m_pMainJobQueue;}
C4JSpursJobQueue();
void shutdown();
void submitJob(C4JSpursJob* pJob);
void waitForCompletion();
void submitSync();
};
@@ -0,0 +1,136 @@
#include "stdafx.h"
#include "C4JThread_SPU.h"
#include "PS3\SPU_Tasks\ChunkUpdate\ChunkRebuildData.h"
#include "PS3\SPU_Tasks\CompressedTile\CompressedTileStorage_SPU.h"
#include "PS3\SPU_Tasks\LevelRenderChunks\LevelRenderChunks.h"
#define SPURS_MAX_SPU 6
#define SPURS_PPU_THREAD_PRIORITY 2
#define SPURS_SPU_THREAD_PRIORITY 100
#define SPURS_PREFIX "Minecraft"
#define PRIMARY_PPU_THREAD_PRIORITY 1001
#define PRIMARY_PPU_THREAD_STACK_SIZE 65536
#define SPU_PRINTF_HANDLER_PRIORITY 999
static const bool sc_verbose = true;
cell::Spurs::Spurs2* C4JThread_SPU::ms_spurs2Object = NULL;
void C4JThread_SPU::initSPURS()
{
int ret;
#ifndef _CONTENT_PACKAGE
// initialize spu_printf server
ret = spu_printf_initialize(SPU_PRINTF_HANDLER_PRIORITY, 0);
if (ret)
{
std::printf("Error: spu_printf_initialize(): %#x\n", ret);
std::printf("## libspurs : FAILED ##\n");
std::abort();
}
#endif
// initialize SPURS attribute
cell::Spurs::SpursAttribute attribute;
ret = cell::Spurs::SpursAttribute::initialize(&attribute, SPURS_MAX_SPU - 1, SPURS_SPU_THREAD_PRIORITY, SPURS_PPU_THREAD_PRIORITY, false);
if (ret)
{
#ifndef _CONTENT_PACKAGE
std::printf("Error: cell::Spurs::SpursAttribute::initialize(): %#x\n", ret);
std::printf("## libspurs : FAILED ##\n");
#endif
std::abort();
}
ret = attribute.setNamePrefix(SPURS_PREFIX, std::strlen(SPURS_PREFIX));
if (ret)
{
#ifndef _CONTENT_PACKAGE
std::printf("Error: attribute.setNamePrefix(): %#x\n", ret);
std::printf("## libspurs : FAILED ##\n");
#endif
std::abort();
}
ret = attribute.setSpuThreadGroupType(SYS_SPU_THREAD_GROUP_TYPE_EXCLUSIVE_NON_CONTEXT);
if (ret)
{
#ifndef _CONTENT_PACKAGE
std::printf("Error: attribute.setSpuThreadGroupType(): %#x\n", ret);
std::printf("## libspurs : FAILED ##\n");
#endif
std::abort();
}
#ifndef _CONTENT_PACKAGE
ret = attribute.enableSpuPrintfIfAvailable();
if (ret)
{
std::printf("Error: attribute.enableSpuPrintfIfAvailable(): %#x\n", ret);
std::printf("## libspurs : FAILED ##\n");
std::abort();
}
#endif
// allocate memory
ms_spurs2Object = new cell::Spurs::Spurs2;
if (ms_spurs2Object == 0)
{
#ifndef _CONTENT_PACKAGE
std::printf("Error: new cell::Spurs::Spurs2\n");
std::printf("## libspurs : FAILED ##\n");
#endif
std::abort();
}
// create SPURS instance
ret = cell::Spurs::Spurs2::initialize(ms_spurs2Object, &attribute);
if (ret)
{
#ifndef _CONTENT_PACKAGE
std::printf("Error: cell::Spurs::Spurs2::initialize(): %#x\n", ret);
std::printf("## libspurs : FAILED ##\n");
#endif
std::abort();
}
}
void C4JThread_SPU::shutdownSPURS()
{
int ret;
// destroy SPURS instance
ret = ms_spurs2Object->finalize();
if (ret)
{
#ifndef _CONTENT_PACKAGE
std::printf("Error: spurs->finalize(): %#x\n", ret);
std::printf("## libspurs : FAILED ##\n");
#endif
std::abort();
}
// free memory
delete ms_spurs2Object;
#ifndef _CONTENT_PACKAGE
// finalize spu_printf server
ret = spu_printf_finalize();
if (ret)
{
std::printf("Error: spu_printf_finalize(): %#x\n", ret);
std::printf("## libspurs : FAILED ##\n");
std::abort();
}
#endif
}
@@ -0,0 +1,31 @@
#pragma once
#undef __in
#undef __out
// standard C libraries
#include <cstdio> // printf
#include <cstdlib> // abort
#include <cstring> // strlen
#include <sys/spu_thread_group.h> // SYS_SPU_THREAD_GROUP_TYPE_EXCLUSIVE_NON_CONTEXT
#include <sys/process.h> // SYS_PROCESS_PARAM
#include <cell/spurs.h>
#ifndef _CONTENTPACKAGE
#include <spu_printf.h>
#endif
class C4JThread_SPU
{
static cell::Spurs::Spurs2* ms_spurs2Object;
public:
static void initSPURS();
static void shutdownSPURS();
static cell::Spurs::Spurs2* getSpurs2() { return ms_spurs2Object; }
};
@@ -0,0 +1,339 @@
//-------------------------------------------------------------------------------------
// DirectXCollision.h -- C++ Collision Math library
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma once
#endif
#include "DirectXMath.h"
namespace DirectX
{
enum ContainmentType
{
DISJOINT = 0,
INTERSECTS = 1,
CONTAINS = 2,
};
enum PlaneIntersectionType
{
FRONT = 0,
INTERSECTING = 1,
BACK = 2,
};
struct BoundingBox;
struct BoundingOrientedBox;
struct BoundingFrustum;
#pragma warning(push)
#pragma warning(disable:4324 4820)
//-------------------------------------------------------------------------------------
// Bounding sphere
//-------------------------------------------------------------------------------------
struct BoundingSphere
{
XMFLOAT3 Center; // Center of the sphere.
float Radius; // Radius of the sphere.
// Creators
BoundingSphere() : Center(0,0,0), Radius( 1.f ) {}
BoundingSphere( _In_ const XMFLOAT3& center, _In_ float radius )
: Center(center), Radius(radius) { assert( radius >= 0.f ); };
BoundingSphere( _In_ const BoundingSphere& sp )
: Center(sp.Center), Radius(sp.Radius) {}
// Methods
BoundingSphere& operator=( _In_ const BoundingSphere& sp ) { Center = sp.Center; Radius = sp.Radius; return *this; }
void Transform( _Out_ BoundingSphere& Out, _In_ CXMMATRIX M ) const;
void Transform( _Out_ BoundingSphere& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation ) const;
// Transform the sphere
ContainmentType Contains( _In_ FXMVECTOR Point ) const;
ContainmentType Contains( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const;
ContainmentType Contains( _In_ const BoundingSphere& sh ) const;
ContainmentType Contains( _In_ const BoundingBox& box ) const;
ContainmentType Contains( _In_ const BoundingOrientedBox& box ) const;
ContainmentType Contains( _In_ const BoundingFrustum& fr ) const;
bool Intersects( _In_ const BoundingSphere& sh ) const;
bool Intersects( _In_ const BoundingBox& box ) const;
bool Intersects( _In_ const BoundingOrientedBox& box ) const;
bool Intersects( _In_ const BoundingFrustum& fr ) const;
bool Intersects( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const;
// Triangle-sphere test
PlaneIntersectionType Intersects( _In_ FXMVECTOR Plane ) const;
// Plane-sphere test
bool Intersects( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float& Dist ) const;
// Ray-sphere test
ContainmentType ContainedBy( _In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
_In_ GXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 ) const;
// Test sphere against six planes (see BoundingFrustum::GetPlanes)
// Static methods
static void CreateMerged( _Out_ BoundingSphere& Out, _In_ const BoundingSphere& S1, _In_ const BoundingSphere& S2 );
static void CreateFromBoundingBox( _Out_ BoundingSphere& Out, _In_ const BoundingBox& box );
static void CreateFromBoundingBox( _Out_ BoundingSphere& Out, _In_ const BoundingOrientedBox& box );
static void CreateFromPoints( _Out_ BoundingSphere& Out, _In_ size_t Count,
_In_reads_bytes_(sizeof(XMFLOAT3)+Stride*(Count-1)) const XMFLOAT3* pPoints, _In_ size_t Stride );
static void CreateFromFrustum( _Out_ BoundingSphere& Out, _In_ const BoundingFrustum& fr );
};
//-------------------------------------------------------------------------------------
// Axis-aligned bounding box
//-------------------------------------------------------------------------------------
struct BoundingBox
{
static const size_t CORNER_COUNT = 8;
XMFLOAT3 Center; // Center of the box.
XMFLOAT3 Extents; // Distance from the center to each side.
// Creators
BoundingBox() : Center(0,0,0), Extents( 1.f, 1.f, 1.f ) {}
BoundingBox( _In_ const XMFLOAT3& center, _In_ const XMFLOAT3& extents )
: Center(center), Extents(extents) { assert(extents.x >= 0 && extents.y >= 0 && extents.z >= 0); }
BoundingBox( _In_ const BoundingBox& box ) : Center(box.Center), Extents(box.Extents) {}
// Methods
BoundingBox& operator=( _In_ const BoundingBox& box) { Center = box.Center; Extents = box.Extents; return *this; }
void Transform( _Out_ BoundingBox& Out, _In_ CXMMATRIX M ) const;
void Transform( _Out_ BoundingBox& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation ) const;
void GetCorners( _Out_writes_(8) XMFLOAT3* Corners ) const;
// Gets the 8 corners of the box
ContainmentType Contains( _In_ FXMVECTOR Point ) const;
ContainmentType Contains( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const;
ContainmentType Contains( _In_ const BoundingSphere& sh ) const;
ContainmentType Contains( _In_ const BoundingBox& box ) const;
ContainmentType Contains( _In_ const BoundingOrientedBox& box ) const;
ContainmentType Contains( _In_ const BoundingFrustum& fr ) const;
bool Intersects( _In_ const BoundingSphere& sh ) const;
bool Intersects( _In_ const BoundingBox& box ) const;
bool Intersects( _In_ const BoundingOrientedBox& box ) const;
bool Intersects( _In_ const BoundingFrustum& fr ) const;
bool Intersects( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const;
// Triangle-Box test
PlaneIntersectionType Intersects( _In_ FXMVECTOR Plane ) const;
// Plane-box test
bool Intersects( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float& Dist ) const;
// Ray-Box test
ContainmentType ContainedBy( _In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
_In_ GXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 ) const;
// Test box against six planes (see BoundingFrustum::GetPlanes)
// Static methods
static void CreateMerged( _Out_ BoundingBox& Out, _In_ const BoundingBox& b1, _In_ const BoundingBox& b2 );
static void CreateFromSphere( _Out_ BoundingBox& Out, _In_ const BoundingSphere& sh );
static void CreateFromPoints( _Out_ BoundingBox& Out, _In_ FXMVECTOR pt1, _In_ FXMVECTOR pt2 );
static void CreateFromPoints( _Out_ BoundingBox& Out, _In_ size_t Count,
_In_reads_bytes_(sizeof(XMFLOAT3)+Stride*(Count-1)) const XMFLOAT3* pPoints, _In_ size_t Stride );
};
//-------------------------------------------------------------------------------------
// Oriented bounding box
//-------------------------------------------------------------------------------------
struct BoundingOrientedBox
{
static const size_t CORNER_COUNT = 8;
XMFLOAT3 Center; // Center of the box.
XMFLOAT3 Extents; // Distance from the center to each side.
XMFLOAT4 Orientation; // Unit quaternion representing rotation (box -> world).
// Creators
BoundingOrientedBox() : Center(0,0,0), Extents( 1.f, 1.f, 1.f ), Orientation(0,0,0, 1.f ) {}
BoundingOrientedBox( _In_ const XMFLOAT3& _Center, _In_ const XMFLOAT3& _Extents, _In_ const XMFLOAT4& _Orientation )
: Center(_Center), Extents(_Extents), Orientation(_Orientation)
{
assert(_Extents.x >= 0 && _Extents.y >= 0 && _Extents.z >= 0);
}
BoundingOrientedBox( _In_ const BoundingOrientedBox& box )
: Center(box.Center), Extents(box.Extents), Orientation(box.Orientation) {}
// Methods
BoundingOrientedBox& operator=( _In_ const BoundingOrientedBox& box ) { Center = box.Center; Extents = box.Extents; Orientation = box.Orientation; return *this; }
void Transform( _Out_ BoundingOrientedBox& Out, _In_ CXMMATRIX M ) const;
void Transform( _Out_ BoundingOrientedBox& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation ) const;
void GetCorners( _Out_writes_(8) XMFLOAT3* Corners ) const;
// Gets the 8 corners of the box
ContainmentType Contains( _In_ FXMVECTOR Point ) const;
ContainmentType Contains( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const;
ContainmentType Contains( _In_ const BoundingSphere& sh ) const;
ContainmentType Contains( _In_ const BoundingBox& box ) const;
ContainmentType Contains( _In_ const BoundingOrientedBox& box ) const;
ContainmentType Contains( _In_ const BoundingFrustum& fr ) const;
bool Intersects( _In_ const BoundingSphere& sh ) const;
bool Intersects( _In_ const BoundingBox& box ) const;
bool Intersects( _In_ const BoundingOrientedBox& box ) const;
bool Intersects( _In_ const BoundingFrustum& fr ) const;
bool Intersects( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const;
// Triangle-OrientedBox test
PlaneIntersectionType Intersects( _In_ FXMVECTOR Plane ) const;
// Plane-OrientedBox test
bool Intersects( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float& Dist ) const;
// Ray-OrientedBox test
ContainmentType ContainedBy( _In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
_In_ GXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 ) const;
// Test OrientedBox against six planes (see BoundingFrustum::GetPlanes)
// Static methods
static void CreateFromBoundingBox( _Out_ BoundingOrientedBox& Out, _In_ const BoundingBox& box );
static void CreateFromPoints( _Out_ BoundingOrientedBox& Out, _In_ size_t Count,
_In_reads_bytes_(sizeof(XMFLOAT3)+Stride*(Count-1)) const XMFLOAT3* pPoints, _In_ size_t Stride );
};
//-------------------------------------------------------------------------------------
// Bounding frustum
//-------------------------------------------------------------------------------------
struct BoundingFrustum
{
static const size_t CORNER_COUNT = 8;
XMFLOAT3 Origin; // Origin of the frustum (and projection).
XMFLOAT4 Orientation; // Quaternion representing rotation.
float RightSlope; // Positive X slope (X/Z).
float LeftSlope; // Negative X slope.
float TopSlope; // Positive Y slope (Y/Z).
float BottomSlope; // Negative Y slope.
float Near, Far; // Z of the near plane and far plane.
// Creators
BoundingFrustum() : Origin(0,0,0), Orientation(0,0,0, 1.f), RightSlope( 1.f ), LeftSlope( -1.f ),
TopSlope( 1.f ), BottomSlope( -1.f ), Near(0), Far( 1.f ) {}
BoundingFrustum( _In_ const XMFLOAT3& _Origin, _In_ const XMFLOAT4& _Orientation,
_In_ float _RightSlope, _In_ float _LeftSlope, _In_ float _TopSlope, _In_ float _BottomSlope,
_In_ float _Near, _In_ float _Far )
: Origin(_Origin), Orientation(_Orientation),
RightSlope(_RightSlope), LeftSlope(_LeftSlope), TopSlope(_TopSlope), BottomSlope(_BottomSlope),
Near(_Near), Far(_Far) { assert( _Near <= _Far ); }
BoundingFrustum( _In_ const BoundingFrustum& fr )
: Origin(fr.Origin), Orientation(fr.Orientation), RightSlope(fr.RightSlope), LeftSlope(fr.LeftSlope),
TopSlope(fr.TopSlope), BottomSlope(fr.BottomSlope), Near(fr.Near), Far(fr.Far) {}
BoundingFrustum( _In_ CXMMATRIX Projection ) { CreateFromMatrix( *this, Projection ); }
// Methods
BoundingFrustum& operator=( _In_ const BoundingFrustum& fr ) { Origin=fr.Origin; Orientation=fr.Orientation;
RightSlope=fr.RightSlope; LeftSlope=fr.LeftSlope;
TopSlope=fr.TopSlope; BottomSlope=fr.BottomSlope;
Near=fr.Near; Far=fr.Far; return *this; }
void Transform( _Out_ BoundingFrustum& Out, _In_ CXMMATRIX M ) const;
void Transform( _Out_ BoundingFrustum& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation ) const;
void GetCorners( _Out_writes_(8) XMFLOAT3* Corners ) const;
// Gets the 8 corners of the frustum
ContainmentType Contains( _In_ FXMVECTOR Point ) const;
ContainmentType Contains( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const;
ContainmentType Contains( _In_ const BoundingSphere& sp ) const;
ContainmentType Contains( _In_ const BoundingBox& box ) const;
ContainmentType Contains( _In_ const BoundingOrientedBox& box ) const;
ContainmentType Contains( _In_ const BoundingFrustum& fr ) const;
// Frustum-Frustum test
bool Intersects( _In_ const BoundingSphere& sh ) const;
bool Intersects( _In_ const BoundingBox& box ) const;
bool Intersects( _In_ const BoundingOrientedBox& box ) const;
bool Intersects( _In_ const BoundingFrustum& fr ) const;
bool Intersects( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const;
// Triangle-Frustum test
PlaneIntersectionType Intersects( _In_ FXMVECTOR Plane ) const;
// Plane-Frustum test
bool Intersects( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float& Dist ) const;
// Ray-Frustum test
ContainmentType ContainedBy( _In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
_In_ GXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 ) const;
// Test frustum against six planes (see BoundingFrustum::GetPlanes)
void GetPlanes( _Out_opt_ XMVECTOR* NearPlane, _Out_opt_ XMVECTOR* FarPlane, _Out_opt_ XMVECTOR* RightPlane,
_Out_opt_ XMVECTOR* LeftPlane, _Out_opt_ XMVECTOR* TopPlane, _Out_opt_ XMVECTOR* BottomPlane ) const;
// Create 6 Planes representation of Frustum
// Static methods
static void CreateFromMatrix( _Out_ BoundingFrustum& Out, _In_ CXMMATRIX Projection );
};
//-----------------------------------------------------------------------------
// Triangle intersection testing routines.
//-----------------------------------------------------------------------------
namespace TriangleTests
{
bool Intersects( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _In_ FXMVECTOR V0, _In_ GXMVECTOR V1, _In_ CXMVECTOR V2, _Out_ float& Dist );
// Ray-Triangle
bool Intersects( _In_ FXMVECTOR A0, _In_ FXMVECTOR A1, _In_ FXMVECTOR A2, _In_ GXMVECTOR B0, _In_ CXMVECTOR B1, _In_ CXMVECTOR B2 );
// Triangle-Triangle
PlaneIntersectionType Intersects( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2, _In_ GXMVECTOR Plane );
// Plane-Triangle
ContainmentType ContainedBy( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2,
_In_ GXMVECTOR Plane0, _In_ CXMVECTOR Plane1, _In_ CXMVECTOR Plane2,
_In_ CXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 );
// Test a triangle against six planes at once (see BoundingFrustum::GetPlanes)
};
#pragma warning(pop)
/****************************************************************************
*
* Implementation
*
****************************************************************************/
#pragma warning(push)
#pragma warning(disable : 4068 4616 6001)
#pragma prefast(push)
#pragma prefast(disable : 25000, "FXMVECTOR is 16 bytes")
#include "DirectXCollision.inl"
#pragma prefast(pop)
#pragma warning(pop)
}; // namespace DirectX
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,168 @@
//-------------------------------------------------------------------------------------
// DirectXColors.h -- C++ Color Math library
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma once
#endif
#include "DirectXMath.h"
namespace DirectX
{
namespace Colors
{
// Standard colors (Red/Green/Blue/Alpha)
XMGLOBALCONST XMVECTORF32 AliceBlue = {0.941176534f, 0.972549081f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 AntiqueWhite = {0.980392218f, 0.921568692f, 0.843137324f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Aqua = {0.000000000f, 1.000000000f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Aquamarine = {0.498039246f, 1.000000000f, 0.831372619f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Azure = {0.941176534f, 1.000000000f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Beige = {0.960784376f, 0.960784376f, 0.862745166f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Bisque = {1.000000000f, 0.894117713f, 0.768627524f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Black = {0.000000000f, 0.000000000f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 BlanchedAlmond = {1.000000000f, 0.921568692f, 0.803921640f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Blue = {0.000000000f, 0.000000000f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 BlueViolet = {0.541176498f, 0.168627456f, 0.886274576f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Brown = {0.647058845f, 0.164705887f, 0.164705887f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 BurlyWood = {0.870588303f, 0.721568644f, 0.529411793f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 CadetBlue = {0.372549027f, 0.619607866f, 0.627451003f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Chartreuse = {0.498039246f, 1.000000000f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Chocolate = {0.823529482f, 0.411764741f, 0.117647067f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Coral = {1.000000000f, 0.498039246f, 0.313725501f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 CornflowerBlue = {0.392156899f, 0.584313750f, 0.929411829f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Cornsilk = {1.000000000f, 0.972549081f, 0.862745166f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Crimson = {0.862745166f, 0.078431375f, 0.235294133f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Cyan = {0.000000000f, 1.000000000f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkBlue = {0.000000000f, 0.000000000f, 0.545098066f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkCyan = {0.000000000f, 0.545098066f, 0.545098066f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkGoldenrod = {0.721568644f, 0.525490224f, 0.043137256f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkGray = {0.662745118f, 0.662745118f, 0.662745118f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkGreen = {0.000000000f, 0.392156899f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkKhaki = {0.741176486f, 0.717647076f, 0.419607878f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkMagenta = {0.545098066f, 0.000000000f, 0.545098066f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkOliveGreen = {0.333333343f, 0.419607878f, 0.184313729f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkOrange = {1.000000000f, 0.549019635f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkOrchid = {0.600000024f, 0.196078449f, 0.800000072f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkRed = {0.545098066f, 0.000000000f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkSalmon = {0.913725555f, 0.588235319f, 0.478431404f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkSeaGreen = {0.560784340f, 0.737254918f, 0.545098066f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkSlateBlue = {0.282352954f, 0.239215702f, 0.545098066f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkSlateGray = {0.184313729f, 0.309803933f, 0.309803933f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkTurquoise = {0.000000000f, 0.807843208f, 0.819607913f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DarkViolet = {0.580392182f, 0.000000000f, 0.827451050f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DeepPink = {1.000000000f, 0.078431375f, 0.576470613f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DeepSkyBlue = {0.000000000f, 0.749019623f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DimGray = {0.411764741f, 0.411764741f, 0.411764741f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 DodgerBlue = {0.117647067f, 0.564705908f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Firebrick = {0.698039234f, 0.133333340f, 0.133333340f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 FloralWhite = {1.000000000f, 0.980392218f, 0.941176534f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 ForestGreen = {0.133333340f, 0.545098066f, 0.133333340f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Fuchsia = {1.000000000f, 0.000000000f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Gainsboro = {0.862745166f, 0.862745166f, 0.862745166f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 GhostWhite = {0.972549081f, 0.972549081f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Gold = {1.000000000f, 0.843137324f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Goldenrod = {0.854902029f, 0.647058845f, 0.125490203f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Gray = {0.501960814f, 0.501960814f, 0.501960814f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Green = {0.000000000f, 0.501960814f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 GreenYellow = {0.678431392f, 1.000000000f, 0.184313729f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Honeydew = {0.941176534f, 1.000000000f, 0.941176534f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 HotPink = {1.000000000f, 0.411764741f, 0.705882370f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 IndianRed = {0.803921640f, 0.360784322f, 0.360784322f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Indigo = {0.294117659f, 0.000000000f, 0.509803951f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Ivory = {1.000000000f, 1.000000000f, 0.941176534f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Khaki = {0.941176534f, 0.901960850f, 0.549019635f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Lavender = {0.901960850f, 0.901960850f, 0.980392218f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LavenderBlush = {1.000000000f, 0.941176534f, 0.960784376f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LawnGreen = {0.486274540f, 0.988235354f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LemonChiffon = {1.000000000f, 0.980392218f, 0.803921640f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightBlue = {0.678431392f, 0.847058892f, 0.901960850f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightCoral = {0.941176534f, 0.501960814f, 0.501960814f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightCyan = {0.878431439f, 1.000000000f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightGoldenrodYellow = {0.980392218f, 0.980392218f, 0.823529482f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightGreen = {0.564705908f, 0.933333397f, 0.564705908f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightGray = {0.827451050f, 0.827451050f, 0.827451050f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightPink = {1.000000000f, 0.713725507f, 0.756862819f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightSalmon = {1.000000000f, 0.627451003f, 0.478431404f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightSeaGreen = {0.125490203f, 0.698039234f, 0.666666687f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightSkyBlue = {0.529411793f, 0.807843208f, 0.980392218f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightSlateGray = {0.466666698f, 0.533333361f, 0.600000024f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightSteelBlue = {0.690196097f, 0.768627524f, 0.870588303f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LightYellow = {1.000000000f, 1.000000000f, 0.878431439f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Lime = {0.000000000f, 1.000000000f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 LimeGreen = {0.196078449f, 0.803921640f, 0.196078449f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Linen = {0.980392218f, 0.941176534f, 0.901960850f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Magenta = {1.000000000f, 0.000000000f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Maroon = {0.501960814f, 0.000000000f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumAquamarine = {0.400000036f, 0.803921640f, 0.666666687f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumBlue = {0.000000000f, 0.000000000f, 0.803921640f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumOrchid = {0.729411781f, 0.333333343f, 0.827451050f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumPurple = {0.576470613f, 0.439215720f, 0.858823597f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumSeaGreen = {0.235294133f, 0.701960802f, 0.443137288f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumSlateBlue = {0.482352972f, 0.407843173f, 0.933333397f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumSpringGreen = {0.000000000f, 0.980392218f, 0.603921592f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumTurquoise = {0.282352954f, 0.819607913f, 0.800000072f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MediumVioletRed = {0.780392230f, 0.082352944f, 0.521568656f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MidnightBlue = {0.098039225f, 0.098039225f, 0.439215720f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MintCream = {0.960784376f, 1.000000000f, 0.980392218f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 MistyRose = {1.000000000f, 0.894117713f, 0.882353008f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Moccasin = {1.000000000f, 0.894117713f, 0.709803939f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 NavajoWhite = {1.000000000f, 0.870588303f, 0.678431392f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Navy = {0.000000000f, 0.000000000f, 0.501960814f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 OldLace = {0.992156923f, 0.960784376f, 0.901960850f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Olive = {0.501960814f, 0.501960814f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 OliveDrab = {0.419607878f, 0.556862772f, 0.137254909f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Orange = {1.000000000f, 0.647058845f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 OrangeRed = {1.000000000f, 0.270588249f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Orchid = {0.854902029f, 0.439215720f, 0.839215755f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 PaleGoldenrod = {0.933333397f, 0.909803987f, 0.666666687f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 PaleGreen = {0.596078455f, 0.984313786f, 0.596078455f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 PaleTurquoise = {0.686274529f, 0.933333397f, 0.933333397f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 PaleVioletRed = {0.858823597f, 0.439215720f, 0.576470613f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 PapayaWhip = {1.000000000f, 0.937254965f, 0.835294187f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 PeachPuff = {1.000000000f, 0.854902029f, 0.725490212f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Peru = {0.803921640f, 0.521568656f, 0.247058839f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Pink = {1.000000000f, 0.752941251f, 0.796078503f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Plum = {0.866666734f, 0.627451003f, 0.866666734f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 PowderBlue = {0.690196097f, 0.878431439f, 0.901960850f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Purple = {0.501960814f, 0.000000000f, 0.501960814f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Red = {1.000000000f, 0.000000000f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 RosyBrown = {0.737254918f, 0.560784340f, 0.560784340f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 RoyalBlue = {0.254901975f, 0.411764741f, 0.882353008f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SaddleBrown = {0.545098066f, 0.270588249f, 0.074509807f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Salmon = {0.980392218f, 0.501960814f, 0.447058856f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SandyBrown = {0.956862807f, 0.643137276f, 0.376470625f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SeaGreen = {0.180392161f, 0.545098066f, 0.341176480f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SeaShell = {1.000000000f, 0.960784376f, 0.933333397f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Sienna = {0.627451003f, 0.321568638f, 0.176470593f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Silver = {0.752941251f, 0.752941251f, 0.752941251f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SkyBlue = {0.529411793f, 0.807843208f, 0.921568692f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SlateBlue = {0.415686309f, 0.352941185f, 0.803921640f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SlateGray = {0.439215720f, 0.501960814f, 0.564705908f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Snow = {1.000000000f, 0.980392218f, 0.980392218f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SpringGreen = {0.000000000f, 1.000000000f, 0.498039246f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 SteelBlue = {0.274509817f, 0.509803951f, 0.705882370f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Tan = {0.823529482f, 0.705882370f, 0.549019635f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Teal = {0.000000000f, 0.501960814f, 0.501960814f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Thistle = {0.847058892f, 0.749019623f, 0.847058892f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Tomato = {1.000000000f, 0.388235331f, 0.278431386f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Transparent = {0.000000000f, 0.000000000f, 0.000000000f, 0.000000000f};
XMGLOBALCONST XMVECTORF32 Turquoise = {0.250980407f, 0.878431439f, 0.815686345f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Violet = {0.933333397f, 0.509803951f, 0.933333397f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Wheat = {0.960784376f, 0.870588303f, 0.701960802f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 White = {1.000000000f, 1.000000000f, 1.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 WhiteSmoke = {0.960784376f, 0.960784376f, 0.960784376f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 Yellow = {1.000000000f, 1.000000000f, 0.000000000f, 1.000000000f};
XMGLOBALCONST XMVECTORF32 YellowGreen = {0.603921592f, 0.803921640f, 0.196078449f, 1.000000000f};
}; // namespace Colors
}; // namespace DirectX
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,995 @@
//-------------------------------------------------------------------------------------
// DirectXPackedVector.h -- SIMD C++ Math library
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma once
#endif
#include "DirectXMath.h"
namespace DirectX
{
namespace PackedVector
{
#ifdef _XM_BIGENDIAN_
#pragma bitfield_order(push)
#pragma bitfield_order(lsb_to_msb)
#endif
#pragma warning(push)
#pragma warning(disable:4201 4365 4324)
//------------------------------------------------------------------------------
// ARGB Color; 8-8-8-8 bit unsigned normalized integer components packed into
// a 32 bit integer. The normalized color is packed into 32 bits using 8 bit
// unsigned, normalized integers for the alpha, red, green, and blue components.
// The alpha component is stored in the most significant bits and the blue
// component in the least significant bits (A8R8G8B8):
// [32] aaaaaaaa rrrrrrrr gggggggg bbbbbbbb [0]
struct XMCOLOR
{
union
{
struct
{
uint8_t b; // Blue: 0/255 to 255/255
uint8_t g; // Green: 0/255 to 255/255
uint8_t r; // Red: 0/255 to 255/255
uint8_t a; // Alpha: 0/255 to 255/255
};
uint32_t c;
};
XMCOLOR() {}
XMCOLOR(uint32_t Color) : c(Color) {}
XMCOLOR(float _r, float _g, float _b, float _a);
explicit XMCOLOR(_In_reads_(4) const float *pArray);
operator uint32_t () const { return c; }
XMCOLOR& operator= (const XMCOLOR& Color) { c = Color.c; return *this; }
XMCOLOR& operator= (const uint32_t Color) { c = Color; return *this; }
};
//------------------------------------------------------------------------------
// 16 bit floating point number consisting of a sign bit, a 5 bit biased
// exponent, and a 10 bit mantissa
typedef uint16_t HALF;
//------------------------------------------------------------------------------
// 2D Vector; 16 bit floating point components
struct XMHALF2
{
union
{
struct
{
HALF x;
HALF y;
};
uint32_t v;
};
XMHALF2() {}
explicit XMHALF2(uint32_t Packed) : v(Packed) {}
XMHALF2(HALF _x, HALF _y) : x(_x), y(_y) {}
explicit XMHALF2(_In_reads_(2) const HALF *pArray) : x(pArray[0]), y(pArray[1]) {}
XMHALF2(float _x, float _y);
explicit XMHALF2(_In_reads_(2) const float *pArray);
XMHALF2& operator= (const XMHALF2& Half2) { x = Half2.x; y = Half2.y; return *this; }
XMHALF2& operator= (uint32_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 2D Vector; 16 bit signed normalized integer components
struct XMSHORTN2
{
union
{
struct
{
int16_t x;
int16_t y;
};
uint32_t v;
};
XMSHORTN2() {}
explicit XMSHORTN2(uint32_t Packed) : v(Packed) {}
XMSHORTN2(int16_t _x, int16_t _y) : x(_x), y(_y) {}
explicit XMSHORTN2(_In_reads_(2) const int16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
XMSHORTN2(float _x, float _y);
explicit XMSHORTN2(_In_reads_(2) const float *pArray);
XMSHORTN2& operator= (const XMSHORTN2& ShortN2) { x = ShortN2.x; y = ShortN2.y; return *this; }
XMSHORTN2& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 2D Vector; 16 bit signed integer components
struct XMSHORT2
{
union
{
struct
{
int16_t x;
int16_t y;
};
uint32_t v;
};
XMSHORT2() {}
explicit XMSHORT2(uint32_t Packed) : v(Packed) {}
XMSHORT2(int16_t _x, int16_t _y) : x(_x), y(_y) {}
explicit XMSHORT2(_In_reads_(2) const int16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
XMSHORT2(float _x, float _y);
explicit XMSHORT2(_In_reads_(2) const float *pArray);
XMSHORT2& operator= (const XMSHORT2& Short2) { x = Short2.x; y = Short2.y; return *this; }
XMSHORT2& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 2D Vector; 16 bit unsigned normalized integer components
struct XMUSHORTN2
{
union
{
struct
{
uint16_t x;
uint16_t y;
};
uint32_t v;
};
XMUSHORTN2() {}
explicit XMUSHORTN2(uint32_t Packed) : v(Packed) {}
XMUSHORTN2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
explicit XMUSHORTN2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
XMUSHORTN2(float _x, float _y);
explicit XMUSHORTN2(_In_reads_(2) const float *pArray);
XMUSHORTN2& operator= (const XMUSHORTN2& UShortN2) { x = UShortN2.x; y = UShortN2.y; return *this; }
XMUSHORTN2& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 2D Vector; 16 bit unsigned integer components
struct XMUSHORT2
{
union
{
struct
{
uint16_t x;
uint16_t y;
};
uint32_t v;
};
XMUSHORT2() {}
explicit XMUSHORT2(uint32_t Packed) : v(Packed) {}
XMUSHORT2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
explicit XMUSHORT2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
XMUSHORT2(float _x, float _y);
explicit XMUSHORT2(_In_reads_(2) const float *pArray);
XMUSHORT2& operator= (const XMUSHORT2& UShort2) { x = UShort2.x; y = UShort2.y; return *this; }
XMUSHORT2& operator= (uint32_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 2D Vector; 8 bit signed normalized integer components
struct XMBYTEN2
{
union
{
struct
{
int8_t x;
int8_t y;
};
uint16_t v;
};
XMBYTEN2() {}
explicit XMBYTEN2(uint16_t Packed) : v(Packed) {}
XMBYTEN2(int8_t _x, int8_t _y) : x(_x), y(_y) {}
explicit XMBYTEN2(_In_reads_(2) const int8_t *pArray) : x(pArray[0]), y(pArray[1]) {}
XMBYTEN2(float _x, float _y);
explicit XMBYTEN2(_In_reads_(2) const float *pArray);
XMBYTEN2& operator= (const XMBYTEN2& ByteN2) { x = ByteN2.x; y = ByteN2.y; return *this; }
XMBYTEN2& operator= (uint16_t Packed) { v = Packed; return *this; }
};
// 2D Vector; 8 bit signed integer components
struct XMBYTE2
{
union
{
struct
{
int8_t x;
int8_t y;
};
uint16_t v;
};
XMBYTE2() {}
explicit XMBYTE2(uint16_t Packed) : v(Packed) {}
XMBYTE2(int8_t _x, int8_t _y) : x(_x), y(_y) {}
explicit XMBYTE2(_In_reads_(2) const int8_t *pArray) : x(pArray[0]), y(pArray[1]) {}
XMBYTE2(float _x, float _y);
explicit XMBYTE2(_In_reads_(2) const float *pArray);
XMBYTE2& operator= (const XMBYTE2& Byte2) { x = Byte2.x; y = Byte2.y; return *this; }
XMBYTE2& operator= (uint16_t Packed) { v = Packed; return *this; }
};
// 2D Vector; 8 bit unsigned normalized integer components
struct XMUBYTEN2
{
union
{
struct
{
uint8_t x;
uint8_t y;
};
uint16_t v;
};
XMUBYTEN2() {}
explicit XMUBYTEN2(uint16_t Packed) : v(Packed) {}
XMUBYTEN2(uint8_t _x, uint8_t _y) : x(_x), y(_y) {}
explicit XMUBYTEN2(_In_reads_(2) const uint8_t *pArray) : x(pArray[0]), y(pArray[1]) {}
XMUBYTEN2(float _x, float _y);
explicit XMUBYTEN2(_In_reads_(2) const float *pArray);
XMUBYTEN2& operator= (const XMUBYTEN2& UByteN2) { x = UByteN2.x; y = UByteN2.y; return *this; }
XMUBYTEN2& operator= (uint16_t Packed) { v = Packed; return *this; }
};
// 2D Vector; 8 bit unsigned integer components
struct XMUBYTE2
{
union
{
struct
{
uint8_t x;
uint8_t y;
};
uint16_t v;
};
XMUBYTE2() {}
explicit XMUBYTE2(uint16_t Packed) : v(Packed) {}
XMUBYTE2(uint8_t _x, uint8_t _y) : x(_x), y(_y) {}
explicit XMUBYTE2(_In_reads_(2) const uint8_t *pArray) : x(pArray[0]), y(pArray[1]) {}
XMUBYTE2(float _x, float _y);
explicit XMUBYTE2(_In_reads_(2) const float *pArray);
XMUBYTE2& operator= (const XMUBYTE2& UByte2) { x = UByte2.x; y = UByte2.y; return *this; }
XMUBYTE2& operator= (uint16_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 3D vector: 5/6/5 unsigned integer components
struct XMU565
{
union
{
struct
{
uint16_t x : 5; // 0 to 31
uint16_t y : 6; // 0 to 63
uint16_t z : 5; // 0 to 31
};
uint16_t v;
};
XMU565() {}
explicit XMU565(uint16_t Packed) : v(Packed) {}
XMU565(uint8_t _x, uint8_t _y, uint8_t _z) : x(_x), y(_y), z(_z) {}
explicit XMU565(_In_reads_(3) const int8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]) {}
XMU565(float _x, float _y, float _z);
explicit XMU565(_In_reads_(3) const float *pArray);
operator uint16_t () const { return v; }
XMU565& operator= (const XMU565& U565) { v = U565.v; return *this; }
XMU565& operator= (uint16_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 3D vector: 11/11/10 floating-point components
// The 3D vector is packed into 32 bits as follows: a 5-bit biased exponent
// and 6-bit mantissa for x component, a 5-bit biased exponent and
// 6-bit mantissa for y component, a 5-bit biased exponent and a 5-bit
// mantissa for z. The z component is stored in the most significant bits
// and the x component in the least significant bits. No sign bits so
// all partial-precision numbers are positive.
// (Z10Y11X11): [32] ZZZZZzzz zzzYYYYY yyyyyyXX XXXxxxxx [0]
struct XMFLOAT3PK
{
union
{
struct
{
uint32_t xm : 6; // x-mantissa
uint32_t xe : 5; // x-exponent
uint32_t ym : 6; // y-mantissa
uint32_t ye : 5; // y-exponent
uint32_t zm : 5; // z-mantissa
uint32_t ze : 5; // z-exponent
};
uint32_t v;
};
XMFLOAT3PK() {}
explicit XMFLOAT3PK(uint32_t Packed) : v(Packed) {}
XMFLOAT3PK(float _x, float _y, float _z);
explicit XMFLOAT3PK(_In_reads_(3) const float *pArray);
operator uint32_t () const { return v; }
XMFLOAT3PK& operator= (const XMFLOAT3PK& float3pk) { v = float3pk.v; return *this; }
XMFLOAT3PK& operator= (uint32_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 3D vector: 9/9/9 floating-point components with shared 5-bit exponent
// The 3D vector is packed into 32 bits as follows: a 5-bit biased exponent
// with 9-bit mantissa for the x, y, and z component. The shared exponent
// is stored in the most significant bits and the x component mantissa is in
// the least significant bits. No sign bits so all partial-precision numbers
// are positive.
// (E5Z9Y9X9): [32] EEEEEzzz zzzzzzyy yyyyyyyx xxxxxxxx [0]
struct XMFLOAT3SE
{
union
{
struct
{
uint32_t xm : 9; // x-mantissa
uint32_t ym : 9; // y-mantissa
uint32_t zm : 9; // z-mantissa
uint32_t e : 5; // shared exponent
};
uint32_t v;
};
XMFLOAT3SE() {}
explicit XMFLOAT3SE(uint32_t Packed) : v(Packed) {}
XMFLOAT3SE(float _x, float _y, float _z);
explicit XMFLOAT3SE(_In_reads_(3) const float *pArray);
operator uint32_t () const { return v; }
XMFLOAT3SE& operator= (const XMFLOAT3SE& float3se) { v = float3se.v; return *this; }
XMFLOAT3SE& operator= (uint32_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 4D Vector; 16 bit floating point components
struct XMHALF4
{
union
{
struct
{
HALF x;
HALF y;
HALF z;
HALF w;
};
uint64_t v;
};
XMHALF4() {}
explicit XMHALF4(uint64_t Packed) : v(Packed) {}
XMHALF4(HALF _x, HALF _y, HALF _z, HALF _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMHALF4(_In_reads_(4) const HALF *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMHALF4(float _x, float _y, float _z, float _w);
explicit XMHALF4(_In_reads_(4) const float *pArray);
XMHALF4& operator= (const XMHALF4& Half4) { x = Half4.x; y = Half4.y; z = Half4.z; w = Half4.w; return *this; }
XMHALF4& operator= (uint64_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 4D Vector; 16 bit signed normalized integer components
struct XMSHORTN4
{
union
{
struct
{
int16_t x;
int16_t y;
int16_t z;
int16_t w;
};
uint64_t v;
};
XMSHORTN4() {}
explicit XMSHORTN4(uint64_t Packed) : v(Packed) {}
XMSHORTN4(int16_t _x, int16_t _y, int16_t _z, int16_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMSHORTN4(_In_reads_(4) const int16_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMSHORTN4(float _x, float _y, float _z, float _w);
explicit XMSHORTN4(_In_reads_(4) const float *pArray);
XMSHORTN4& operator= (const XMSHORTN4& ShortN4) { x = ShortN4.x; y = ShortN4.y; z = ShortN4.z; w = ShortN4.w; return *this; }
XMSHORTN4& operator= (uint64_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 16 bit signed integer components
struct XMSHORT4
{
union
{
struct
{
int16_t x;
int16_t y;
int16_t z;
int16_t w;
};
uint64_t v;
};
XMSHORT4() {}
explicit XMSHORT4(uint64_t Packed) : v(Packed) {}
XMSHORT4(int16_t _x, int16_t _y, int16_t _z, int16_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMSHORT4(_In_reads_(4) const int16_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMSHORT4(float _x, float _y, float _z, float _w);
explicit XMSHORT4(_In_reads_(4) const float *pArray);
XMSHORT4& operator= (const XMSHORT4& Short4) { x = Short4.x; y = Short4.y; z = Short4.z; w = Short4.w; return *this; }
XMSHORT4& operator= (uint64_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 16 bit unsigned normalized integer components
struct XMUSHORTN4
{
union
{
struct
{
uint16_t x;
uint16_t y;
uint16_t z;
uint16_t w;
};
uint64_t v;
};
XMUSHORTN4() {}
explicit XMUSHORTN4(uint64_t Packed) : v(Packed) {}
XMUSHORTN4(uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMUSHORTN4(_In_reads_(4) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMUSHORTN4(float _x, float _y, float _z, float _w);
explicit XMUSHORTN4(_In_reads_(4) const float *pArray);
XMUSHORTN4& operator= (const XMUSHORTN4& UShortN4) { x = UShortN4.x; y = UShortN4.y; z = UShortN4.z; w = UShortN4.w; return *this; }
XMUSHORTN4& operator= (uint64_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 16 bit unsigned integer components
struct XMUSHORT4
{
union
{
struct
{
uint16_t x;
uint16_t y;
uint16_t z;
uint16_t w;
};
uint64_t v;
};
XMUSHORT4() {}
explicit XMUSHORT4(uint64_t Packed) : v(Packed) {}
XMUSHORT4(uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMUSHORT4(_In_reads_(4) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMUSHORT4(float _x, float _y, float _z, float _w);
explicit XMUSHORT4(_In_reads_(4) const float *pArray);
XMUSHORT4& operator= (const XMUSHORT4& UShort4) { x = UShort4.x; y = UShort4.y; z = UShort4.z; w = UShort4.w; return *this; }
XMUSHORT4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer
// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned,
// normalized integer for the w component and 10 bit signed, normalized
// integers for the z, y, and x components. The w component is stored in the
// most significant bits and the x component in the least significant bits
// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0]
struct XMXDECN4
{
union
{
struct
{
int32_t x : 10; // -511/511 to 511/511
int32_t y : 10; // -511/511 to 511/511
int32_t z : 10; // -511/511 to 511/511
uint32_t w : 2; // 0/3 to 3/3
};
uint32_t v;
};
XMXDECN4() {}
explicit XMXDECN4(uint32_t Packed) : v(Packed) {}
XMXDECN4(float _x, float _y, float _z, float _w);
explicit XMXDECN4(_In_reads_(4) const float *pArray);
operator uint32_t () const { return v; }
XMXDECN4& operator= (const XMXDECN4& XDecN4) { v = XDecN4.v; return *this; }
XMXDECN4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer
// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned
// integer for the w component and 10 bit signed integers for the
// z, y, and x components. The w component is stored in the
// most significant bits and the x component in the least significant bits
// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0]
struct XMXDEC4
{
union
{
struct
{
int32_t x : 10; // -511 to 511
int32_t y : 10; // -511 to 511
int32_t z : 10; // -511 to 511
uint32_t w : 2; // 0 to 3
};
uint32_t v;
};
XMXDEC4() {}
explicit XMXDEC4(uint32_t Packed) : v(Packed) {}
XMXDEC4(float _x, float _y, float _z, float _w);
explicit XMXDEC4(_In_reads_(4) const float *pArray);
operator uint32_t () const { return v; }
XMXDEC4& operator= (const XMXDEC4& XDec4) { v = XDec4.v; return *this; }
XMXDEC4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer
// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit signed,
// normalized integer for the w component and 10 bit signed, normalized
// integers for the z, y, and x components. The w component is stored in the
// most significant bits and the x component in the least significant bits
// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0]
struct XMDECN4
{
union
{
struct
{
int32_t x : 10; // -511/511 to 511/511
int32_t y : 10; // -511/511 to 511/511
int32_t z : 10; // -511/511 to 511/511
int32_t w : 2; // -1/1 to 1/1
};
uint32_t v;
};
XMDECN4() {}
explicit XMDECN4(uint32_t Packed) : v(Packed) {}
XMDECN4(float _x, float _y, float _z, float _w);
explicit XMDECN4(_In_reads_(4) const float *pArray);
operator uint32_t () const { return v; }
XMDECN4& operator= (const XMDECN4& DecN4) { v = DecN4.v; return *this; }
XMDECN4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer
// The 4D Vector is packed into 32 bits as follows: a 2 bit signed,
// integer for the w component and 10 bit signed integers for the
// z, y, and x components. The w component is stored in the
// most significant bits and the x component in the least significant bits
// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0]
struct XMDEC4
{
union
{
struct
{
int32_t x : 10; // -511 to 511
int32_t y : 10; // -511 to 511
int32_t z : 10; // -511 to 511
int32_t w : 2; // -1 to 1
};
uint32_t v;
};
XMDEC4() {}
explicit XMDEC4(uint32_t Packed) : v(Packed) {}
XMDEC4(float _x, float _y, float _z, float _w);
explicit XMDEC4(_In_reads_(4) const float *pArray);
operator uint32_t () const { return v; }
XMDEC4& operator= (const XMDEC4& Dec4) { v = Dec4.v; return *this; }
XMDEC4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer
// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned,
// normalized integer for the w component and 10 bit unsigned, normalized
// integers for the z, y, and x components. The w component is stored in the
// most significant bits and the x component in the least significant bits
// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0]
struct XMUDECN4
{
union
{
struct
{
uint32_t x : 10; // 0/1023 to 1023/1023
uint32_t y : 10; // 0/1023 to 1023/1023
uint32_t z : 10; // 0/1023 to 1023/1023
uint32_t w : 2; // 0/3 to 3/3
};
uint32_t v;
};
XMUDECN4() {}
explicit XMUDECN4(uint32_t Packed) : v(Packed) {}
XMUDECN4(float _x, float _y, float _z, float _w);
explicit XMUDECN4(_In_reads_(4) const float *pArray);
operator uint32_t () const { return v; }
XMUDECN4& operator= (const XMUDECN4& UDecN4) { v = UDecN4.v; return *this; }
XMUDECN4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer
// The 4D Vector is packed into 32 bits as follows: a 2 bit unsigned,
// integer for the w component and 10 bit unsigned integers
// for the z, y, and x components. The w component is stored in the
// most significant bits and the x component in the least significant bits
// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0]
struct XMUDEC4
{
union
{
struct
{
uint32_t x : 10; // 0 to 1023
uint32_t y : 10; // 0 to 1023
uint32_t z : 10; // 0 to 1023
uint32_t w : 2; // 0 to 3
};
uint32_t v;
};
XMUDEC4() {}
explicit XMUDEC4(uint32_t Packed) : v(Packed) {}
XMUDEC4(float _x, float _y, float _z, float _w);
explicit XMUDEC4(_In_reads_(4) const float *pArray);
operator uint32_t () const { return v; }
XMUDEC4& operator= (const XMUDEC4& UDec4) { v = UDec4.v; return *this; }
XMUDEC4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 4D Vector; 8 bit signed normalized integer components
struct XMBYTEN4
{
union
{
struct
{
int8_t x;
int8_t y;
int8_t z;
int8_t w;
};
uint32_t v;
};
XMBYTEN4() {}
XMBYTEN4(int8_t _x, int8_t _y, int8_t _z, int8_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMBYTEN4(uint32_t Packed) : v(Packed) {}
explicit XMBYTEN4(_In_reads_(4) const int8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMBYTEN4(float _x, float _y, float _z, float _w);
explicit XMBYTEN4(_In_reads_(4) const float *pArray);
XMBYTEN4& operator= (const XMBYTEN4& ByteN4) { x = ByteN4.x; y = ByteN4.y; z = ByteN4.z; w = ByteN4.w; return *this; }
XMBYTEN4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 8 bit signed integer components
struct XMBYTE4
{
union
{
struct
{
int8_t x;
int8_t y;
int8_t z;
int8_t w;
};
uint32_t v;
};
XMBYTE4() {}
XMBYTE4(int8_t _x, int8_t _y, int8_t _z, int8_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMBYTE4(uint32_t Packed) : v(Packed) {}
explicit XMBYTE4(_In_reads_(4) const int8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMBYTE4(float _x, float _y, float _z, float _w);
explicit XMBYTE4(_In_reads_(4) const float *pArray);
XMBYTE4& operator= (const XMBYTE4& Byte4) { x = Byte4.x; y = Byte4.y; z = Byte4.z; w = Byte4.w; return *this; }
XMBYTE4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 8 bit unsigned normalized integer components
struct XMUBYTEN4
{
union
{
struct
{
uint8_t x;
uint8_t y;
uint8_t z;
uint8_t w;
};
uint32_t v;
};
XMUBYTEN4() {}
XMUBYTEN4(uint8_t _x, uint8_t _y, uint8_t _z, uint8_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMUBYTEN4(uint32_t Packed) : v(Packed) {}
explicit XMUBYTEN4(_In_reads_(4) const uint8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMUBYTEN4(float _x, float _y, float _z, float _w);
explicit XMUBYTEN4(_In_reads_(4) const float *pArray);
XMUBYTEN4& operator= (const XMUBYTEN4& UByteN4) { x = UByteN4.x; y = UByteN4.y; z = UByteN4.z; w = UByteN4.w; return *this; }
XMUBYTEN4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
// 4D Vector; 8 bit unsigned integer components
struct XMUBYTE4
{
union
{
struct
{
uint8_t x;
uint8_t y;
uint8_t z;
uint8_t w;
};
uint32_t v;
};
XMUBYTE4() {}
XMUBYTE4(uint8_t _x, uint8_t _y, uint8_t _z, uint8_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMUBYTE4(uint32_t Packed) : v(Packed) {}
explicit XMUBYTE4(_In_reads_(4) const uint8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMUBYTE4(float _x, float _y, float _z, float _w);
explicit XMUBYTE4(_In_reads_(4) const float *pArray);
XMUBYTE4& operator= (const XMUBYTE4& UByte4) { x = UByte4.x; y = UByte4.y; z = UByte4.z; w = UByte4.w; return *this; }
XMUBYTE4& operator= (uint32_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 4D vector; 4 bit unsigned integer components
struct XMUNIBBLE4
{
union
{
struct
{
uint16_t x : 4; // 0 to 15
uint16_t y : 4; // 0 to 15
uint16_t z : 4; // 0 to 15
uint16_t w : 4; // 0 to 15
};
uint16_t v;
};
XMUNIBBLE4() {}
explicit XMUNIBBLE4(uint16_t Packed) : v(Packed) {}
XMUNIBBLE4(int8_t _x, int8_t _y, int8_t _z, int8_t _w) : x(_x), y(_y), z(_z), w(_w) {}
explicit XMUNIBBLE4(_In_reads_(4) const int8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
XMUNIBBLE4(float _x, float _y, float _z, float _w);
explicit XMUNIBBLE4(_In_reads_(4) const float *pArray);
operator uint16_t () const { return v; }
XMUNIBBLE4& operator= (const XMUNIBBLE4& UNibble4) { v = UNibble4.v; return *this; }
XMUNIBBLE4& operator= (uint16_t Packed) { v = Packed; return *this; }
};
//------------------------------------------------------------------------------
// 4D vector: 5/5/5/1 unsigned integer components
struct XMU555
{
union
{
struct
{
uint16_t x : 5; // 0 to 31
uint16_t y : 5; // 0 to 31
uint16_t z : 5; // 0 to 31
uint16_t w : 1; // 0 or 1
};
uint16_t v;
};
XMU555() {}
explicit XMU555(uint16_t Packed) : v(Packed) {}
XMU555(int8_t _x, int8_t _y, int8_t _z, bool _w) : x(_x), y(_y), z(_z), w(_w ? 0x1 : 0) {}
XMU555(_In_reads_(3) const int8_t *pArray, _In_ bool _w) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(_w ? 0x1 : 0) {}
XMU555(float _x, float _y, float _z, bool _w);
XMU555(_In_reads_(3) const float *pArray, _In_ bool _w);
operator uint16_t () const { return v; }
XMU555& operator= (const XMU555& U555) { v = U555.v; return *this; }
XMU555& operator= (uint16_t Packed) { v = Packed; return *this; }
};
#pragma warning(pop)
#ifdef _XM_BIGENDIAN_
#pragma bitfield_order(pop)
#endif
/****************************************************************************
*
* Data conversion operations
*
****************************************************************************/
float XMConvertHalfToFloat(HALF Value);
float* XMConvertHalfToFloatStream(_Out_writes_bytes_(sizeof(float)+OutputStride*(HalfCount-1)) float* pOutputStream,
_In_ size_t OutputStride,
_In_reads_bytes_(sizeof(HALF)+InputStride*(HalfCount-1)) const HALF* pInputStream,
_In_ size_t InputStride, _In_ size_t HalfCount);
HALF XMConvertFloatToHalf(float Value);
HALF* XMConvertFloatToHalfStream(_Out_writes_bytes_(sizeof(HALF)+OutputStride*(FloatCount-1)) HALF* pOutputStream,
_In_ size_t OutputStride,
_In_reads_bytes_(sizeof(float)+InputStride*(FloatCount-1)) const float* pInputStream,
_In_ size_t InputStride, _In_ size_t FloatCount);
/****************************************************************************
*
* Load operations
*
****************************************************************************/
XMVECTOR XMLoadColor(_In_ const XMCOLOR* pSource);
XMVECTOR XMLoadHalf2(_In_ const XMHALF2* pSource);
XMVECTOR XMLoadShortN2(_In_ const XMSHORTN2* pSource);
XMVECTOR XMLoadShort2(_In_ const XMSHORT2* pSource);
XMVECTOR XMLoadUShortN2(_In_ const XMUSHORTN2* pSource);
XMVECTOR XMLoadUShort2(_In_ const XMUSHORT2* pSource);
XMVECTOR XMLoadByteN2(_In_ const XMBYTEN2* pSource);
XMVECTOR XMLoadByte2(_In_ const XMBYTE2* pSource);
XMVECTOR XMLoadUByteN2(_In_ const XMUBYTEN2* pSource);
XMVECTOR XMLoadUByte2(_In_ const XMUBYTE2* pSource);
XMVECTOR XMLoadU565(_In_ const XMU565* pSource);
XMVECTOR XMLoadFloat3PK(_In_ const XMFLOAT3PK* pSource);
XMVECTOR XMLoadFloat3SE(_In_ const XMFLOAT3SE* pSource);
XMVECTOR XMLoadHalf4(_In_ const XMHALF4* pSource);
XMVECTOR XMLoadShortN4(_In_ const XMSHORTN4* pSource);
XMVECTOR XMLoadShort4(_In_ const XMSHORT4* pSource);
XMVECTOR XMLoadUShortN4(_In_ const XMUSHORTN4* pSource);
XMVECTOR XMLoadUShort4(_In_ const XMUSHORT4* pSource);
XMVECTOR XMLoadXDecN4(_In_ const XMXDECN4* pSource);
XMVECTOR XMLoadXDec4(_In_ const XMXDEC4* pSource);
XMVECTOR XMLoadDecN4(_In_ const XMDECN4* pSource);
XMVECTOR XMLoadDec4(_In_ const XMDEC4* pSource);
XMVECTOR XMLoadUDecN4(_In_ const XMUDECN4* pSource);
XMVECTOR XMLoadUDec4(_In_ const XMUDEC4* pSource);
XMVECTOR XMLoadByteN4(_In_ const XMBYTEN4* pSource);
XMVECTOR XMLoadByte4(_In_ const XMBYTE4* pSource);
XMVECTOR XMLoadUByteN4(_In_ const XMUBYTEN4* pSource);
XMVECTOR XMLoadUByte4(_In_ const XMUBYTE4* pSource);
XMVECTOR XMLoadUNibble4(_In_ const XMUNIBBLE4* pSource);
XMVECTOR XMLoadU555(_In_ const XMU555* pSource);
/****************************************************************************
*
* Store operations
*
****************************************************************************/
void XMStoreColor(_Out_ XMCOLOR* pDestination, _In_ FXMVECTOR V);
void XMStoreHalf2(_Out_ XMHALF2* pDestination, _In_ FXMVECTOR V);
void XMStoreShortN2(_Out_ XMSHORTN2* pDestination, _In_ FXMVECTOR V);
void XMStoreShort2(_Out_ XMSHORT2* pDestination, _In_ FXMVECTOR V);
void XMStoreUShortN2(_Out_ XMUSHORTN2* pDestination, _In_ FXMVECTOR V);
void XMStoreUShort2(_Out_ XMUSHORT2* pDestination, _In_ FXMVECTOR V);
void XMStoreByteN2(_Out_ XMBYTEN2* pDestination, _In_ FXMVECTOR V);
void XMStoreByte2(_Out_ XMBYTE2* pDestination, _In_ FXMVECTOR V);
void XMStoreUByteN2(_Out_ XMUBYTEN2* pDestination, _In_ FXMVECTOR V);
void XMStoreUByte2(_Out_ XMUBYTE2* pDestination, _In_ FXMVECTOR V);
void XMStoreU565(_Out_ XMU565* pDestination, _In_ FXMVECTOR V);
void XMStoreFloat3PK(_Out_ XMFLOAT3PK* pDestination, _In_ FXMVECTOR V);
void XMStoreFloat3SE(_Out_ XMFLOAT3SE* pDestination, _In_ FXMVECTOR V);
void XMStoreHalf4(_Out_ XMHALF4* pDestination, _In_ FXMVECTOR V);
void XMStoreShortN4(_Out_ XMSHORTN4* pDestination, _In_ FXMVECTOR V);
void XMStoreShort4(_Out_ XMSHORT4* pDestination, _In_ FXMVECTOR V);
void XMStoreUShortN4(_Out_ XMUSHORTN4* pDestination, _In_ FXMVECTOR V);
void XMStoreUShort4(_Out_ XMUSHORT4* pDestination, _In_ FXMVECTOR V);
void XMStoreXDecN4(_Out_ XMXDECN4* pDestination, _In_ FXMVECTOR V);
void XMStoreXDec4(_Out_ XMXDEC4* pDestination, _In_ FXMVECTOR V);
void XMStoreDecN4(_Out_ XMDECN4* pDestination, _In_ FXMVECTOR V);
void XMStoreDec4(_Out_ XMDEC4* pDestination, _In_ FXMVECTOR V);
void XMStoreUDecN4(_Out_ XMUDECN4* pDestination, _In_ FXMVECTOR V);
void XMStoreUDec4(_Out_ XMUDEC4* pDestination, _In_ FXMVECTOR V);
void XMStoreByteN4(_Out_ XMBYTEN4* pDestination, _In_ FXMVECTOR V);
void XMStoreByte4(_Out_ XMBYTE4* pDestination, _In_ FXMVECTOR V);
void XMStoreUByteN4(_Out_ XMUBYTEN4* pDestination, _In_ FXMVECTOR V);
void XMStoreUByte4(_Out_ XMUBYTE4* pDestination, _In_ FXMVECTOR V);
void XMStoreUNibble4(_Out_ XMUNIBBLE4* pDestination, _In_ FXMVECTOR V);
void XMStoreU555(_Out_ XMU555* pDestination, _In_ FXMVECTOR V);
/****************************************************************************
*
* Implementation
*
****************************************************************************/
#pragma warning(push)
#pragma warning(disable:4068 4214 4204 4365 4616 6001)
#pragma prefast(push)
#pragma prefast(disable : 25000, "FXMVECTOR is 16 bytes")
#include "DirectXPackedVector.inl"
#pragma prefast(pop)
#pragma warning(pop)
}; // namespace PackedVector
}; // namespace DirectX
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+419
View File
@@ -0,0 +1,419 @@
#include "stdafx.h"
#include <stdlib.h>
#include "EdgeZLib.h"
#include "edge/zlib/edgezlib_ppu.h"
static CellSpurs* s_pSpurs = NULL;
//Set this to 5 if you want deflate/inflate to run in parallel on 5 SPUs.
const uint32_t kNumDeflateTasks = 1;
const uint32_t kMaxNumDeflateQueueEntries = 64;
static CellSpursEventFlag s_eventFlagDeflate; //Cannot be on stack
static CellSpursTaskset s_taskSetDeflate; //Cannot be on stack
static EdgeZlibDeflateQHandle s_deflateQueue;
static void* s_pDeflateQueueBuffer = NULL;
static void* s_pDeflateTaskContext[kNumDeflateTasks];
static uint32_t s_numElementsToCompress; //Cannot be on stack
const uint32_t kNumInflateTasks = 1;
const uint32_t kMaxNumInflateQueueEntries = 64;
static CellSpursEventFlag s_eventFlagInflate; //Cannot be on stack
static CellSpursTaskset s_taskSetInflate; //Cannot be on stack
static EdgeZlibInflateQHandle s_inflateQueue;
static void* s_pInflateQueueBuffer = NULL;
static void* s_pInflateTaskContext[kNumInflateTasks];
static uint32_t s_numElementsToDecompress; //Cannot be on stack
static CRITICAL_SECTION s_critSect;
static const bool sc_verbose = false;
#define printf_verbose(...) { if(sc_verbose){ printf(__VA_ARGS__);} }
void EdgeZLib::Init(CellSpurs* pSpurs)
{
s_pSpurs = pSpurs;
InitializeCriticalSection(&s_critSect);
//////////////////////////////////////////////////////////////////////////
//
// Initialize Deflate Queue.
// This will hold the queue of work that the Deflate Task(s) on SPU will
// pull work from.
//
//////////////////////////////////////////////////////////////////////////
{
// register taskSet
CellSpursTasksetAttribute taskSetAttribute;
uint8_t prios[8] = {15, 15, 15, 15, 15, 15, 0, 0};
int ret = cellSpursTasksetAttributeInitialize( &taskSetAttribute, 0, prios, 8 );
PS3_ASSERT_CELL_ERROR(ret);
ret = cellSpursTasksetAttributeSetName(&taskSetAttribute, "edgeZlibDeflateTaskSet");
PS3_ASSERT_CELL_ERROR(ret);
ret = cellSpursCreateTasksetWithAttribute( pSpurs, &s_taskSetDeflate, &taskSetAttribute );
PS3_ASSERT_CELL_ERROR(ret);
ret = cellSpursEventFlagInitializeIWL( pSpurs,
&s_eventFlagDeflate,
CELL_SPURS_EVENT_FLAG_CLEAR_AUTO,
CELL_SPURS_EVENT_FLAG_SPU2PPU );
PS3_ASSERT_CELL_ERROR(ret);
ret = cellSpursEventFlagAttachLv2EventQueue( &s_eventFlagDeflate );
PS3_ASSERT_CELL_ERROR(ret);
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Event flag created\n" );
#endif
uint32_t deflateQueueBuffSize = edgeZlibGetDeflateQueueSize( kMaxNumDeflateQueueEntries );
s_pDeflateQueueBuffer = memalign( EDGE_ZLIB_DEFLATE_QUEUE_ALIGN, deflateQueueBuffSize );
s_deflateQueue = edgeZlibCreateDeflateQueue(
s_pSpurs,
kMaxNumDeflateQueueEntries,
s_pDeflateQueueBuffer,
deflateQueueBuffSize );
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Deflate Queue created\n" );
#endif
//////////////////////////////////////////////////////////////////////////
//
// Build Deflate Tasks.
// We want the compression to be able to run in parallel on multiple
// SPUs so we create as many tasks as SPUs that we want it to run
// on (kNumDeflateTasks).
//
//////////////////////////////////////////////////////////////////////////
s_pDeflateTaskContext[kNumDeflateTasks];
for( uint32_t taskNum = 0 ; taskNum < kNumDeflateTasks ; taskNum++ )
{
uint32_t contextSaveSize = edgeZlibGetDeflateTaskContextSaveSize();
s_pDeflateTaskContext[taskNum] = memalign( CELL_SPURS_TASK_CONTEXT_ALIGN, contextSaveSize );
edgeZlibCreateDeflateTask( &s_taskSetDeflate, s_pDeflateTaskContext[taskNum], s_deflateQueue );
}
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: %d Deflate Task(s) started\n", kNumDeflateTasks );
#endif
}
{
//////////////////////////////////////////////////////////////////////////
//
// Initialize taskset and event flag
//
//////////////////////////////////////////////////////////////////////////
// register taskSet
CellSpursTasksetAttribute taskSetAttribute;
uint8_t prios[8] = {15, 15, 15, 15, 15, 15, 0, 0};
int ret = cellSpursTasksetAttributeInitialize( &taskSetAttribute, 0, prios, 8 );
PS3_ASSERT_CELL_ERROR(ret);
ret = cellSpursTasksetAttributeSetName(&taskSetAttribute, "edgeZlibInflateTaskSet");
PS3_ASSERT_CELL_ERROR(ret);
ret = cellSpursCreateTasksetWithAttribute( s_pSpurs, &s_taskSetInflate, &taskSetAttribute );
PS3_ASSERT_CELL_ERROR(ret);
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Inflate Taskset created\n" );
#endif
ret = cellSpursEventFlagInitializeIWL( s_pSpurs,
&s_eventFlagInflate,
CELL_SPURS_EVENT_FLAG_CLEAR_AUTO,
CELL_SPURS_EVENT_FLAG_SPU2PPU );
PS3_ASSERT_CELL_ERROR(ret);
ret = cellSpursEventFlagAttachLv2EventQueue( &s_eventFlagInflate );
PS3_ASSERT_CELL_ERROR(ret);
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Event flag created\n" );
#endif
//////////////////////////////////////////////////////////////////////////
//
// Initialize Inflate Queue.
// This will hold the queue of work that the Inflate Task(s) on SPU will
// pull work from.
//
//////////////////////////////////////////////////////////////////////////
uint32_t inflateQueueBuffSize = edgeZlibGetInflateQueueSize( kMaxNumInflateQueueEntries );
s_pInflateQueueBuffer = memalign( EDGE_ZLIB_INFLATE_QUEUE_ALIGN, inflateQueueBuffSize );
s_inflateQueue = edgeZlibCreateInflateQueue(
s_pSpurs,
kMaxNumInflateQueueEntries,
s_pInflateQueueBuffer,
inflateQueueBuffSize );
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Inflate Queue created\n" );
#endif
//////////////////////////////////////////////////////////////////////////
//
// Build Inflate Tasks.
// We want the compression to be able to run in parallel on multiple
// SPUs so we create as many tasks as SPUs that we want it to run
// on (kNumInflateTasks).
//
//////////////////////////////////////////////////////////////////////////
for( uint32_t taskNum = 0 ; taskNum < kNumInflateTasks ; taskNum++ )
{
uint32_t contextSaveSize = edgeZlibGetInflateTaskContextSaveSize();
s_pInflateTaskContext[taskNum] = memalign( CELL_SPURS_TASK_CONTEXT_ALIGN, contextSaveSize );
edgeZlibCreateInflateTask( &s_taskSetInflate, s_pInflateTaskContext[taskNum], s_inflateQueue );
}
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: %d Inflate Task(s) started\n", kNumInflateTasks );
#endif
}
}
bool EdgeZLib::Compress(void* pDestination, uint32_t* pDestSize, const void* pSource, uint32_t SrcSize)
{
EnterCriticalSection(&s_critSect);
//////////////////////////////////////////////////////////////////////////
//
// Add one item to the Deflate Queue.
// The Deflate Task will wake up and process this work.
//
//////////////////////////////////////////////////////////////////////////
uint32_t* pDst = NULL;
bool findingSizeOnly = false;
if(pDestination == NULL && *pDestSize == 0)
{
pDst = (uint32_t*)malloc(SrcSize);
findingSizeOnly = true;
*pDestSize = SrcSize;
}
else
{
pDst = ((uint32_t*)pDestination);
}
pDst[0] = SrcSize; // 4 byte header added for source size
s_numElementsToCompress = 1; //Must be set correctly before any elements are added
uint16_t eventFlagBits = 1;
uint32_t compressionLevel = 9;
static uint32_t s_compressedSize; //Cannot be on stack
// create one task queue entry (max 64K deflate per entry)
edgeZlibAddDeflateQueueElement( s_deflateQueue,
pSource, SrcSize,
&pDst[1], *pDestSize,
&s_compressedSize,
&s_numElementsToCompress, //This will be decremented by 1 when this element is compressed
&s_eventFlagDeflate, //When s_numElementsToCompress decrements to zero, this event will be triggered
eventFlagBits,
compressionLevel,
kEdgeZlibDeflateTask_DeflateStoreCompressed
);
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Deflate element(s) added to queue\n" );
printf_verbose( "PPU: Wait for event flag acknowledgment\n" );
#endif
//////////////////////////////////////////////////////////////////////////
//
// Wait for the event flag to be acknowledged in order to tell us the
// work is done.
//
//////////////////////////////////////////////////////////////////////////
int ret = cellSpursEventFlagWait( &s_eventFlagDeflate, &eventFlagBits, CELL_SPURS_EVENT_FLAG_AND );
PS3_ASSERT_CELL_ERROR(ret );
assert( s_numElementsToCompress == 0 ); //Should have reached zero by now
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Edge Zlib event acknowledged\n" );
#endif
// ensure Deflate task told us it stored the compressed data
assert( (s_compressedSize & kEdgeZlibDeflateTask_HowStoredMask) == kEdgeZlibDeflateTask_CompressedWasStored );
// remove bit from s_compressedSize
s_compressedSize &= ~kEdgeZlibDeflateTask_HowStoredMask;
//////////////////////////////////////////////////////////////////////////
//
// Print stats
//
//////////////////////////////////////////////////////////////////////////
#ifndef _CONTENT_PACKAGE
printf_verbose( "\n uncompSiz compSiz compress%% numTasks\n" );
printf_verbose( "___________________________________________\n" );
#endif
float compressionPercent = (1.f - (float)s_compressedSize / (float)SrcSize) * 100.f;
#ifndef _CONTENT_PACKAGE
printf_verbose( " 0x%05x 0x%05x %8.2f%% %d\n\n",
(int)SrcSize, (int)s_compressedSize, compressionPercent, kNumDeflateTasks );
#endif
*pDestSize = s_compressedSize + 4; // 4 byte header for size
if(findingSizeOnly)
free(pDst);
LeaveCriticalSection(&s_critSect);
return true;
}
void EdgeZLib::Shutdown()
{
//////////////////////////////////////////////////////////////////////////
//
// Shutdown Deflate Queue, event flag and taskset.
//
//////////////////////////////////////////////////////////////////////////
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Shutdown Deflate Queue...\n" );
#endif
edgeZlibShutdownDeflateQueue( s_deflateQueue );
int ret = cellSpursEventFlagDetachLv2EventQueue( &s_eventFlagDeflate );
PS3_ASSERT_CELL_ERROR(ret);
// shutdown taskSet
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Wait for taskset shutdown...\n" );
#endif
ret = cellSpursShutdownTaskset( &s_taskSetDeflate );
PS3_ASSERT_CELL_ERROR(ret);
// wait for all tasks to finish
ret = cellSpursJoinTaskset( &s_taskSetDeflate );
PS3_ASSERT_CELL_ERROR(ret);
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Shutdown taskset completed.\n" );
#endif
// free alloc'd buffers
for( uint32_t taskNum = 0 ; taskNum < kNumDeflateTasks ; taskNum++ )
{
free( s_pDeflateTaskContext[taskNum] );
}
free( s_pDeflateQueueBuffer );
//////////////////////////////////////////////////////////////////////////
//
// Shutdown Inflate Queue, event flag and taskset.
//
//////////////////////////////////////////////////////////////////////////
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Shutdown Inflate Queue...\n" );
#endif
edgeZlibShutdownInflateQueue( s_inflateQueue );
ret = cellSpursEventFlagDetachLv2EventQueue( &s_eventFlagInflate );
PS3_ASSERT_CELL_ERROR(ret);
// shutdown taskSet
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Wait for taskset shutdown...\n" );
#endif
ret = cellSpursShutdownTaskset( &s_taskSetInflate );
PS3_ASSERT_CELL_ERROR(ret);
// wait for all tasks to finish
ret = cellSpursJoinTaskset( &s_taskSetInflate );
PS3_ASSERT_CELL_ERROR(ret);
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Shutdown taskset completed.\n" );
#endif
// free alloc'd buffers
for( uint32_t taskNum = 0 ; taskNum < kNumInflateTasks ; taskNum++ )
{
free( s_pInflateTaskContext[taskNum] );
}
free( s_pInflateQueueBuffer );
}
bool EdgeZLib::Decompress(void* pDestination, uint32_t* pDestSize, const void* pSource, uint32_t SrcSize)
{
#if 1
EnterCriticalSection(&s_critSect);
const uint32_t* pSrc = (uint32_t*)pSource;
uint32_t uncompressedSize = pSrc[0];
assert(uncompressedSize <= (*pDestSize));
//////////////////////////////////////////////////////////////////////////
//
// Add one item to the Inflate Queue.
// The Inflate Task will wake up and process this work.
//
//////////////////////////////////////////////////////////////////////////
s_numElementsToDecompress = 1; //Must be set correctly before any elements are added
uint16_t eventFlagBits = 1;
// create one task queue entry (max 64K inflate per entry)
edgeZlibAddInflateQueueElement( s_inflateQueue,
&pSrc[1], SrcSize,
pDestination, uncompressedSize,
&s_numElementsToDecompress, //This will be decremented by 1 when this element is compressed
&s_eventFlagInflate, //When s_numElementsToDecompress decrements to zero, this event will be triggered
eventFlagBits,
kEdgeZlibInflateTask_Inflate
);
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Inflate element(s) added to queue\n" );
printf_verbose( "PPU: Wait for event flag acknowledgment\n" );
#endif
//////////////////////////////////////////////////////////////////////////
//
// Wait for the event flag to be acknowledged in order to tell us the
// work is done.
//
//////////////////////////////////////////////////////////////////////////
int ret = cellSpursEventFlagWait( &s_eventFlagInflate, &eventFlagBits, CELL_SPURS_EVENT_FLAG_AND );
PS3_ASSERT_CELL_ERROR(ret);
assert( s_numElementsToDecompress == 0 ); //Should have reached zero by now
#ifndef _CONTENT_PACKAGE
printf_verbose( "PPU: Edge Zlib event acknowledged\n" );
#endif
*pDestSize = uncompressedSize;
LeaveCriticalSection(&s_critSect);
return true;
#endif // 0
}
+13
View File
@@ -0,0 +1,13 @@
#pragma once
#include <cell/spurs.h>
class EdgeZLib
{
static void InitDeflate();
static void InitInflate();
public:
static void Init(CellSpurs* pSpurs);
static void Shutdown();
static bool Compress(void* pDestination, uint32_t* pDestSize, const void* pSource, uint32_t SrcSize);
static bool Decompress(void* pDestination, uint32_t* pDestSize, const void* pSource, uint32_t SrcSize);
};
@@ -0,0 +1,169 @@
{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi31507\deflang1043\deflangfe1043\themelang1043\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f2\fbidi \fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}
{\f34\fbidi \froman\fcharset1\fprq2{\*\panose 02040503050406030204}Cambria Math;}{\flomajor\f31500\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbmajor\f31501\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhimajor\f31502\fbidi \froman\fcharset0\fprq2{\*\panose 02040503050406030204}Cambria;}
{\fbimajor\f31503\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\flominor\f31504\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbminor\f31505\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhiminor\f31506\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}
{\fbiminor\f31507\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f39\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\f40\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\f42\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\f43\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\f44\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f45\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\f46\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\f47\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f59\fbidi \fmodern\fcharset238\fprq1 Courier New CE;}{\f60\fbidi \fmodern\fcharset204\fprq1 Courier New Cyr;}
{\f62\fbidi \fmodern\fcharset161\fprq1 Courier New Greek;}{\f63\fbidi \fmodern\fcharset162\fprq1 Courier New Tur;}{\f64\fbidi \fmodern\fcharset177\fprq1 Courier New (Hebrew);}{\f65\fbidi \fmodern\fcharset178\fprq1 Courier New (Arabic);}
{\f66\fbidi \fmodern\fcharset186\fprq1 Courier New Baltic;}{\f67\fbidi \fmodern\fcharset163\fprq1 Courier New (Vietnamese);}{\flomajor\f31508\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}
{\flomajor\f31509\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\flomajor\f31511\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\flomajor\f31512\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}
{\flomajor\f31513\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\flomajor\f31514\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\flomajor\f31515\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}
{\flomajor\f31516\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fdbmajor\f31518\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\fdbmajor\f31519\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\fdbmajor\f31521\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fdbmajor\f31522\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\fdbmajor\f31523\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}
{\fdbmajor\f31524\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fdbmajor\f31525\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\fdbmajor\f31526\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}
{\fhimajor\f31528\fbidi \froman\fcharset238\fprq2 Cambria CE;}{\fhimajor\f31529\fbidi \froman\fcharset204\fprq2 Cambria Cyr;}{\fhimajor\f31531\fbidi \froman\fcharset161\fprq2 Cambria Greek;}{\fhimajor\f31532\fbidi \froman\fcharset162\fprq2 Cambria Tur;}
{\fhimajor\f31535\fbidi \froman\fcharset186\fprq2 Cambria Baltic;}{\fhimajor\f31536\fbidi \froman\fcharset163\fprq2 Cambria (Vietnamese);}{\fbimajor\f31538\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}
{\fbimajor\f31539\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fbimajor\f31541\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fbimajor\f31542\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}
{\fbimajor\f31543\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fbimajor\f31544\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fbimajor\f31545\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}
{\fbimajor\f31546\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\flominor\f31548\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\flominor\f31549\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\flominor\f31551\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\flominor\f31552\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\flominor\f31553\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}
{\flominor\f31554\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\flominor\f31555\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\flominor\f31556\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}
{\fdbminor\f31558\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\fdbminor\f31559\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fdbminor\f31561\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}
{\fdbminor\f31562\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\fdbminor\f31563\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fdbminor\f31564\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\fdbminor\f31565\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\fdbminor\f31566\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fhiminor\f31568\fbidi \fswiss\fcharset238\fprq2 Calibri CE;}
{\fhiminor\f31569\fbidi \fswiss\fcharset204\fprq2 Calibri Cyr;}{\fhiminor\f31571\fbidi \fswiss\fcharset161\fprq2 Calibri Greek;}{\fhiminor\f31572\fbidi \fswiss\fcharset162\fprq2 Calibri Tur;}
{\fhiminor\f31575\fbidi \fswiss\fcharset186\fprq2 Calibri Baltic;}{\fhiminor\f31576\fbidi \fswiss\fcharset163\fprq2 Calibri (Vietnamese);}{\fbiminor\f31578\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}
{\fbiminor\f31579\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fbiminor\f31581\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fbiminor\f31582\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}
{\fbiminor\f31583\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fbiminor\f31584\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fbiminor\f31585\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}
{\fbiminor\f31586\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;
\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\*\defchp
\fs22\loch\af31506\hich\af31506\dbch\af31505 }{\*\defpap \ql \li0\ri0\sa200\sl276\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 }\noqfpromote {\stylesheet{\ql \li0\ri0\sa200\sl276\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \fs22\lang1043\langfe1043\loch\f31506\hich\af31506\dbch\af31505\cgrid\langnp1043\langfenp1043 \snext0 \sqformat \spriority0 Normal;}
{\*\cs10 \additive \ssemihidden \sunhideused \spriority1 Default Paragraph Font;}{\*
\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tblind0\tblindtype3\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv \ql \li0\ri0\sa200\sl276\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \fs22\lang1043\langfe1043\loch\f31506\hich\af31506\dbch\af31505\cgrid\langnp1043\langfenp1043
\snext11 \ssemihidden \sunhideused \sqformat Normal Table;}}{\*\rsidtbl \rsid11566407}{\mmathPr\mmathFont34\mbrkBin0\mbrkBinSub0\msmallFrac0\mdispDef1\mlMargin0\mrMargin0\mdefJc1\mwrapIndent1440\mintLim0\mnaryLim1}{\info{\operator van der beek}
{\creatim\yr2012\mo1\dy3\hr12\min37}{\revtim\yr2012\mo1\dy3\hr12\min39}{\version2}{\edmins2}{\nofpages1}{\nofwords121}{\nofchars674}{\nofcharsws794}{\vern32771}}{\*\xmlnstbl {\xmlns1 http://schemas.microsoft.com/office/word/2003/wordml}}
\paperw12240\paperh15840\margl1417\margr1417\margt1417\margb1417\gutter0\ltrsect
\widowctrl\ftnbj\aenddoc\hyphhotz425\trackmoves1\trackformatting1\donotembedsysfont0\relyonvml0\donotembedlingdata1\grfdocevents0\validatexml0\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0\showxmlerrors0\horzdoc\dghspace120\dgvspace120
\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind1\viewscale100\rsidroot11566407 \fet0{\*\wgrffmtfilter 2450}\ilfomacatclnup0\ltrpar \sectd \ltrsect\linex0\headery708\footery708\colsx708\sectdefaultcl\sftnbj {\*\pnseclvl1
\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5
\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang
{\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0
\fs22\lang1043\langfe1043\loch\af31506\hich\af31506\dbch\af31505\cgrid\langnp1043\langfenp1043 {\rtlch\fcs1 \af2 \ltrch\fcs0 \f2\lang1033\langfe1043\langnp1033\insrsid11566407\charrsid11566407 \hich\af2\dbch\af31505\loch\f2
Heap Inspector is Copyright 2010-201}{\rtlch\fcs1 \af2 \ltrch\fcs0 \f2\lang1033\langfe1043\langnp1033\insrsid11566407 \hich\af2\dbch\af31505\loch\f2 2}{\rtlch\fcs1 \af2 \ltrch\fcs0 \f2\lang1033\langfe1043\langnp1033\insrsid11566407\charrsid11566407
\hich\af2\dbch\af31505\loch\f2 by Jelle van der Beek
\par -------------------------------------------------------------
\par
\par \hich\af2\dbch\af31505\loch\f2 This software is provided free of charge. \hich\af2\dbch\af31505\loch\f2 If Heap Inspector helped in the production of your application, }{\rtlch\fcs1 \af2 \ltrch\fcs0 \f2\lang1033\langfe1043\langnp1033\insrsid11566407
\hich\af2\dbch\af31505\loch\f2 a mention of }{\rtlch\fcs1 \af2 \ltrch\fcs0 \f2\lang1033\langfe1043\langnp1033\insrsid11566407\charrsid11566407 \hich\af2\dbch\af31505\loch\f2 Heap Inspector \hich\af2\dbch\af31505\loch\f2
in the product or its accompanying documentation}{\rtlch\fcs1 \af2 \ltrch\fcs0 \f2\lang1033\langfe1043\langnp1033\insrsid11566407 \hich\af2\dbch\af31505\loch\f2 is \hich\af2\dbch\af31505\loch\f2 highly \hich\af2\dbch\af31505\loch\f2
appreciated, but not required}{\rtlch\fcs1 \af2 \ltrch\fcs0 \f2\lang1033\langfe1043\langnp1033\insrsid11566407\charrsid11566407 \hich\af2\dbch\af31505\loch\f2 . The copyright notice above may serve as an examp\hich\af2\dbch\af31505\loch\f2 le.
\par
\par
\par \hich\af2\dbch\af31505\loch\f2
JELLE VAN DER BEEK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. IN NO EVENT SHALL JELLE VAN DER BEEK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHE
\hich\af2\dbch\af31505\loch\f2 R IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
\par
\par }{\*\themedata 504b030414000600080000002100828abc13fa0000001c020000130000005b436f6e74656e745f54797065735d2e786d6cac91cb6ac3301045f785fe83d0b6d8
72ba28a5d8cea249777d2cd20f18e4b12d6a8f843409c9df77ecb850ba082d74231062ce997b55ae8fe3a00e1893f354e9555e6885647de3a8abf4fbee29bbd7
2a3150038327acf409935ed7d757e5ee14302999a654e99e393c18936c8f23a4dc072479697d1c81e51a3b13c07e4087e6b628ee8cf5c4489cf1c4d075f92a0b
44d7a07a83c82f308ac7b0a0f0fbf90c2480980b58abc733615aa2d210c2e02cb04430076a7ee833dfb6ce62e3ed7e14693e8317d8cd0433bf5c60f53fea2fe7
065bd80facb647e9e25c7fc421fd2ddb526b2e9373fed4bb902e182e97b7b461e6bfad3f010000ffff0300504b030414000600080000002100a5d6a7e7c00000
00360100000b0000005f72656c732f2e72656c73848fcf6ac3300c87ef85bd83d17d51d2c31825762fa590432fa37d00e1287f68221bdb1bebdb4fc7060abb08
84a4eff7a93dfeae8bf9e194e720169aaa06c3e2433fcb68e1763dbf7f82c985a4a725085b787086a37bdbb55fbc50d1a33ccd311ba548b63095120f88d94fbc
52ae4264d1c910d24a45db3462247fa791715fd71f989e19e0364cd3f51652d73760ae8fa8c9ffb3c330cc9e4fc17faf2ce545046e37944c69e462a1a82fe353
bd90a865aad41ed0b5b8f9d6fd010000ffff0300504b0304140006000800000021006b799616830000008a0000001c0000007468656d652f7468656d652f7468
656d654d616e616765722e786d6c0ccc4d0ac3201040e17da17790d93763bb284562b2cbaebbf600439c1a41c7a0d29fdbd7e5e38337cedf14d59b4b0d592c9c
070d8a65cd2e88b7f07c2ca71ba8da481cc52c6ce1c715e6e97818c9b48d13df49c873517d23d59085adb5dd20d6b52bd521ef2cdd5eb9246a3d8b4757e8d3f7
29e245eb2b260a0238fd010000ffff0300504b0304140006000800000021002749e2e69e060000531b0000160000007468656d652f7468656d652f7468656d65
312e786d6cec594d6f1b4518be23f11f467b6f6327761a4775aad8b11b48d246b15bd4e37877bc3bcdecce6a669cd437d41e9190100571a012370e08a8d44a5c
caaf09144191fa1778676677bd13af69d20651417d48bcb3cfbcdfef331fbe7aed5eccd0111192f2a4edd52fd73c44129f073409dbdead61ffd29a87a4c24980
194f48db9b12e95ddb78ffbdab785d45242608e627721db7bd48a9747d6949fa308ce5659e9204de8db988b18247112e05021f83dc982d2dd76aab4b31a68987
121c83d89be331f5c9252d127b1bb9f01e030d89927ac06762a045936cc60e4e14e7c28083c3ba86c8a9ec32818e306b7ba028e0c743724f798861a9e045dbab
998fb7b4717509af6793985a30b734af6f3ed9bc6c4270b86c748a705428adf71bad2b5b857c03606a1ed7ebf5babd7a21cf00b0ef83abd696b2cc467faddec9
659640f6ebbcec6ead596bb8f892fc95399b5b9d4ea7d9ca6cb1420dc87e6dcce1d76aab8dcd65076f4016df9cc3373a9bddeeaa8337208b5f9dc3f7afb4561b
2ede80224693c339b44e68bf9f492f2063ceb62be16b005fab65f0190aaaa1282fad62cc13b5b0d8627c978b3e203492614513a4a62919631feab88be391a058
6bc0eb0497ded8215fce0d696548fa82a6aaed7d9862e88999bc97cfbe7ff9ec093ab9fff4e4fe4f270f1e9cdcffd10a72666de3242ccf7af1ed677f3efa18fd
f1e49b170fbfa8c6cb32fed71f3ef9e5e7cfab81d03f33739e7ff9f8b7a78f9f7ff5e9efdf3dac806f0a3c2ac387342612dd20c7e880c7e098898a6b391989f3
cd18469896676c26a1c409d65a2ae4f754e4a06f4c31cbb2e3d8d1216e046f0be08f2ae0f5c95dc7e04124268a5668de896207b8c739eb705119851dadab14e6
e12409ab958b49197780f15195ee2e4e9cfcf6262930675e968ee3dd883866ee33e0551c928428a4dff143422abcbb43a913d73dea0b2ef958a13b147530ad0c
c9908e9c6a9a4ddaa631e4655ae533e4db89cdde6dd4e1accaeb2d72e422a12b30ab307e489813c6eb78a2705c25728863560ef82e5651959183a9f0cbb89e54
90e990308e7a0191b26ace4d01fe9692be8381b22ad3bec7a6b18b148a1e56c9dcc59c97915bfcb01be138adc20e681295b11fc84328518cf6b9aa82ef71b743
f433e401270bd37d9b1227ddaf66835b34744c9a15887e33113a97c0d50e03c734f93b3a6614f8d8d6c0c5d13110e0f3af1f5554d6db4ac49bb0265575c2f629
fa5d843b4dba5d2e02faf673ee169e24fb04ca7c7ee17947b9ef28d7fbcf53eea27e3e2bd1ceb8156857ef1becaed8ec91e3c55be431656ca0a68cec4ab34b96
b050047d18d413cd01911467a63482af19b13bb85060330709ae3ea22a1a4438851d76ddd3424299890e254ab984a39d19ae94adf1b04b57f660d8d447064b08
12ab3d1ed8e1153d9c9f0c0a3166b909cdf93357b4a2059c55d9ca954c28b8fd3acaeadaa8336bab1bd30cd739da0a972189f3aec160114dd88120d8b7409457
e188ae55c3c9043312e8b8dbc5374f8bc9c245a648463820598eb4dff339aa9b24e5b5622e03a0762a72a48f79af885a495b4b8b7d036d674952595d6381ba3c
7b6f92a5bc826759d28d7baa1d59526e4e96a0e3b6d76a2e373de4e3b4ed8de1500b5fe314b22ef5a60fb310ee867c652f5b9c262dcac926ce36b3e9f259365b
b9636e13d4e1a2c2c67dce6147452aa4dac232b21accabac0458a23559fb979b10d68b72c056fa6b58b1b206c5f0af59017174534bc663e2ab72b24b233a76f6
31a3523e51440ca2e0188dd8441c6048bf2e55f027a012ee260c23e807b849d3d136af5c72ce9aae7c7f6570761cb334c219ddea16cd3bd9c24d1f173698a792
79e05ba5edc6b9f3bb625afe825c2997f1ffcc15bd9ec055c14aa033e0c34daec048f76bdbe342451c58288da8df17b073304b26540bdcc6c26b282ab84f36ff
0539d2ff6dcf5919a6ade1c4a70e68880485f5484582907da025537daf1056cfd62e2b9265824c4595cc95a9357b448e081b6a0e5cd56bbb87222875c326190d
18dce9fa739fb30e1a857a9353ee3787432ac9b2826b72f2bee09d8f6d66d0e7f2b0d9d0e4f12f4cac5855ed7c333d5f7b4fb3fe6c9bd5c8bb029495968256d6
f6af69c239975acb58731e2f3773e3208bf31ec360b1214ae1c207e93fb0fe51e13362ca582fa8437e00dc8ae0a7062d0cca06aafa92dd78204d907670041b27
3b68f3ac45d9d0665b271dce7f28df85de53c1d6969d25dfe70c76b13973d539bd7891c1ce22ecc4da8e2d0c3564f6748bc2d0383fc998c4985fb5ca3f3cf1d1
5d48f4165cf04f9892a698e057258161eb39307d00cd6f359aa91b7f010000ffff0300504b0304140006000800000021000dd1909fb60000001b010000270000
007468656d652f7468656d652f5f72656c732f7468656d654d616e616765722e786d6c2e72656c73848f4d0ac2301484f78277086f6fd3ba109126dd88d0add4
0384e4350d363f2451eced0dae2c082e8761be9969bb979dc9136332de3168aa1a083ae995719ac16db8ec8e4052164e89d93b64b060828e6f37ed1567914b28
4d262452282e3198720e274a939cd08a54f980ae38a38f56e422a3a641c8bbd048f7757da0f19b017cc524bd62107bd5001996509affb3fd381a89672f1f165d
fe514173d9850528a2c6cce0239baa4c04ca5bbabac4df000000ffff0300504b01022d0014000600080000002100828abc13fa0000001c020000130000000000
0000000000000000000000005b436f6e74656e745f54797065735d2e786d6c504b01022d0014000600080000002100a5d6a7e7c0000000360100000b00000000
0000000000000000002b0100005f72656c732f2e72656c73504b01022d00140006000800000021006b799616830000008a0000001c0000000000000000000000
0000140200007468656d652f7468656d652f7468656d654d616e616765722e786d6c504b01022d00140006000800000021002749e2e69e060000531b00001600
000000000000000000000000d10200007468656d652f7468656d652f7468656d65312e786d6c504b01022d00140006000800000021000dd1909fb60000001b01
00002700000000000000000000000000a30900007468656d652f7468656d652f5f72656c732f7468656d654d616e616765722e786d6c2e72656c73504b050600000000050005005d0100009e0a00000000}
{\*\colorschememapping 3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d3822207374616e64616c6f6e653d22796573223f3e0d0a3c613a636c724d
617020786d6c6e733a613d22687474703a2f2f736368656d61732e6f70656e786d6c666f726d6174732e6f72672f64726177696e676d6c2f323030362f6d6169
6e22206267313d226c743122207478313d22646b3122206267323d226c743222207478323d22646b322220616363656e74313d22616363656e74312220616363
656e74323d22616363656e74322220616363656e74333d22616363656e74332220616363656e74343d22616363656e74342220616363656e74353d22616363656e74352220616363656e74363d22616363656e74362220686c696e6b3d22686c696e6b2220666f6c486c696e6b3d22666f6c486c696e6b222f3e}
{\*\latentstyles\lsdstimax267\lsdlockeddef0\lsdsemihiddendef1\lsdunhideuseddef1\lsdqformatdef0\lsdprioritydef99{\lsdlockedexcept \lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority0 \lsdlocked0 Normal;
\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 1;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 2;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 3;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 4;
\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 5;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 6;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 7;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 8;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 9;
\lsdpriority39 \lsdlocked0 toc 1;\lsdpriority39 \lsdlocked0 toc 2;\lsdpriority39 \lsdlocked0 toc 3;\lsdpriority39 \lsdlocked0 toc 4;\lsdpriority39 \lsdlocked0 toc 5;\lsdpriority39 \lsdlocked0 toc 6;\lsdpriority39 \lsdlocked0 toc 7;
\lsdpriority39 \lsdlocked0 toc 8;\lsdpriority39 \lsdlocked0 toc 9;\lsdqformat1 \lsdpriority35 \lsdlocked0 caption;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority10 \lsdlocked0 Title;\lsdpriority1 \lsdlocked0 Default Paragraph Font;
\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority11 \lsdlocked0 Subtitle;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority22 \lsdlocked0 Strong;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority20 \lsdlocked0 Emphasis;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority59 \lsdlocked0 Table Grid;\lsdunhideused0 \lsdlocked0 Placeholder Text;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority1 \lsdlocked0 No Spacing;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading;\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 1;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 1;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 1;\lsdunhideused0 \lsdlocked0 Revision;
\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority34 \lsdlocked0 List Paragraph;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority29 \lsdlocked0 Quote;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority30 \lsdlocked0 Intense Quote;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 1;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 1;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 2;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 2;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 2;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 2;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 2;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 3;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 3;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 3;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 3;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 3;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 4;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 4;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 4;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 4;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 5;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 5;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 5;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 5;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 5;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 6;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 6;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 6;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 6;
\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 6;
\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority19 \lsdlocked0 Subtle Emphasis;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority21 \lsdlocked0 Intense Emphasis;
\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority31 \lsdlocked0 Subtle Reference;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority32 \lsdlocked0 Intense Reference;
\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority33 \lsdlocked0 Book Title;\lsdpriority37 \lsdlocked0 Bibliography;\lsdqformat1 \lsdpriority39 \lsdlocked0 TOC Heading;}}{\*\datastore 010500000200000018000000
4d73786d6c322e534158584d4c5265616465722e352e3000000000000000000000060000
d0cf11e0a1b11ae1000000000000000000000000000000003e000300feff090006000000000000000000000001000000010000000000000000100000feffffff00000000feffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
fffffffffffffffffdfffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffff52006f006f007400200045006e00740072007900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000500ffffffffffffffffffffffffec69d9888b8b3d4c859eaf6cd158be0f000000000000000000000000a0ec
1d650ccacc01feffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000105000000000000}}
@@ -0,0 +1,30 @@
// =================================================================================================================================
// This sample demonstrates how to use the auto-hooking functionality of HeapInspector. On PlayStation 3, this uses link-time
// malloc/realloc/free overloading. On PC it uses the mhook API, which will hook into the very low-level HeapAlloc, HeapRealloc
// and HeapFree functions. This will cause any allocations in your application to be caught.
//
// NOTE: the platform specific hooking calls can be found in the Main<platform>.cpp.
// =================================================================================================================================
#include <stdlib.h>
void Wait(int a_MilliSeconds);
void RunHeapInspectorServer()
{
while (1)
{
void* mem1;
void* memB;
mem1 = malloc(16);
memB = malloc(1024);
Wait(100);
free(mem1);
free(memB);
Wait(100);
}
}
@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="HookSample"
ProjectGUID="{79AEA684-C1E1-4E26-A335-E98B4088FD5C}"
RootNamespace="BasicServerSample"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="PS3 Debug|Win32"
OutputDirectory="Debug_VS2008"
IntermediateDirectory="Debug_VS2008"
ConfigurationType="1"
DeleteExtensionsOnClean="*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);$(TargetDir)$(TargetName).self"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-g -Wall -fno-exceptions -fno-rtti"
AdditionalIncludeDirectories="&quot;$(SN_PS3_PATH)\ppu\include\sn&quot;;&quot;$(SCE_PS3_ROOT)\target\ppu\include&quot;;&quot;$(SCE_PS3_ROOT)\target\common\include&quot;"
PreprocessorDefinitions="SN_TARGET_PS3;_DEBUG;__GCC__;__CELL_ASSERT__;HEAPINSPECTOR_PS3=1"
ProgramDataBaseFileName=""
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="-fno-exceptions -fno-rtti -Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init"
AdditionalDependencies="&quot;$(SN_PS3_PATH)\ppu\lib\sn\libsn.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libm.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a&quot; &quot;..\..\..\Server\PS3\Debug\libHeapInspectorServer.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a&quot;"
OutputFile="$(OutDir)/$(ProjectName).ppu.elf"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=""
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Fake Signing ELF &quot;$(TargetDir)$(TargetName).self&quot;"
CommandLine="$(SCE_PS3_ROOT)\host-win32\bin\make_fself &quot;$(TargetPath)&quot; &quot;$(TargetDir)$(TargetName).self&quot;"
/>
</Configuration>
<Configuration
Name="PS3 Release|Win32"
OutputDirectory="Release_VS2008"
IntermediateDirectory="Release_VS2008"
ConfigurationType="1"
DeleteExtensionsOnClean="*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);$(TargetDir)$(TargetName).self"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-Wall -fno-exceptions -fno-rtti -O2"
AdditionalIncludeDirectories="&quot;$(SN_PS3_PATH)\ppu\include\sn&quot;;&quot;$(SCE_PS3_ROOT)\target\ppu\include&quot;;&quot;$(SCE_PS3_ROOT)\target\common\include&quot;"
PreprocessorDefinitions="SN_TARGET_PS3;NDEBUG;__GCC__;HEAPINSPECTOR_PS3=1"
ProgramDataBaseFileName=""
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="-fno-exceptions -fno-rtti -Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init"
AdditionalDependencies="&quot;$(SN_PS3_PATH)\ppu\lib\sn\libsn.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libm.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a&quot; &quot;..\..\..\Server\PS3\Release\libHeapInspectorServer.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a&quot;"
OutputFile="$(OutDir)/$(ProjectName).ppu.elf"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=""
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Fake Signing ELF &quot;$(TargetDir)$(TargetName).self&quot;"
CommandLine="$(SCE_PS3_ROOT)\host-win32\bin\make_fself &quot;$(TargetPath)&quot; &quot;$(TargetDir)$(TargetName).self&quot;"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="PS3"
>
<File
RelativePath=".\Main.cpp"
>
</File>
<File
RelativePath=".\Wait.cpp"
>
</File>
</Filter>
<File
RelativePath="..\HookSample.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,72 @@
<?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|PS3">
<Configuration>Debug</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|PS3">
<Configuration>Release</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\HookSample.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Wait.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{F749F5D0-B972-4E99-8B4B-2B865D4A8BC9}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>GCC</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>GCC</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<OutDir>$(ProjectDir)$(Platform)_$(Configuration)_VS2010\</OutDir>
<IntDir>$(Platform)_$(Configuration)_VS2010\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<OutDir>$(ProjectDir)$(Platform)_$(Configuration)_VS2010\</OutDir>
<IntDir>$(Platform)_$(Configuration)_VS2010\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;__CELL_ASSERT__;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1</PreprocessorDefinitions>
<GenerateDebugInformation>true</GenerateDebugInformation>
</ClCompile>
<Link>
<AdditionalDependencies>"$(SCE_PS3_ROOT)\target\ppu\lib\libm.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a";"..\..\..\Server\PS3\Debug\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>-Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1</PreprocessorDefinitions>
<OptimizationLevel>Level2</OptimizationLevel>
</ClCompile>
<Link>
<AdditionalDependencies>"..\..\..\Server\PS3\Release\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>-Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<Import Condition="'$(ConfigurationType)' == 'Makefile' and Exists('$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets')" Project="$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,18 @@
#include "../../../Server/HeapInspectorServer.h"
#include "../../../Server/PS3/HeapHooks.hpp"
void RunHeapInspectorServer();
extern "C" void* __real__malloc_init();
extern "C" void* __wrap__malloc_init()
{
void* result = __real__malloc_init();
Initialise(HeapInspectorServer::GetDefaultHeapInfo(), 3000, HeapInspectorServer::WaitForConnection_Enabled);
return result;
}
int main(int /*a_ArgC*/, const char* /*a_ArgV[]*/)
{
RunHeapInspectorServer();
HeapInspectorServer::Shutdown();
}
@@ -0,0 +1,6 @@
#include <sys/timer.h>
void Wait(int a_Milliseconds)
{
sys_timer_usleep(a_Milliseconds * 1000);
}
@@ -0,0 +1,78 @@
// =================================================================================================================================
// This sample demonstrates how to use the Server API to send allocs, reallocs and frees directly to the client. It also shows
// how to configure multiple heaps.
// =================================================================================================================================
#include "../../Server/HeapInspectorServer.h"
#include <stdlib.h>
using namespace HeapInspectorServer;
void Wait(int a_MilliSeconds);
std::vector<HeapInfo> GetHeapInfo()
{
std::vector<HeapInfo> result;
HeapInfo heapInfo;
heapInfo.m_Description = "Heap1";
heapInfo.m_Range.m_Min = 0;
heapInfo.m_Range.m_Max = 0x80000000 - 1;
result.push_back(heapInfo);
heapInfo.m_Description = "Heap2";
heapInfo.m_Range.m_Min = 0;
heapInfo.m_Range.m_Max = 0x80000000 - 1;
result.push_back(heapInfo);
return result;
}
void* Alloc(uint32 a_Size, int a_Heap)
{
Mutation mutation = BeginAlloc();
void* mem = malloc(a_Size);
EndAlloc(mutation, a_Heap, mem, a_Size, a_Size);
return mem;
}
void Free(void* a_Block, int a_Heap)
{
Mutation mutation = BeginFree();
free(a_Block);
EndFree(mutation, a_Heap, a_Block);
}
void* ReAlloc(void* a_OldBlock, uint32 a_Size, int a_Heap)
{
Mutation mutation = BeginReAlloc();
void* mem = realloc(a_OldBlock, a_Size);
EndReAlloc(mutation, a_Heap, a_OldBlock, mem, a_Size, a_Size);
return mem;
}
void RunHeapInspectorServer()
{
Initialise(GetHeapInfo(), 3000, WaitForConnection_Enabled);
while (1)
{
void* mem1;
void* memB;
mem1 = Alloc(16, 0);
memB = Alloc(1024, 1);
Wait(100);
void* mem2 = ReAlloc(mem1, 32, 0);
Wait(100);
Free(mem2, 0);
Free(memB, 1);
Wait(100);
}
Shutdown();
}
@@ -0,0 +1,7 @@
void RunHeapInspectorServer();
int main(int /*a_ArgC*/, const char* /*a_ArgV[]*/)
{
RunHeapInspectorServer();
}
@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="ManualSample"
ProjectGUID="{EE51F556-4CCE-4D4C-96C3-B271CC035C6E}"
RootNamespace="BasicServerSample"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="PS3 Debug|Win32"
OutputDirectory="Debug_VS2008"
IntermediateDirectory="Debug_VS2008"
ConfigurationType="1"
DeleteExtensionsOnClean="*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);$(TargetDir)$(TargetName).self"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-g -Wall -fno-exceptions -fno-rtti"
AdditionalIncludeDirectories="&quot;$(SN_PS3_PATH)\ppu\include\sn&quot;;&quot;$(SCE_PS3_ROOT)\target\ppu\include&quot;;&quot;$(SCE_PS3_ROOT)\target\common\include&quot;"
PreprocessorDefinitions="SN_TARGET_PS3;_DEBUG;__GCC__;__CELL_ASSERT__;HEAPINSPECTOR_PS3=1"
ProgramDataBaseFileName=""
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="-fno-exceptions -fno-rtti"
AdditionalDependencies="&quot;$(SN_PS3_PATH)\ppu\lib\sn\libsn.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libm.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a&quot; &quot;..\..\..\Server\PS3\Debug\libHeapInspectorServer.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a&quot;"
OutputFile="$(OutDir)/$(ProjectName).ppu.elf"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=""
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Fake Signing ELF &quot;$(TargetDir)$(TargetName).self&quot;"
CommandLine="$(SCE_PS3_ROOT)\host-win32\bin\make_fself &quot;$(TargetPath)&quot; &quot;$(TargetDir)$(TargetName).self&quot;"
/>
</Configuration>
<Configuration
Name="PS3 Release|Win32"
OutputDirectory="Release_VS2008"
IntermediateDirectory="Release_VS2008"
ConfigurationType="1"
DeleteExtensionsOnClean="*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);$(TargetDir)$(TargetName).self"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-O2 -Wall -fno-exceptions -fno-rtti"
AdditionalIncludeDirectories="&quot;$(SN_PS3_PATH)\ppu\include\sn&quot;;&quot;$(SCE_PS3_ROOT)\target\ppu\include&quot;;&quot;$(SCE_PS3_ROOT)\target\common\include&quot;"
PreprocessorDefinitions="SN_TARGET_PS3;NDEBUG;__GCC__;HEAPINSPECTOR_PS3=1"
ProgramDataBaseFileName=""
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="-fno-exceptions -fno-rtti"
AdditionalDependencies="&quot;$(SN_PS3_PATH)\ppu\lib\sn\libsn.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libm.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a&quot; &quot;..\..\..\Server\PS3\Release\libHeapInspectorServer.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a&quot;"
OutputFile="$(OutDir)/$(ProjectName).ppu.elf"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=""
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Fake Signing ELF &quot;$(TargetDir)$(TargetName).self&quot;"
CommandLine="$(SCE_PS3_ROOT)\host-win32\bin\make_fself &quot;$(TargetPath)&quot; &quot;$(TargetDir)$(TargetName).self&quot;"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="PS3"
>
<File
RelativePath=".\Main.cpp"
>
</File>
<File
RelativePath=".\Wait.cpp"
>
</File>
</Filter>
<File
RelativePath="..\ManualSample.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,70 @@
<?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|PS3">
<Configuration>Debug</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|PS3">
<Configuration>Release</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\ManualSample.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Wait.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B6B851C9-DC76-4A5B-9AFE-6CF944BFB502}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>GCC</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>GCC</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<OutDir>$(ProjectDir)$(Platform)_$(Configuration)_VS2010\</OutDir>
<IntDir>$(Platform)_$(Configuration)_VS2010\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<OutDir>$(ProjectDir)$(Platform)_$(Configuration)_VS2010\</OutDir>
<IntDir>$(Platform)_$(Configuration)_VS2010\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;__CELL_ASSERT__;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1</PreprocessorDefinitions>
<GenerateDebugInformation>true</GenerateDebugInformation>
</ClCompile>
<Link>
<AdditionalDependencies>"$(SCE_PS3_ROOT)\target\ppu\lib\libm.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a";"..\..\..\Server\PS3\Debug\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1</PreprocessorDefinitions>
<OptimizationLevel>Level2</OptimizationLevel>
</ClCompile>
<Link>
<AdditionalDependencies>"..\..\..\Server\PS3\Release\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Condition="'$(ConfigurationType)' == 'Makefile' and Exists('$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets')" Project="$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,6 @@
#include <sys/timer.h>
void Wait(int a_Milliseconds)
{
sys_timer_usleep(a_Milliseconds * 1000);
}
@@ -0,0 +1,17 @@
#ifndef _MULTITHREADEDHOOKSAMPLE_ITHREAD_H_
#define _MULTITHREADEDHOOKSAMPLE_ITHREAD_H_
typedef void(*ThreadFunction)();
class IThread
{
public:
virtual ~IThread() {}
virtual void Fork(ThreadFunction a_Function) = 0;
virtual void Join() = 0;
};
IThread* CreateThread();
void DestroyThread(IThread* a_Thread);
#endif // _MULTITHREADEDHOOKSAMPLE_ITHREAD_H_
@@ -0,0 +1,80 @@
// =================================================================================================================================
// This sample is more of a show-(and test) case for HeapInspector's. It demonstrates:
// 1) That HeapInspector is multithread safe.
// 2) HeapInspector's ability to deal with allocations prior to Initialise (although those allocations will not be tracked).
// 3) HeapInspector's ability to deal with API calls during static initialisation phase.
//
// In this sample, multiple threads are started that perform allocations for a set period of time. The
// application will wait for those threads to finish. After the time is passed and the application calls Shutdown,
// the client will disconnect.
//
// To switch between launching the threads during the static initalisation phase and launching the treads
// in main, flip the INIT_IN_STATIC_PHASE define.
//
// =================================================================================================================================
#include "IThread.h"
#include <stdlib.h>
void Wait(int a_MilliSeconds);
#define INIT_IN_STATIC_PHASE 0
const int g_NumThreads = 4;
class MultiThreadedAllocator
{
public:
static void WorkerThread()
{
for (int i = 0; i != 1000; ++i)
{
void* mem1 = malloc(10);
Wait(10);
free(mem1);
Wait(10);
}
}
MultiThreadedAllocator()
{
for (int i = 0; i != g_NumThreads; ++i)
{
m_Threads[i] = CreateThread();
m_Threads[i]->Fork(WorkerThread);
}
}
~MultiThreadedAllocator()
{
WaitForThreads();
for (int i = 0; i != g_NumThreads; ++i)
{
DestroyThread(m_Threads[i]);
}
}
private:
void WaitForThreads()
{
for (int i = 0; i != g_NumThreads; ++i)
{
m_Threads[i]->Join();
}
}
private:
IThread* m_Threads[g_NumThreads];
};
#if INIT_IN_STATIC_PHASE
static MultiThreadedAllocator* g_Allocator = new MultiThreadedAllocator();
#endif
void RunHeapInspectorServer()
{
#if !INIT_IN_STATIC_PHASE
MultiThreadedAllocator* g_Allocator = new MultiThreadedAllocator();
#endif
delete g_Allocator;
}
@@ -0,0 +1,18 @@
#include "../../../Server/HeapInspectorServer.h"
#include "../../../Server/PS3/HeapHooks.hpp"
void RunHeapInspectorServer();
extern "C" void* __real__malloc_init();
extern "C" void* __wrap__malloc_init()
{
void* result = __real__malloc_init();
Initialise(HeapInspectorServer::GetDefaultHeapInfo(), 3000, HeapInspectorServer::WaitForConnection_Enabled);
return result;
}
int main(int /*a_ArgC*/, const char* /*a_ArgV[]*/)
{
RunHeapInspectorServer();
HeapInspectorServer::Shutdown();
}
@@ -0,0 +1,191 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="MultiThreadedHookSample"
ProjectGUID="{37C97160-EB4F-46FD-9CA7-0E0789EFE398}"
RootNamespace="BasicServerSample"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="PS3 Debug|Win32"
OutputDirectory="Debug_VS2008"
IntermediateDirectory="Debug_VS2008"
ConfigurationType="1"
DeleteExtensionsOnClean="*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);$(TargetDir)$(TargetName).self"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-g -Wall -fno-exceptions -fno-rtti"
AdditionalIncludeDirectories="&quot;$(SN_PS3_PATH)\ppu\include\sn&quot;;&quot;$(SCE_PS3_ROOT)\target\ppu\include&quot;;&quot;$(SCE_PS3_ROOT)\target\common\include&quot;"
PreprocessorDefinitions="SN_TARGET_PS3;_DEBUG;__GCC__;__CELL_ASSERT__;HEAPINSPECTOR_PS3=1"
ProgramDataBaseFileName=""
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="-fno-exceptions -fno-rtti -Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init"
AdditionalDependencies="&quot;$(SN_PS3_PATH)\ppu\lib\sn\libsn.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libm.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a&quot; &quot;..\..\..\Server\PS3\Debug\libHeapInspectorServer.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a&quot;"
OutputFile="$(OutDir)/$(ProjectName).ppu.elf"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=""
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Fake Signing ELF &quot;$(TargetDir)$(TargetName).self&quot;"
CommandLine="$(SCE_PS3_ROOT)\host-win32\bin\make_fself &quot;$(TargetPath)&quot; &quot;$(TargetDir)$(TargetName).self&quot;"
/>
</Configuration>
<Configuration
Name="PS3 Release|Win32"
OutputDirectory="Release_VS2008"
IntermediateDirectory="Release_VS2008"
ConfigurationType="1"
DeleteExtensionsOnClean="*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);$(TargetDir)$(TargetName).self"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-Wall -fno-exceptions -fno-rtti -O2"
AdditionalIncludeDirectories="&quot;$(SN_PS3_PATH)\ppu\include\sn&quot;;&quot;$(SCE_PS3_ROOT)\target\ppu\include&quot;;&quot;$(SCE_PS3_ROOT)\target\common\include&quot;"
PreprocessorDefinitions="SN_TARGET_PS3;NDEBUG;__GCC__;HEAPINSPECTOR_PS3=1"
ProgramDataBaseFileName=""
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="-fno-exceptions -fno-rtti -Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init"
AdditionalDependencies="&quot;$(SN_PS3_PATH)\ppu\lib\sn\libsn.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libm.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a&quot; &quot;..\..\..\Server\PS3\Release\libHeapInspectorServer.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a&quot;"
OutputFile="$(OutDir)/$(ProjectName).ppu.elf"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=""
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Fake Signing ELF &quot;$(TargetDir)$(TargetName).self&quot;"
CommandLine="$(SCE_PS3_ROOT)\host-win32\bin\make_fself &quot;$(TargetPath)&quot; &quot;$(TargetDir)$(TargetName).self&quot;"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="PS3"
>
<File
RelativePath=".\Main.cpp"
>
</File>
<File
RelativePath=".\ThreadPS3.cpp"
>
</File>
<File
RelativePath=".\Wait.cpp"
>
</File>
</Filter>
<File
RelativePath="..\IThread.h"
>
</File>
<File
RelativePath="..\MultiThreadedHookSample.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,76 @@
<?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|PS3">
<Configuration>Debug</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|PS3">
<Configuration>Release</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\IThread.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\MultiThreadedHookSample.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="ThreadPS3.cpp" />
<ClCompile Include="Wait.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E9BC25AD-CFFD-43B6-ABEC-CA516CADD296}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>GCC</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>GCC</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<OutDir>$(ProjectDir)$(Platform)_$(Configuration)_VS2010\</OutDir>
<IntDir>$(Platform)_$(Configuration)_VS2010\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<OutDir>$(ProjectDir)$(Platform)_$(Configuration)_VS2010\</OutDir>
<IntDir>$(Platform)_$(Configuration)_VS2010\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;__CELL_ASSERT__;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1</PreprocessorDefinitions>
<GenerateDebugInformation>true</GenerateDebugInformation>
</ClCompile>
<Link>
<AdditionalDependencies>"$(SCE_PS3_ROOT)\target\ppu\lib\libm.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a";"..\..\..\Server\PS3\Debug\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>-Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1</PreprocessorDefinitions>
<OptimizationLevel>Level2</OptimizationLevel>
</ClCompile>
<Link>
<AdditionalDependencies>"..\..\..\Server\PS3\Release\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>-Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<Import Condition="'$(ConfigurationType)' == 'Makefile' and Exists('$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets')" Project="$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,41 @@
#include <pthread.h>
#include "../IThread.h"
void* InternalThread(void* a_UserData)
{
ThreadFunction function = (ThreadFunction)a_UserData;
function();
pthread_exit(0);
return 0;
}
class ThreadPS3 : public IThread
{
public:
virtual void Fork(ThreadFunction a_Function)
{
pthread_create(&m_Thread, 0, InternalThread, (void*)a_Function);
}
virtual void Join()
{
void* threadResult;
pthread_join(m_Thread, &threadResult);
}
private:
pthread_t m_Thread;
};
IThread* CreateThread()
{
return new ThreadPS3();
}
void DestroyThread(IThread* a_Thread)
{
delete a_Thread;
}
@@ -0,0 +1,6 @@
#include <sys/timer.h>
void Wait(int a_Milliseconds)
{
sys_timer_usleep(a_Milliseconds * 1000);
}
@@ -0,0 +1,7 @@
void RunHeapInspectorServer();
int main(int /*a_ArgC*/, const char* /*a_ArgV[]*/)
{
RunHeapInspectorServer();
}
@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="ReplaceNewDeleteSample"
ProjectGUID="{EFE31408-0463-46AB-8695-CD342951EC17}"
RootNamespace="BasicServerSample"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="PS3 Debug|Win32"
OutputDirectory="Debug_VS2008"
IntermediateDirectory="Debug_VS2008"
ConfigurationType="1"
DeleteExtensionsOnClean="*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);$(TargetDir)$(TargetName).self"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-g -Wall -fno-exceptions -fno-rtti"
AdditionalIncludeDirectories="&quot;$(SN_PS3_PATH)\ppu\include\sn&quot;;&quot;$(SCE_PS3_ROOT)\target\ppu\include&quot;;&quot;$(SCE_PS3_ROOT)\target\common\include&quot;"
PreprocessorDefinitions="SN_TARGET_PS3;_DEBUG;__GCC__;__CELL_ASSERT__;HEAPINSPECTOR_PS3=1"
ProgramDataBaseFileName=""
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="-fno-exceptions -fno-rtti"
AdditionalDependencies="&quot;$(SN_PS3_PATH)\ppu\lib\sn\libsn.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libm.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a&quot; &quot;..\..\..\Server\PS3\Debug\libHeapInspectorServer.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a&quot;"
OutputFile="$(OutDir)/$(ProjectName).ppu.elf"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=""
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Fake Signing ELF &quot;$(TargetDir)$(TargetName).self&quot;"
CommandLine="$(SCE_PS3_ROOT)\host-win32\bin\make_fself &quot;$(TargetPath)&quot; &quot;$(TargetDir)$(TargetName).self&quot;"
/>
</Configuration>
<Configuration
Name="PS3 Release|Win32"
OutputDirectory="Release_VS2008"
IntermediateDirectory="Release_VS2008"
ConfigurationType="1"
DeleteExtensionsOnClean="*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);$(TargetDir)$(TargetName).self"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-O2 -Wall -fno-exceptions -fno-rtti"
AdditionalIncludeDirectories="&quot;$(SN_PS3_PATH)\ppu\include\sn&quot;;&quot;$(SCE_PS3_ROOT)\target\ppu\include&quot;;&quot;$(SCE_PS3_ROOT)\target\common\include&quot;"
PreprocessorDefinitions="SN_TARGET_PS3;NDEBUG;__GCC__;HEAPINSPECTOR_PS3=1"
ProgramDataBaseFileName=""
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="-fno-exceptions -fno-rtti"
AdditionalDependencies="&quot;$(SN_PS3_PATH)\ppu\lib\sn\libsn.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libm.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a&quot; &quot;..\..\..\Server\PS3\Release\libHeapInspectorServer.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a&quot; &quot;$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a&quot;"
OutputFile="$(OutDir)/$(ProjectName).ppu.elf"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=""
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Fake Signing ELF &quot;$(TargetDir)$(TargetName).self&quot;"
CommandLine="$(SCE_PS3_ROOT)\host-win32\bin\make_fself &quot;$(TargetPath)&quot; &quot;$(TargetDir)$(TargetName).self&quot;"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="PS3"
>
<File
RelativePath=".\Main.cpp"
>
</File>
<File
RelativePath=".\Wait.cpp"
>
</File>
</Filter>
<File
RelativePath="..\ReplaceNewDeleteSample.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,70 @@
<?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|PS3">
<Configuration>Debug</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|PS3">
<Configuration>Release</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\ReplaceNewDeleteSample.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Wait.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B0416FCD-A32B-4F91-93D1-4EDFF99F740B}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>GCC</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>GCC</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<OutDir>$(ProjectDir)$(Platform)_$(Configuration)_VS2010\</OutDir>
<IntDir>$(Platform)_$(Configuration)_VS2010\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<OutDir>$(ProjectDir)$(Platform)_$(Configuration)_VS2010\</OutDir>
<IntDir>$(Platform)_$(Configuration)_VS2010\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;__CELL_ASSERT__;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1</PreprocessorDefinitions>
<GenerateDebugInformation>true</GenerateDebugInformation>
</ClCompile>
<Link>
<AdditionalDependencies>"$(SCE_PS3_ROOT)\target\ppu\lib\libm.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a";"..\..\..\Server\PS3\Debug\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1</PreprocessorDefinitions>
<OptimizationLevel>Level2</OptimizationLevel>
</ClCompile>
<Link>
<AdditionalDependencies>"..\..\..\Server\PS3\Release\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Condition="'$(ConfigurationType)' == 'Makefile' and Exists('$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets')" Project="$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,6 @@
#include <sys/timer.h>
void Wait(int a_Milliseconds)
{
sys_timer_usleep(a_Milliseconds * 1000);
}
@@ -0,0 +1,67 @@
// =================================================================================================================================
// This sample demonstrates how to replace operator new and delete and how to send these allocations to the HeapInspector client.
// Please note that the Hook sample captures allocations on a lower level and will also trace all new/delete allocations.
//
// WARNING: Make sure that you replace both the array and non-array operators. If there are any pairing issues in your code
// (allocating with new[] and deleting with delete), HeapInspector will miss those deallocations and that will be problematic
// for a subsequent allocation on that address: it will then warn that it found a double allocation. That will actually be a
// sign that the operators aren't properly matched.
// =================================================================================================================================
#include "../../Server/HeapInspectorServer.h"
#include <stdlib.h>
#include <new>
using namespace HeapInspectorServer;
void Wait(int a_MilliSeconds);
void* operator new(size_t a_Size)
{
Mutation mutation = BeginAlloc();
void* mem = malloc(a_Size);
EndAlloc(mutation, 0, mem, a_Size, a_Size);
return mem;
}
void operator delete(void* a_Pointer)
{
Mutation mutation = BeginFree();
free(a_Pointer);
EndFree(mutation, 0, a_Pointer);
}
void* operator new[](size_t a_Size)
{
Mutation mutation = BeginAlloc();
void* mem = malloc(a_Size);
EndAlloc(mutation, 0, mem, a_Size, a_Size);
return mem;
}
void operator delete[](void* a_Pointer)
{
Mutation mutation = BeginFree();
free(a_Pointer);
EndFree(mutation, 0, a_Pointer);
}
void RunHeapInspectorServer()
{
Initialise(GetDefaultHeapInfo(), 3000, WaitForConnection_Enabled);
while (1)
{
int* xArray = new int[100];
float* y = new float;
Wait(100);
delete[] xArray;
delete y;
Wait(100);
}
Shutdown();
}
@@ -0,0 +1,23 @@
#ifndef _HEAPINSPECTORSERVER_HEAPINFO_H_
#define _HEAPINSPECTORSERVER_HEAPINFO_H_
#include "HeapInspectorServerTypes.h"
#include <string>
BEGIN_NAMESPACE(HeapInspectorServer)
struct Range
{
uint32 m_Min;
uint32 m_Max;
};
struct HeapInfo
{
std::string m_Description;
Range m_Range;
};
END_NAMESPACE(HeapInspectorServer)
#endif // _HEAPINSPECTORSERVER_HEAPINFO_H_
@@ -0,0 +1,33 @@
#ifndef _HEAPINSPECTORSERVER_PLATFORMINTERFACES_HEAPINSPECTORSERVER_H_
#define _HEAPINSPECTORSERVER_PLATFORMINTERFACES_HEAPINSPECTORSERVER_H_
#include "HeapInfo.h"
#include <vector>
BEGIN_NAMESPACE(HeapInspectorServer)
enum EWaitForConnection
{
WaitForConnection_Disabled,
WaitForConnection_Enabled
};
std::vector<HeapInfo> GetDefaultHeapInfo();
bool Initialise(const std::vector<HeapInfo>& a_HeapInfo, int a_Port, EWaitForConnection a_WaitForConnection);
bool IsInitialised();
void Shutdown();
typedef int Mutation;
Mutation BeginAlloc();
void EndAlloc(Mutation a_Mutation, uint16 a_HeapID, void* a_Address, uint32 a_SizeRequested, uint32 a_SizeReceived);
Mutation BeginReAlloc();
void EndReAlloc(Mutation a_Mutation, uint16 a_HeapID, void* a_OldAddress, void* a_NewAddress, uint32 a_SizeRequested, uint32 a_SizeReceived);
Mutation BeginFree();
void EndFree(Mutation a_Mutation, uint16 a_HeapID, void* a_Address);
END_NAMESPACE(HeapInspectorServer)
#endif // _HEAPINSPECTORSERVER_PLATFORMINTERFACES_HEAPINSPECTORSERVER_H_
@@ -0,0 +1,32 @@
#ifndef _HEAPINSPECTORSERVER_TYPES_H_
#define _HEAPINSPECTORSERVER_TYPES_H_
#define BEGIN_NAMESPACE(x) namespace x {
#define END_NAMESPACE(x) }
#define BEGIN_UNNAMED_NAMESPACE() namespace {
#define END_UNNAMED_NAMESPACE() }
BEGIN_NAMESPACE(HeapInspectorServer)
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
#if HEAPINSPECTOR_PS3
typedef unsigned long long uint64;
typedef long long int64;
#else
typedef unsigned __int64 uint64;
typedef __int64 int64;
#endif
typedef char int8;
typedef short int16;
typedef int int32;
typedef char char8;
typedef wchar_t char16;
END_NAMESPACE(HeapInspectorServer)
#endif //_HEAPINSPECTORSERVER_TYPES_H_
@@ -0,0 +1,63 @@
#ifndef _HEAPINSPECTORSERVER_PS3_HEAPHOOKS_HPP_
#define _HEAPINSPECTORSERVER_PS3_HEAPHOOKS_HPP_
#include <stdlib.h>
extern "C" void* __real_memalign(size_t a_Boundary, size_t a_Size);
extern "C" void* __wrap_memalign(size_t a_Boundary, size_t a_Size)
{
HeapInspectorServer::Mutation mutation = HeapInspectorServer::BeginAlloc();
void* result = __real_memalign(a_Boundary, a_Size);
size_t usableSize = malloc_usable_size(result);
HeapInspectorServer::EndAlloc(mutation, 0, result, a_Size, usableSize);
return result;
}
extern "C" void* __real_calloc(size_t a_NumElements, size_t a_SizePerElement);
extern "C" void* __wrap_calloc(size_t a_NumElements, size_t a_SizePerElement)
{
HeapInspectorServer::Mutation mutation = HeapInspectorServer::BeginAlloc();
void* result = __real_calloc(a_NumElements, a_SizePerElement);
size_t usableSize = malloc_usable_size(result);
HeapInspectorServer::EndAlloc(mutation, 0, result, a_NumElements * a_SizePerElement, usableSize);
return result;
}
extern "C" void* __real_malloc(size_t a_Size);
extern "C" void* __wrap_malloc(size_t a_Size)
{
HeapInspectorServer::Mutation mutation = HeapInspectorServer::BeginAlloc();
void* result = __real_malloc(a_Size);
size_t usableSize = malloc_usable_size(result);
HeapInspectorServer::EndAlloc(mutation, 0, result, a_Size, usableSize);
return result;
}
extern "C" void __real_free(void* a_Address);
extern "C" void __wrap_free(void* a_Address)
{
HeapInspectorServer::Mutation mutation = HeapInspectorServer::BeginFree();
__real_free(a_Address);
HeapInspectorServer::EndFree(mutation, 0, a_Address);
}
extern "C" void *__real_realloc(void *a_Address, size_t a_Size);
extern "C" void *__wrap_realloc(void *a_Address, size_t a_Size)
{
HeapInspectorServer::Mutation mutation = HeapInspectorServer::BeginReAlloc();
void* result = __real_realloc(a_Address, a_Size);
size_t usableSize = malloc_usable_size(result);
HeapInspectorServer::EndReAlloc(mutation, 0, a_Address, result, a_Size, usableSize);
return result;
}
extern "C" void* __real_reallocalign(void *a_Address, size_t a_Size, size_t a_Boundary);
extern "C" void* __wrap_reallocalign(void *a_Address, size_t a_Size, size_t a_Boundary)
{
HeapInspectorServer::Mutation mutation = HeapInspectorServer::BeginReAlloc();
void* result = __real_reallocalign(a_Address, a_Size, a_Boundary);
size_t usableSize = malloc_usable_size(result);
HeapInspectorServer::EndReAlloc(mutation, 0, a_Address, result, a_Size, usableSize);
return result;
}
#endif //_HEAPINSPECTORSERVER_PS3_HEAPHOOKS_HPP_
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include <vectormath/cpp/vectormath_aos.h>
using namespace Vectormath::Aos;
typedef Vector4 XMVECTOR;
typedef Matrix4 XMMATRIX;
typedef Vector4 XMFLOAT4;
XMMATRIX XMMatrixMultiply(XMMATRIX a, XMMATRIX b);
XMVECTOR XMMatrixDeterminant(XMMATRIX a);
XMMATRIX XMMatrixInverse(Vector4 *a, XMMATRIX b);
@@ -0,0 +1,31 @@
#include "stdafx.h"
#include "PS3Strings.h"
uint8_t *mallocAndCreateUTF8ArrayFromString(int iID)
{
int result;
l10n_conv_t cd;
LPCWSTR wchString=app.GetString(iID);
size_t src_len,dst_len;
int iLen=wcslen(wchString);
src_len=sizeof(WCHAR)*(iLen);
if( (cd = l10n_get_converter( L10N_UTF16, L10N_UTF8 )) == -1 )
{
app.DebugPrintf("l10n_get_converter: no such converter\n");
return NULL;
}
l10n_convert_str( cd, wchString, &src_len, NULL, &dst_len );
uint8_t *strUtf8=(uint8_t *)malloc(dst_len);
memset(strUtf8,0,dst_len);
result = l10n_convert_str( cd, wchString, &src_len, strUtf8, &dst_len );
if( result != ConversionOK )
{
app.DebugPrintf("l10n_convert: conversion error : 0x%x\n", result);
return NULL;
}
return strUtf8;
}
@@ -0,0 +1,3 @@
#pragma once
uint8_t *mallocAndCreateUTF8ArrayFromString(int iID);
+788
View File
@@ -0,0 +1,788 @@
#ifdef __PS3__
#include "stdafx.h"
#include <libsn.h>
#include <cell/cell_fs.h>
#include <sys/vm.h>
#include <sys/memory.h>
#undef __in
#undef __out
#include <cell/atomic.h>
#include <sysutil/sysutil_gamecontent.h>
#include <np.h>
#include <np/drm.h>
#include <sysutil/sysutil_common.h>
#include <sysutil/sysutil_sysparam.h>
#include "ShutdownManager.h"
static char dirName[CELL_GAME_PATH_MAX];
static char contentInfoPath[CELL_GAME_PATH_MAX];
static char usrdirPath[CELL_GAME_PATH_MAX];
static char contentInfoPathBDPatch[CELL_GAME_PATH_MAX];
static char usrdirPathBDPatch[CELL_GAME_PATH_MAX];
//static char sc_loadPath[] = {"/app_home/"};
//static char sc_loadPath[CELL_GAME_PATH_MAX];
static int iFilesOpen=0;
vector<int> vOpenFileHandles;
namespace boost
{
void assertion_failed(char const * expr,
char const * function, char const * file, long line)
{
#ifndef _CONTENT_PACKAGE
printf("Assert failed!!!\n");
printf(expr);
printf("\n");
printf("----------------------\n %s failed. File %s at line %d \n----------------------\n", function, file, line);
snPause();
#endif
} // user defined
} // namespace boost
char* getConsoleHomePath()
{
return contentInfoPath;
}
char* getUsrDirPath()
{
return usrdirPath;
}
char* getConsoleHomePathBDPatch()
{
return contentInfoPathBDPatch;
}
char* getUsrDirPathBDPatch()
{
return usrdirPathBDPatch;
}
char* getDirName()
{
return dirName;
}
int _wcsicmp( const wchar_t * dst, const wchar_t * src )
{
wchar_t f,l;
// validation section
// _VALIDATE_RETURN(dst != NULL, EINVAL, _NLSCMPERROR);
// _VALIDATE_RETURN(src != NULL, EINVAL, _NLSCMPERROR);
do {
f = towlower(*dst);
l = towlower(*src);
dst++;
src++;
} while ( (f) && (f == l) );
return (int)(f - l);
}
size_t wcsnlen(const wchar_t *wcs, size_t maxsize)
{
size_t n;
// Note that we do not check if s == NULL, because we do not
// return errno_t...
for (n = 0; n < maxsize && *wcs; n++, wcs++)
;
return n;
}
Cnullptr nullptr;
VOID GetSystemTime( LPSYSTEMTIME lpSystemTime)
{
CellRtcDateTime dateTime;
int err = cellRtcGetCurrentClock(&dateTime, 0);
assert(err == CELL_OK);
lpSystemTime->wYear = cellRtcGetYear(&dateTime);
lpSystemTime->wMonth = cellRtcGetMonth(&dateTime);
lpSystemTime->wDay = cellRtcGetDay(&dateTime);
lpSystemTime->wDayOfWeek = cellRtcGetDayOfWeek(lpSystemTime->wYear, lpSystemTime->wMonth, lpSystemTime->wDay);
lpSystemTime->wHour = cellRtcGetHour(&dateTime);
lpSystemTime->wMinute = cellRtcGetMinute(&dateTime);
lpSystemTime->wSecond = cellRtcGetSecond(&dateTime);
lpSystemTime->wMilliseconds = cellRtcGetMicrosecond(&dateTime)/1000;
}
BOOL FileTimeToSystemTime(CONST FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime) { PS3_STUBBED; return false; }
BOOL SystemTimeToFileTime(CONST SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime) { PS3_STUBBED; return false; }
VOID GetLocalTime(LPSYSTEMTIME lpSystemTime)
{
CellRtcDateTime dateTime;
int err = cellRtcGetCurrentClockLocalTime(&dateTime);
assert(err == CELL_OK);
lpSystemTime->wYear = cellRtcGetYear(&dateTime);
lpSystemTime->wMonth = cellRtcGetMonth(&dateTime);
lpSystemTime->wDay = cellRtcGetDay(&dateTime);
lpSystemTime->wDayOfWeek = cellRtcGetDayOfWeek(lpSystemTime->wYear, lpSystemTime->wMonth, lpSystemTime->wDay);
lpSystemTime->wHour = cellRtcGetHour(&dateTime);
lpSystemTime->wMinute = cellRtcGetMinute(&dateTime);
lpSystemTime->wSecond = cellRtcGetSecond(&dateTime);
lpSystemTime->wMilliseconds = cellRtcGetMicrosecond(&dateTime)/1000;
}
HANDLE CreateEvent(void* lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName) { PS3_STUBBED; return NULL; }
VOID Sleep(DWORD dwMilliseconds)
{
C4JThread::Sleep(dwMilliseconds);
}
BOOL SetThreadPriority(HANDLE hThread, int nPriority) { PS3_STUBBED; return FALSE; }
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) { PS3_STUBBED; return false; }
LONG InterlockedCompareExchangeRelease(LONG volatile *Destination, LONG Exchange,LONG Comperand )
{
return cellAtomicCompareAndSwap32((uint32_t*)Destination, (uint32_t)Comperand, (uint32_t)Exchange);
}
LONG64 InterlockedCompareExchangeRelease64(LONG64 volatile *Destination, LONG64 Exchange, LONG64 Comperand)
{
return cellAtomicCompareAndSwap64((uint64_t*)Destination, (uint64_t)Comperand, (uint64_t)Exchange);
}
VOID InitializeCriticalSection(PCRITICAL_SECTION CriticalSection)
{
sys_lwmutex_attribute_t attr;
// from the defaults in sys_lwmutex_attribute_initialize
attr.attr_protocol = SYS_SYNC_PRIORITY;
attr.attr_recursive = SYS_SYNC_RECURSIVE;
attr.name[0] = '\0';
int err = sys_lwmutex_create(CriticalSection, &attr);
PS3_ASSERT_CELL_ERROR(err);
}
VOID InitializeCriticalSectionAndSpinCount(PCRITICAL_SECTION CriticalSection, ULONG SpinCount)
{
// no spin count on PS3
InitializeCriticalSection(CriticalSection);
}
VOID DeleteCriticalSection(PCRITICAL_SECTION CriticalSection)
{
int err = sys_lwmutex_destroy(CriticalSection);
PS3_ASSERT_CELL_ERROR(err);
}
extern CRITICAL_SECTION g_singleThreadCS;
VOID EnterCriticalSection(PCRITICAL_SECTION CriticalSection)
{
// if(CriticalSection != &g_singleThreadCS &&(C4JThread::isMainThread() == false) )
// LeaveCriticalSection(&g_singleThreadCS);
int err = sys_lwmutex_lock(CriticalSection, 0); // timeout, in microsecs - 0 here
PS3_ASSERT_CELL_ERROR(err);
// if(CriticalSection != &g_singleThreadCS && !C4JThread::isMainThread())
// EnterCriticalSection(&g_singleThreadCS);
}
VOID LeaveCriticalSection(PCRITICAL_SECTION CriticalSection)
{
int err = sys_lwmutex_unlock(CriticalSection);
PS3_ASSERT_CELL_ERROR(err);
}
ULONG TryEnterCriticalSection(PCRITICAL_SECTION CriticalSection)
{
int err = sys_lwmutex_trylock(CriticalSection);
if(err == CELL_OK)
return true;
return false;
}
DWORD WaitForMultipleObjects(DWORD nCount, CONST HANDLE *lpHandles,BOOL bWaitAll,DWORD dwMilliseconds) { PS3_STUBBED; return 0; }
BOOL CloseHandle(HANDLE hObject)
{
if(hObject==INVALID_HANDLE_VALUE)
{
//printf("\n\nTRYING TO CLOSE AN INVALID FILE HANDLE\n\n");
return false;
}
else
{
CellFsErrno err;
err=cellFsClose(int(hObject));
if(err==CELL_FS_SUCCEEDED)
{
iFilesOpen--;
AUTO_VAR(itEnd, vOpenFileHandles.end());
for (AUTO_VAR(it, vOpenFileHandles.begin()); it != itEnd; it++)
{
int iFH=(int)*it;
if(iFH==(int)hObject)
{
vOpenFileHandles.erase(it);
break;
}
}
//printf("\n\nFiles Open - %d\n\n",iFilesOpen);
return true;
}
else
{
return false;
}
}
}
BOOL SetEvent(HANDLE hEvent) { PS3_STUBBED; return false; }
HMODULE GetModuleHandle(LPCSTR lpModuleName) { PS3_STUBBED; return 0; }
sys_ppu_thread_t GetCurrentThreadId(VOID)
{
sys_ppu_thread_t id;
int err = sys_ppu_thread_get_id(&id);
PS3_ASSERT_CELL_ERROR(err);
return id;
}
DWORD WaitForMultipleObjectsEx(DWORD nCount,CONST HANDLE *lpHandles,BOOL bWaitAll,DWORD dwMilliseconds,BOOL bAlertable ) { PS3_STUBBED; return 0; }
BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode) { PS3_STUBBED; return FALSE; }
DWORD TlsAlloc(VOID) { return TLSStoragePS3::Instance()->Alloc(); }
BOOL TlsFree(DWORD dwTlsIndex) { return TLSStoragePS3::Instance()->Free(dwTlsIndex); }
LPVOID TlsGetValue(DWORD dwTlsIndex) { return TLSStoragePS3::Instance()->GetValue(dwTlsIndex); }
BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) { return TLSStoragePS3::Instance()->SetValue(dwTlsIndex, lpTlsValue); }
LPVOID VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect)
{
int err;
sys_addr_t newAddress = NULL;
if(lpAddress == NULL)
{
// reserve, and possibly commit also
int commitSize = 0;
if(flAllocationType == MEM_RESERVE)
commitSize = 1024*1024; // has to be a min of 1mb
else if(flAllocationType == MEM_COMMIT)
commitSize = dwSize;
else
{
PS3_ASSERT(0);
}
err = sys_vm_memory_map(dwSize, commitSize, SYS_MEMORY_CONTAINER_ID_INVALID,
SYS_MEMORY_PAGE_SIZE_64K, SYS_VM_POLICY_AUTO_RECOMMENDED, &newAddress);
PS3_ASSERT(err == CELL_OK);
}
else
{
// reserved already, so just commit
sys_vm_statistics_t stat;
err = sys_vm_get_statistics((sys_addr_t)lpAddress, &stat);
PS3_ASSERT(err == CELL_OK);
int memToAdd = dwSize - stat.pmem_total;
err = sys_vm_append_memory((sys_addr_t)lpAddress, memToAdd);
PS3_ASSERT(err == CELL_OK);
newAddress = (sys_addr_t)lpAddress;
}
return (LPVOID)newAddress;
}
BOOL VirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType)
{
if(dwFreeType == MEM_DECOMMIT)
{
int err;
sys_vm_statistics_t stat;
err = sys_vm_get_statistics((sys_addr_t)lpAddress, &stat);
PS3_ASSERT(err == CELL_OK);
// 4J Stu - We can only return what we have actually committed on PS3
// From PS3 Docs:
// The maximum amount of memory that can be returned is the difference of the total amount of physical memory used by the virtual memory area minus 1MB. When an amount exceeding this value is specified, EBUSY will return.
SIZE_T memToFree = stat.pmem_total - (1024 * 1024);
if(dwSize < memToFree)
memToFree = dwSize;
app.DebugPrintf("VirtualFree: Requested size - %d, Actual size - %d\n", dwSize, memToFree);
err = sys_vm_return_memory((sys_addr_t)lpAddress, memToFree);
PS3_ASSERT_CELL_ERROR(err);
return FALSE;
}
else
{
assert(dwFreeType == MEM_RELEASE);
assert(0); // not implemented yet
}
return TRUE;
}
DWORD GetFileSize( HANDLE hFile, LPDWORD lpFileSizeHigh )
{
// check if the file exists first
//printf("GetFileSize\n");
CellFsStat statData;
if(cellFsFstat((int)hFile, &statData) != CELL_FS_SUCCEEDED)
return 0;
if(statData.st_mode == CELL_FS_S_IFDIR)
return 0;
//printf("+++GetFileSize - %ll\n",statData.st_size);
return statData.st_size;
}
BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize ) { PS3_STUBBED; return false; }
BOOL WriteFile( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped )
{
int fd = (int)hFile;
uint64_t bytesWritten;
CellFsErrno err = cellFsWrite(fd, lpBuffer, nNumberOfBytesToWrite, &bytesWritten);
*lpNumberOfBytesWritten = (DWORD)bytesWritten;
return (err == CELL_FS_OK);
}
BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped )
{
int fd = (int)hFile;
uint64_t bytesRead;
CellFsErrno err = cellFsRead(fd, lpBuffer, nNumberOfBytesToRead, &bytesRead);
*lpNumberOfBytesRead = (DWORD)bytesRead;
// fake a read error due to disc eject
//err=CELL_FS_EBADF;
switch(err)
{
case CELL_FS_EBADF: // disc eject
CloseHandle((HANDLE)fd);
// sys message will come in and flag to start a shutdown
//ShutdownManager::StartShutdown();
break;
default:
break;
}
return (err==CELL_FS_SUCCEEDED);
}
BOOL SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
{
int fd = (int) hFile;
uint64_t pos = 0, bitsToMove = (int64_t) lDistanceToMove;
if (lpDistanceToMoveHigh != NULL)
bitsToMove |= ((uint64_t) (*lpDistanceToMoveHigh)) << 32;
int whence = 0;
switch(dwMoveMethod)
{
case FILE_BEGIN: whence = CELL_FS_SEEK_SET; break;
case FILE_CURRENT: whence = CELL_FS_SEEK_CUR; break;
case FILE_END: whence = CELL_FS_SEEK_END; break;
};
CellFsErrno err = cellFsLseek(fd, (int64_t) lDistanceToMove, whence, &pos);
return (err == CELL_FS_SUCCEEDED);
}
void replaceBackslashes(char* szFilename)
{
int len = strlen(szFilename);
for(int i=0;i<len;i++)
{
if(szFilename[i] == '\\')
szFilename[i] = '/';
}
}
HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
char filePath[256];
std::string mountedPath;
// 4J-PB - If we are running from the blu ray patch , then we need to check if we should load a file from the blu ray or the patch dir
if(app.GetBootedFromDiscPatch() && app.IsFileInPatchList(lpFileName))
{
// does this file need to be loaded from the patch directory?
#ifndef _CONTENT_PACKAGE
printf("*** Found a patched file %s\n",lpFileName);
#endif
char *pchPatchPath = app.GetDiscPatchUsrDir();
if(lpFileName[0] == '/') // already fully qualified path
strcpy(filePath, lpFileName );
else
sprintf(filePath,"%s/%s",pchPatchPath, lpFileName );
}
else
{
mountedPath = StorageManager.GetMountedPath(lpFileName);
if(mountedPath.length() > 0)
{
strcpy(filePath, mountedPath.c_str());
}
else if(lpFileName[0] == '/') // already fully qualified path
strcpy(filePath, lpFileName );
else
sprintf(filePath,"%s/%s",usrdirPath, lpFileName ); // set to load from host
}
replaceBackslashes(filePath);
int fd = 0;
int flags = 0;
switch(dwDesiredAccess)
{
case GENERIC_READ:
flags = CELL_FS_O_RDONLY; break;
case GENERIC_WRITE:
flags = CELL_FS_O_WRONLY; break;
default:
flags = CELL_FS_O_RDWR; break;
}
switch(dwCreationDisposition)
{
case CREATE_ALWAYS:
flags |= CELL_FS_O_CREAT; break;
case CREATE_NEW:
flags |= CELL_FS_O_EXCL; break;
case OPEN_ALWAYS:
flags |= CELL_FS_O_CREAT; break;
case OPEN_EXISTING:
break;
case TRUNCATE_EXISTING:
break;
}
CellFsErrno err;
#ifndef _CONTENT_PACKAGE
printf("*** Opening %s\n",filePath);
#endif
// check if it's a DRM edat file
int filePathLen = strlen(filePath);
if( (filePath[filePathLen-5] == '.' || filePath[filePathLen-4] == '.') &&
(filePath[filePathLen-4] == 'e' || filePath[filePathLen-4] == 'E') &&
(filePath[filePathLen-3] == 'd' || filePath[filePathLen-3] == 'D') &&
(filePath[filePathLen-2] == 'a' || filePath[filePathLen-2] == 'A') &&
(filePath[filePathLen-1] == 't' || filePath[filePathLen-1] == 'T') )
{
SceNpDrmOpenArg arg;
arg.flag = SCE_NP_DRM_OPEN_FLAG;
err = cellFsOpen(filePath, flags, &fd, &arg, sizeof(arg));
iFilesOpen++;
//printf("\n\nNPDRM Files Open - %d\n\n",iFilesOpen);
}
else
{
err = cellFsOpen(filePath, flags, &fd ,NULL, 0);
iFilesOpen++;
//printf("\n\nFiles Open - %d\n\n",iFilesOpen);
}
//PS3_ASSERT(err == CELL_FS_OK);
CellFsStat statData;
err = cellFsFstat(fd,&statData);
// fake a disc eject
//err=CELL_FS_EBADF;
#ifndef _CONTENT_PACKAGE
printf("*** Open error %d\n",err);
#endif
switch(err)
{
case CELL_FS_SUCCEEDED:
{
app.DebugPrintf("CELL_FS_SUCCEEDED\n");
DWORD dwFileSize = (DWORD)statData.st_size;
app.DebugPrintf("Filesize is %d\n", dwFileSize);
// 4J-PB - push the file handle on to a vector
vOpenFileHandles.push_back(fd);
}
break;
case CELL_FS_EBADF:
// fd is invalid or the file system on a removable media has been unmounted
// When cellFsFstat() returns CELL_FS_EBADF, it can be deduced that the above error occurred because a disc was ejected.
// Explicitly call cellFsClose() and close the applicable file. When using stream supporting APIs, call cellFsStReadFinish() before calling cellFsClose().
app.DebugPrintf("CELL_FS_EBADF\n");
CloseHandle((HANDLE)fd);
// sys message will come in to start shutdown
//ShutdownManager::StartShutdown();
return INVALID_HANDLE_VALUE;
case CELL_FS_EIO:
app.DebugPrintf("CELL_FS_EIO\n");
break;
case CELL_FS_ENOMEM:
app.DebugPrintf("CELL_FS_ENOMEM\n");
break;
case CELL_FS_EFSSPECIFIC:
app.DebugPrintf("CELL_FS_EFSSPECIFIC\n");
break;
case CELL_FS_EFAULT:
app.DebugPrintf("CELL_FS_EFAULT\n");
break;
}
return (void*)fd;
}
BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
char filePath[256];
sprintf(filePath,"%s/%s",usrdirPath, lpPathName );
CellFsErrno err = cellFsMkdir(filePath, CELL_FS_DEFAULT_CREATE_MODE_1);
if(err == CELL_FS_SUCCEEDED)
return true;
//printf("cellFsMkdir failed with error 0x%08x\n", err);
return false;
}
BOOL DeleteFileA(LPCSTR lpFileName) { PS3_STUBBED; return false; }
// BOOL XCloseHandle(HANDLE a)
// {
// cellFsClose(int(a));
// }
DWORD GetFileAttributesA(LPCSTR lpFileName)
{
char filePath[256];
std::string mountedPath = StorageManager.GetMountedPath(lpFileName);
if(mountedPath.length() > 0)
{
strcpy(filePath, mountedPath.c_str());
}
else if(lpFileName[0] == '/') // already fully qualified path
strcpy(filePath, lpFileName );
else
sprintf(filePath,"%s/%s",usrdirPath, lpFileName ); // set to load from host
//strcat(filePath,".edat");
//printf("GetFileAttributesA - %s\n",filePath);
// check if the file exists first
CellFsStat statData;
if(cellFsStat(filePath, &statData) != CELL_FS_SUCCEEDED)
{
//printf("GetFileAttributesA FAIL\n");
return -1;
}
if( statData.st_mode & CELL_FS_S_IFDIR )
return FILE_ATTRIBUTE_DIRECTORY;
else
return FILE_ATTRIBUTE_NORMAL;
}
BOOL MoveFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName) { PS3_STUBBED; return false; }
void __debugbreak() { snPause(); }
VOID DebugBreak(VOID) { snPause(); }
DWORD GetLastError(VOID) { PS3_STUBBED; return 0; }
VOID GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
{
malloc_managed_size stat;
int err = malloc_stats(&stat);
if(err != 0)
{
//printf("Failed to get mem stats\n");
}
lpBuffer->dwTotalPhys = stat.max_system_size;
lpBuffer->dwAvailPhys = stat.max_system_size - stat.current_system_size;
lpBuffer->dwAvailVirtual = stat.max_system_size - stat.current_inuse_size;
}
DWORD GetTickCount()
{
// This function returns the current system time at this function is called.
// The system time is represented the time elapsed since the system starts up in microseconds.
system_time_t sysTime = sys_time_get_system_time();
return sysTime / 1000;
}
// we should really use libperf for this kind of thing, but this will do for now.
BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency)
{
// microseconds
lpFrequency->QuadPart = (1000 * 1000);
return false;
}
BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount)
{
sys_time_sec_t sec;
sys_time_nsec_t nsec;
sys_time_get_current_time(&sec, &nsec);
// microseconds
lpPerformanceCount->QuadPart = (sec * (1000 * 1000)) + (nsec / 1000);
return true;
}
#ifndef _FINAL_BUILD
VOID OutputDebugStringW(LPCWSTR lpOutputString)
{
wprintf(lpOutputString);
}
VOID OutputDebugString(LPCSTR lpOutputString)
{
printf(lpOutputString);
}
VOID OutputDebugStringA(LPCSTR lpOutputString)
{
printf(lpOutputString);
}
#endif // _CONTENT_PACKAGE
BOOL GetFileAttributesExA(LPCSTR lpFileName,GET_FILEEX_INFO_LEVELS fInfoLevelId,LPVOID lpFileInformation)
{
PS3_STUBBED;
return false;
}
HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData) { PS3_STUBBED; return 0;}
BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData) { PS3_STUBBED; return false;}
errno_t _itoa_s(int _Value, char * _DstBuf, size_t _Size, int _Radix) { if(_Radix==10) sprintf(_DstBuf,"%d",_Value); else if(_Radix==16) sprintf(_DstBuf,"%lx",_Value); else return -1; return 0; }
errno_t _i64toa_s(__int64 _Val, char * _DstBuf, size_t _Size, int _Radix) { if(_Radix==10) sprintf(_DstBuf,"%lld",_Val); else return -1; return 0; }
int _wtoi(const wchar_t *_Str)
{
return wcstol(_Str, NULL, 10);
}
DWORD XGetLanguage()
{
unsigned char ucLang = app.GetMinecraftLanguage(0);
int iLang;
// check if we should override the system language or not
if(ucLang==MINECRAFT_LANGUAGE_DEFAULT)
{
cellSysutilGetSystemParamInt(CELL_SYSUTIL_SYSTEMPARAM_ID_LANG,&iLang);
}
else
{
return (DWORD)ucLang;
}
switch(iLang)
{
case CELL_SYSUTIL_LANG_JAPANESE : return XC_LANGUAGE_JAPANESE;
case CELL_SYSUTIL_LANG_ENGLISH_US : return XC_LANGUAGE_ENGLISH;
case CELL_SYSUTIL_LANG_FRENCH : return XC_LANGUAGE_FRENCH;
case CELL_SYSUTIL_LANG_SPANISH :
if(app.IsAmericanSKU())
{
return XC_LANGUAGE_LATINAMERICANSPANISH;
}
else
{
return XC_LANGUAGE_SPANISH;
}
case CELL_SYSUTIL_LANG_GERMAN : return XC_LANGUAGE_GERMAN;
case CELL_SYSUTIL_LANG_ITALIAN : return XC_LANGUAGE_ITALIAN;
case CELL_SYSUTIL_LANG_PORTUGUESE_PT : return XC_LANGUAGE_PORTUGUESE;
case CELL_SYSUTIL_LANG_RUSSIAN : return XC_LANGUAGE_RUSSIAN;
case CELL_SYSUTIL_LANG_KOREAN : return XC_LANGUAGE_KOREAN;
case CELL_SYSUTIL_LANG_CHINESE_T : return XC_LANGUAGE_TCHINESE;
case CELL_SYSUTIL_LANG_PORTUGUESE_BR : return XC_LANGUAGE_PORTUGUESE;
case CELL_SYSUTIL_LANG_ENGLISH_GB : return XC_LANGUAGE_ENGLISH;
case CELL_SYSUTIL_LANG_DUTCH : return XC_LANGUAGE_DUTCH;
case CELL_SYSUTIL_LANG_FINNISH : return XC_LANGUAGE_FINISH;
case CELL_SYSUTIL_LANG_SWEDISH : return XC_LANGUAGE_SWEDISH;
case CELL_SYSUTIL_LANG_DANISH : return XC_LANGUAGE_DANISH;
case CELL_SYSUTIL_LANG_NORWEGIAN : return XC_LANGUAGE_BNORWEGIAN;
case CELL_SYSUTIL_LANG_POLISH : return XC_LANGUAGE_POLISH;
case CELL_SYSUTIL_LANG_TURKISH : return XC_LANGUAGE_TURKISH;
case CELL_SYSUTIL_LANG_CHINESE_S : return XC_LANGUAGE_SCHINESE;
default : return XC_LANGUAGE_ENGLISH;
}
}
DWORD XGetLocale()
{
int iLang;
cellSysutilGetSystemParamInt(CELL_SYSUTIL_SYSTEMPARAM_ID_LANG,&iLang);
switch(iLang)
{
case CELL_SYSUTIL_LANG_JAPANESE : return XC_LOCALE_JAPAN;
case CELL_SYSUTIL_LANG_ENGLISH_US : return XC_LOCALE_UNITED_STATES;
case CELL_SYSUTIL_LANG_FRENCH : return XC_LOCALE_FRANCE;
case CELL_SYSUTIL_LANG_SPANISH :
if(app.IsAmericanSKU())
{
return XC_LOCALE_LATIN_AMERICA;
}
else
{
return XC_LOCALE_SPAIN;
}
return XC_LOCALE_SPAIN;
case CELL_SYSUTIL_LANG_GERMAN : return XC_LOCALE_GERMANY;
case CELL_SYSUTIL_LANG_ITALIAN : return XC_LOCALE_ITALY;
case CELL_SYSUTIL_LANG_PORTUGUESE_PT : return XC_LOCALE_PORTUGAL;
case CELL_SYSUTIL_LANG_RUSSIAN : return XC_LOCALE_RUSSIAN_FEDERATION;
case CELL_SYSUTIL_LANG_KOREAN : return XC_LOCALE_KOREA;
case CELL_SYSUTIL_LANG_CHINESE_T : return XC_LOCALE_CHINA;
case CELL_SYSUTIL_LANG_PORTUGUESE_BR : return XC_LOCALE_BRAZIL;
case CELL_SYSUTIL_LANG_ENGLISH_GB : return XC_LOCALE_GREAT_BRITAIN;
case CELL_SYSUTIL_LANG_DUTCH : return XC_LOCALE_NETHERLANDS;
case CELL_SYSUTIL_LANG_FINNISH : return XC_LOCALE_FINLAND;
case CELL_SYSUTIL_LANG_SWEDISH : return XC_LOCALE_SWEDEN;
case CELL_SYSUTIL_LANG_DANISH : return XC_LOCALE_DENMARK;
case CELL_SYSUTIL_LANG_NORWEGIAN : return XC_LOCALE_NORWAY;
case CELL_SYSUTIL_LANG_POLISH : return XC_LOCALE_POLAND;
case CELL_SYSUTIL_LANG_TURKISH : return XC_LOCALE_TURKEY;
case CELL_SYSUTIL_LANG_CHINESE_S : return XC_LOCALE_CHINA;
default : return XC_LOCALE_UNITED_STATES;
}
}
DWORD XEnableGuestSignin(BOOL fEnable)
{
return 0;
}
#endif // __PS3__
+431
View File
@@ -0,0 +1,431 @@
#pragma once
#include "TLSStorage.h"
#include <sys/synchronization.h>
#include <sys/sys_time.h>
#include <sys/timer.h>
#include <sys/ppu_thread.h>
#include <libsn.h>
#ifndef _CONTENT_PACKAGE
#define DEBUG_PRINTF(fmt, arg...) printf(fmt, ## arg)
#else
#define DEBUG_PRINTF(fmt, arg...) (void)0
#endif
char* getConsoleHomePath();
char* getUsrDirPath();
char* getConsoleHomePathBDPatch();
char* getUsrDirPathBDPatch();
char* getDirName();
DWORD TlsAlloc(VOID);
LPVOID TlsGetValue(DWORD dwTlsIndex);
BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue);
typedef struct _RECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT;
typedef void ID3D11Device;
typedef void ID3D11DeviceContext;
typedef void IDXGISwapChain;
typedef RECT D3D11_RECT;
typedef void ID3D11Buffer;
typedef DWORD (*PTHREAD_START_ROUTINE)( LPVOID lpThreadParameter);
typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
typedef int errno_t;
// typedef struct _RTL_CRITICAL_SECTION {
// //
// // The following field is used for blocking when there is contention for
// // the resource
// //
//
// union {
// ULONG_PTR RawEvent[4];
// } Synchronization;
//
// //
// // The following three fields control entering and exiting the critical
// // section for the resource
// //
//
// LONG LockCount;
// LONG RecursionCount;
// HANDLE OwningThread;
// } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
typedef sys_lwmutex_t RTL_CRITICAL_SECTION;
typedef sys_lwmutex_t* PRTL_CRITICAL_SECTION;
typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;
typedef PRTL_CRITICAL_SECTION PCRITICAL_SECTION;
typedef PRTL_CRITICAL_SECTION LPCRITICAL_SECTION;
void EnterCriticalSection(CRITICAL_SECTION* _c);
void LeaveCriticalSection(CRITICAL_SECTION* _c);
void InitializeCriticalSection(CRITICAL_SECTION* _c);
void DeleteCriticalSection(CRITICAL_SECTION* _c);
HANDLE CreateEvent(void* lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName);
VOID Sleep(DWORD dwMilliseconds);
BOOL SetThreadPriority(HANDLE hThread, int nPriority);
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds);
LONG InterlockedCompareExchangeRelease(LONG volatile *Destination, LONG Exchange,LONG Comperand );
VOID InitializeCriticalSection(PCRITICAL_SECTION CriticalSection);
VOID InitializeCriticalSectionAndSpinCount(PCRITICAL_SECTION CriticalSection, ULONG SpinCount);
VOID DeleteCriticalSection(PCRITICAL_SECTION CriticalSection);
VOID EnterCriticalSection(PCRITICAL_SECTION CriticalSection);
VOID LeaveCriticalSection(PCRITICAL_SECTION CriticalSection);
ULONG TryEnterCriticalSection(PCRITICAL_SECTION CriticalSection);
DWORD WaitForMultipleObjects(DWORD nCount, CONST HANDLE *lpHandles,BOOL bWaitAll,DWORD dwMilliseconds);
LONG64 InterlockedCompareExchangeRelease64(LONG64 volatile *Destination, LONG64 Exchange, LONG64 Comperand);
BOOL CloseHandle(HANDLE hObject);
BOOL SetEvent(HANDLE hEvent);
HMODULE GetModuleHandle(LPCSTR lpModuleName);
HANDLE CreateThread( void* lpThreadAttributes, DWORD dwStackSize, void* lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId );
DWORD ResumeThread( HANDLE hThread );
sys_ppu_thread_t GetCurrentThreadId(VOID);
DWORD WaitForMultipleObjectsEx(DWORD nCount,CONST HANDLE *lpHandles,BOOL bWaitAll,DWORD dwMilliseconds,BOOL bAlertable );
BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode);
LPVOID VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
BOOL VirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType);
DWORD GetFileSize( HANDLE hFile, LPDWORD lpFileSizeHigh );
BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize );
BOOL WriteFile(
HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped );
BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped );
#define INVALID_SET_FILE_POINTER false
BOOL SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
#define CreateFile CreateFileA
BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
#define CreateDirectory CreateDirectoryA
BOOL DeleteFileA(LPCSTR lpFileName);
#define DeleteFile DeleteFileA
DWORD GetFileAttributesA(LPCSTR lpFileName);
#define GetFileAttributes GetFileAttributesA
BOOL MoveFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
#define MoveFile MoveFileA
#define MAX_PATH 260
void __debugbreak();
VOID DebugBreak(VOID);
enum D3D11_BLEND
{
D3D11_BLEND_ZERO = 1,
D3D11_BLEND_ONE = 2,
D3D11_BLEND_SRC_COLOR = 3,
D3D11_BLEND_INV_SRC_COLOR = 4,
D3D11_BLEND_SRC_ALPHA = 5,
D3D11_BLEND_INV_SRC_ALPHA = 6,
D3D11_BLEND_DEST_ALPHA = 7,
D3D11_BLEND_INV_DEST_ALPHA = 8,
D3D11_BLEND_DEST_COLOR = 9,
D3D11_BLEND_INV_DEST_COLOR = 10,
D3D11_BLEND_SRC_ALPHA_SAT = 11,
D3D11_BLEND_BLEND_FACTOR = 14,
D3D11_BLEND_INV_BLEND_FACTOR = 15,
D3D11_BLEND_SRC1_COLOR = 16,
D3D11_BLEND_INV_SRC1_COLOR = 17,
D3D11_BLEND_SRC1_ALPHA = 18,
D3D11_BLEND_INV_SRC1_ALPHA = 19
};
enum D3D11_COMPARISON_FUNC
{
D3D11_COMPARISON_NEVER = 1,
D3D11_COMPARISON_LESS = 2,
D3D11_COMPARISON_EQUAL = 3,
D3D11_COMPARISON_LESS_EQUAL = 4,
D3D11_COMPARISON_GREATER = 5,
D3D11_COMPARISON_NOT_EQUAL = 6,
D3D11_COMPARISON_GREATER_EQUAL = 7,
D3D11_COMPARISON_ALWAYS = 8
};
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
VOID GetSystemTime( LPSYSTEMTIME lpSystemTime);
BOOL FileTimeToSystemTime(CONST FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime);
BOOL SystemTimeToFileTime(CONST SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime);
VOID GetLocalTime(LPSYSTEMTIME lpSystemTime);
typedef struct _MEMORYSTATUS {
DWORD dwLength;
DWORD dwMemoryLoad;
SIZE_T dwTotalPhys;
SIZE_T dwAvailPhys;
SIZE_T dwTotalPageFile;
SIZE_T dwAvailPageFile;
SIZE_T dwTotalVirtual;
SIZE_T dwAvailVirtual;
} MEMORYSTATUS, *LPMEMORYSTATUS;
#define WINAPI
#define CREATE_SUSPENDED 0x00000004
#define THREAD_BASE_PRIORITY_LOWRT 15 // value that gets a thread to LowRealtime-1
#define THREAD_BASE_PRIORITY_MAX 2 // maximum thread base priority boost
#define THREAD_BASE_PRIORITY_MIN -2 // minimum thread base priority boost
#define THREAD_BASE_PRIORITY_IDLE -15 // value that gets a thread to idle
#define THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
#define THREAD_PRIORITY_BELOW_NORMAL (THREAD_PRIORITY_LOWEST+1)
#define THREAD_PRIORITY_NORMAL 0
#define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX
#define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST-1)
#define THREAD_PRIORITY_ERROR_RETURN (MAXLONG)
#define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT
#define THREAD_PRIORITY_IDLE THREAD_BASE_PRIORITY_IDLE
#define WAIT_TIMEOUT 258L
#define STATUS_ABANDONED_WAIT_0 ((DWORD )0x00000080L)
#define WAIT_ABANDONED ((STATUS_ABANDONED_WAIT_0 ) + 0 )
#define MAXUINT_PTR (~((UINT_PTR)0))
#define MAXINT_PTR ((INT_PTR)(MAXUINT_PTR >> 1))
#define MININT_PTR (~MAXINT_PTR)
#define MAXULONG_PTR (~((ULONG_PTR)0))
#define MAXLONG_PTR ((LONG_PTR)(MAXULONG_PTR >> 1))
#define MINLONG_PTR (~MAXLONG_PTR)
#define MAXUHALF_PTR ((UHALF_PTR)~0)
#define MAXHALF_PTR ((HALF_PTR)(MAXUHALF_PTR >> 1))
#define MINHALF_PTR (~MAXHALF_PTR)
#define INVALID_HANDLE_VALUE ((HANDLE)-1)
//
// Generic test for success on any status value (non-negative numbers
// indicate success).
//
#define HRESULT_SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
//
// and the inverse
//
// #define _HRESULT_TYPEDEF_(_sc) _sc
#define FAILED(Status) ((HRESULT)(Status)<0)
// #define MAKE_HRESULT(sev,fac,code) \
// ((HRESULT) (((unsigned int)(sev)<<31) | ((unsigned int)(fac)<<16) | ((unsigned int)(code))) )
// #define MAKE_SCODE(sev,fac,code) \
// ((SCODE) (((unsigned int)(sev)<<31) | ((unsigned int)(fac)<<16) | ((unsigned int)(code))) )
// #define E_FAIL _HRESULT_TYPEDEF_(0x80004005L)
// #define E_ABORT _HRESULT_TYPEDEF_(0x80004004L)
// #define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L)
#define GENERIC_READ (0x80000000L)
#define GENERIC_WRITE (0x40000000L)
#define GENERIC_EXECUTE (0x20000000L)
#define GENERIC_ALL (0x10000000L)
#define FILE_SHARE_READ 0x00000001
#define FILE_SHARE_WRITE 0x00000002
#define FILE_SHARE_DELETE 0x00000004
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_DEVICE 0x00000040
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_FLAG_WRITE_THROUGH 0x80000000
#define FILE_FLAG_OVERLAPPED 0x40000000
#define FILE_FLAG_NO_BUFFERING 0x20000000
#define FILE_FLAG_RANDOM_ACCESS 0x10000000
#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000
#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
#define FILE_BEGIN 0
#define FILE_CURRENT 1
#define FILE_END 2
#define CREATE_NEW 1
#define CREATE_ALWAYS 2
#define OPEN_EXISTING 3
#define OPEN_ALWAYS 4
#define TRUNCATE_EXISTING 5
#define PAGE_NOACCESS 0x01
#define PAGE_READONLY 0x02
#define PAGE_READWRITE 0x04
#define PAGE_WRITECOPY 0x08
#define PAGE_EXECUTE 0x10
#define PAGE_EXECUTE_READ 0x20
#define PAGE_EXECUTE_READWRITE 0x40
#define PAGE_EXECUTE_WRITECOPY 0x80
#define PAGE_GUARD 0x100
#define PAGE_NOCACHE 0x200
#define PAGE_WRITECOMBINE 0x400
#define PAGE_USER_READONLY 0x1000
#define PAGE_USER_READWRITE 0x2000
#define MEM_COMMIT 0x1000
#define MEM_RESERVE 0x2000
#define MEM_DECOMMIT 0x4000
#define MEM_RELEASE 0x8000
#define MEM_FREE 0x10000
#define MEM_PRIVATE 0x20000
#define MEM_RESET 0x80000
#define MEM_TOP_DOWN 0x100000
#define MEM_NOZERO 0x800000
#define MEM_LARGE_PAGES 0x20000000
#define MEM_HEAP 0x40000000
#define MEM_16MB_PAGES 0x80000000
#define IGNORE 0 // Ignore signal
#define INFINITE 0xFFFFFFFF // Infinite timeout
#define WAIT_FAILED ((DWORD)0xFFFFFFFF)
#define STATUS_WAIT_0 ((DWORD )0x00000000L)
#define WAIT_OBJECT_0 ((STATUS_WAIT_0 ) + 0 )
#define STATUS_PENDING ((DWORD )0x00000103L)
#define STILL_ACTIVE STATUS_PENDING
DWORD GetLastError(VOID);
VOID GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer);
DWORD GetTickCount();
BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency);
BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount);
#define ERROR_SUCCESS 0L
#define ERROR_IO_PENDING 997L // dderror
#define ERROR_CANCELLED 1223L
//#define S_OK ((HRESULT)0x00000000L)
#define S_FALSE ((HRESULT)0x00000001L)
#define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
#define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
#define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
#define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
#define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
#define MoveMemory RtlMoveMemory
#define CopyMemory RtlCopyMemory
#define FillMemory RtlFillMemory
#define ZeroMemory RtlZeroMemory
#define CDECL
#define APIENTRY
#define wsprintfW swprintf
#define wcsncpy_s wcsncpy
#define _wcstoui64 wcstoll
#define VK_ESCAPE 0x1B
#define VK_RETURN 0x0D
VOID OutputDebugStringW(LPCWSTR lpOutputString);
VOID OutputDebugString(LPCSTR lpOutputString);
VOID OutputDebugStringA(LPCSTR lpOutputString);
errno_t _itoa_s(int _Value, char * _DstBuf, size_t _Size, int _Radix);
errno_t _i64toa_s(__int64 _Val, char * _DstBuf, size_t _Size, int _Radix);
int _wtoi(const wchar_t *_Str);
#define __declspec(a)
extern "C" int _wcsicmp (const wchar_t * dst, const wchar_t * src);
size_t wcsnlen(const wchar_t *wcs, size_t maxsize);
typedef struct _WIN32_FIND_DATAA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
CHAR cFileName[ MAX_PATH ];
CHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
typedef WIN32_FIND_DATAA WIN32_FIND_DATA;
typedef PWIN32_FIND_DATAA PWIN32_FIND_DATA;
typedef LPWIN32_FIND_DATAA LPWIN32_FIND_DATA;
typedef struct _WIN32_FILE_ATTRIBUTE_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
} WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;
DWORD GetFileAttributesA(LPCSTR lpFileName);
#define GetFileAttributes GetFileAttributesA
typedef enum _GET_FILEEX_INFO_LEVELS {
GetFileExInfoStandard,
GetFileExMaxInfoLevel
} GET_FILEEX_INFO_LEVELS;
BOOL GetFileAttributesExA(LPCSTR lpFileName,GET_FILEEX_INFO_LEVELS fInfoLevelId,LPVOID lpFileInformation);
#define GetFileAttributesEx GetFileAttributesExA
BOOL DeleteFileA(LPCSTR lpFileName);
#define DeleteFile DeleteFileA
HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData);
#define FindFirstFile FindFirstFileA
BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData);
#define FindNextFile FindNextFileA
#define FindClose(hFindFile) CloseHandle(hFindFile)
DWORD XGetLanguage();
DWORD XGetLocale();
DWORD XEnableGuestSignin(BOOL fEnable);
#ifdef _CONTENT_PACKAGE
#define PS3_STUBBED { }
#else
#define PS3_STUBBED { static bool bSet = false; if(!bSet){printf("missing function on PS3 : %s\n Tell MarkH about this, then press f5 to continue.", __FUNCTION__); bSet = true; assert(0);} }
#endif
+257
View File
@@ -0,0 +1,257 @@
#pragma once
#define BOOST_NO_CXX11_NULLPTR
#define BOOST_ENABLE_ASSERT_HANDLER
#include <typeinfo>
#include <stddef.h>
#include <boost/typeof/typeof.hpp>
#include <boost/tr1/memory.hpp>
#include "boost/tr1/unordered_map.hpp"
#include "boost/tr1/unordered_set.hpp"
#include "boost/pool/pool_alloc.hpp"
#include <boost/mpl/equal_to.hpp>
#define __forceinline inline
//#include "winerror.h"
using std::tr1::bad_weak_ptr;
using std::tr1::const_pointer_cast;
using std::tr1::dynamic_pointer_cast;
using std::tr1::enable_shared_from_this;
using std::tr1::get_deleter;
using std::tr1::shared_ptr;
using std::tr1::static_pointer_cast;
using std::tr1::swap;
using std::tr1::weak_ptr;
using std::tr1::unordered_map;
using std::tr1::unordered_set;
using boost::hash;
// user the pool_allocator for all unordered_set and unordered_map instances
// template < class T, class H = hash<T>, class P = std::equal_to<T>, class A = boost::pool_allocator<T> >
// class unordered_set : public std::tr1::unordered_set<T, H, P, A >
// {};
//
// template <class K, class T, class H = hash<K>, class P = std::equal_to<K>, class A = boost::pool_allocator<std::pair<const K,T> > >
// class unordered_map : public std::tr1::unordered_map<K, T, H, P, A >
// {};
// template < class T, class H = hash<T>, class P = std::equal_to<T>, class A = C4JPoolAllocator<T> >
// class unordered_set : public std::tr1::unordered_set<T, H, P, A >
// {};
//
// template <class K, class T, class H = hash<K>, class P = std::equal_to<K>, class A = C4JPoolAllocator<std::pair<const K,T> > >
// class unordered_map : public std::tr1::unordered_map<K, T, H, P, A >
// {};
// using boost::ublas::vector;
#define static_assert(a,b) BOOST_STATIC_ASSERT(a)
#define AUTO_VAR BOOST_AUTO
class Cnullptr{
public:
template<typename T>
operator shared_ptr<T>() { return shared_ptr<T>(); }
};
extern Cnullptr nullptr;
// #include <math.h>
// #include "DirectX\DirectXMath.h"
// using namespace DirectX;
#define S_OK 0
typedef unsigned long DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef float FLOAT;
typedef int __int32;
typedef FLOAT *PFLOAT;
typedef BOOL *PBOOL;
typedef BOOL *LPBOOL;
typedef BYTE *PBYTE;
typedef BYTE *LPBYTE;
typedef int *PINT;
typedef int *LPINT;
typedef WORD *PWORD;
typedef WORD *LPWORD;
typedef long *PLONG;
typedef long *LPLONG;
typedef DWORD *PDWORD;
typedef DWORD *LPDWORD;
typedef void *LPVOID;
typedef const void *LPCVOID;
typedef void *PVOID;
typedef unsigned long ULONG;
typedef unsigned char boolean;
typedef int INT;
typedef unsigned int UINT;
typedef unsigned int *PUINT;
typedef unsigned char byte;
typedef long long __int64;
typedef unsigned long long __uint64;
typedef unsigned long DWORD;
typedef int INT;
typedef unsigned long ULONG_PTR, *PULONG_PTR;
typedef ULONG_PTR SIZE_T, *PSIZE_T;
typedef __int64 LONG64, *PLONG64;
#define VOID void
typedef char CHAR;
typedef short SHORT;
typedef long LONG;
typedef __int64 LONGLONG;
typedef __uint64 ULONGLONG;
#define CONST const
typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
typedef WCHAR *PWCHAR;
typedef WCHAR *LPWCH, *PWCH;
typedef CONST WCHAR *LPCWCH, *PCWCH;
typedef WCHAR *NWPSTR;
typedef WCHAR *LPWSTR, *PWSTR;
typedef CONST WCHAR *LPCWSTR, *PCWSTR;
//
// ANSI (Multi-byte Character) types
//
typedef CHAR *PCHAR;
typedef CHAR *LPCH, *PCH;
typedef CONST CHAR *LPCCH, *PCCH;
typedef CHAR *NPSTR;
typedef CHAR *LPSTR, *PSTR;
typedef CONST CHAR *LPCSTR, *PCSTR;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
typedef struct _FILETIME {
#ifdef _M_PPCBE
DWORD dwHighDateTime;
DWORD dwLowDateTime;
#else
DWORD dwLowDateTime;
DWORD dwHighDateTime;
#endif
} FILETIME, *PFILETIME, *LPFILETIME;
#if defined(MIDL_PASS)
typedef struct _LARGE_INTEGER {
#else // MIDL_PASS
typedef union _LARGE_INTEGER {
struct {
#if defined(_M_PPCBE)
LONG HighPart;
DWORD LowPart;
#else
DWORD LowPart;
LONG HighPart;
#endif
};
struct {
#if defined(_M_PPCBE)
LONG HighPart;
DWORD LowPart;
#else
DWORD LowPart;
LONG HighPart;
#endif
} u;
#endif //MIDL_PASS
LONGLONG QuadPart;
} LARGE_INTEGER;
typedef LARGE_INTEGER *PLARGE_INTEGER;
#if defined(MIDL_PASS)
typedef struct _ULARGE_INTEGER {
#else // MIDL_PASS
typedef union _ULARGE_INTEGER {
struct {
#if defined(_M_PPCBE)
DWORD HighPart;
DWORD LowPart;
#else
DWORD LowPart;
DWORD HighPart;
#endif
};
struct {
#if defined(_M_PPCBE)
DWORD HighPart;
DWORD LowPart;
#else
DWORD LowPart;
DWORD HighPart;
#endif
} u;
#endif //MIDL_PASS
ULONGLONG QuadPart;
} ULARGE_INTEGER;
typedef ULARGE_INTEGER *PULARGE_INTEGER;
// 360 specifics
typedef long HRESULT;
typedef void* HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
DECLARE_HANDLE(HINSTANCE);
typedef HINSTANCE HMODULE; /* HMODULEs can be used in place of HINSTANCEs */
typedef struct _OVERLAPPED {
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
DWORD Offset;
DWORD OffsetHigh;
HANDLE hEvent;
} OVERLAPPED, *LPOVERLAPPED;
typedef LPVOID PSECURITY_ATTRIBUTES;
typedef LPVOID LPSECURITY_ATTRIBUTES;
#define __in_ecount(a)
#define __in_bcount(a)
// const int XUSER_MAX_COUNT = 4;
@@ -0,0 +1,204 @@
#include "stdafx.h"
#include "ShutdownManager.h"
#include "..\..\Common\Leaderboards\LeaderboardManager.h"
#include "..\..\MinecraftServer.h"
#ifdef __PS3__
#include "C4JSpursJob.h"
bool ShutdownManager::s_threadShouldRun[ShutdownManager::eThreadIdCount];
int ShutdownManager::s_threadRunning[ShutdownManager::eThreadIdCount];
CRITICAL_SECTION ShutdownManager::s_threadRunningCS;
C4JThread::EventArray *ShutdownManager::s_eventArray[eThreadIdCount];
#endif
// Initialises the shutdown manager - this needs to be called as soon as the game is started so it can respond as quickly as possible to shut down requests
void ShutdownManager::Initialise()
{
#ifdef __PS3__
cellSysutilRegisterCallback( 1, SysUtilCallback, NULL );
for( int i = 0; i < eThreadIdCount; i++ )
{
s_threadShouldRun[i] = true;
s_threadRunning[i] = 0;
s_eventArray[i] = NULL;
}
// Special case for storage manager, which we will manually set now to be considered as running - this will be unset by StorageManager.ExitRequest if required
s_threadRunning[eStorageManagerThreads] = true;
InitializeCriticalSection(&s_threadRunningCS);
#endif
}
// Called in response to a system request to exit the game. This just requests that the main thread should stop, and then the main thread is responsible for calling MainThreadHandleShutdown which
// starts the rest of the shut down process, then waits until it is complete.
void ShutdownManager::StartShutdown()
{
#ifdef __PS3__
s_threadShouldRun[ eMainThread ] = false;
#endif
}
// This should be called from the main thread after it has been requested to shut down (ShouldRun for main thread returns false), and before it returns control to the kernel. This is responsible for
// signalling to all other threads to stop, and wait until their completion before returning.
void ShutdownManager::MainThreadHandleShutdown()
{
#ifdef __PS3__
// Set flags for each thread which will be reset when they are complete
s_threadRunning[ eMainThread ] = false;
// Second wave of things we would like to shut down (after main)
LeaderboardManager::Instance()->CancelOperation();
RequestThreadToStop( eLeaderboardThread );
RequestThreadToStop( eCommerceThread );
RequestThreadToStop( ePostProcessThread );
RequestThreadToStop( eRunUpdateThread );
RequestThreadToStop( eRenderChunkUpdateThread );
RequestThreadToStop( eConnectionReadThreads );
RequestThreadToStop( eConnectionWriteThreads );
RequestThreadToStop( eEventQueueThreads );
app.DebugPrintf("Shutdown manager: waiting on first batch of threads requested to terminate...\n");
WaitForSignalledToComplete();
app.DebugPrintf("Shutdown manager: terminated.\n");
// Now shut down the server thread
MinecraftServer::HaltServer();
RequestThreadToStop( eServerThread );
app.DebugPrintf("Shutdown manager: waiting on server to terminate...\n");
WaitForSignalledToComplete();
app.DebugPrintf("Shutdown manager: terminated.\n");
//And shut down the storage manager
RequestThreadToStop( eStorageManagerThreads );
StorageManager.ExitRequest(&StorageManagerCompleteFn);
app.DebugPrintf("Shutdown manager: waiting on storage manager to terminate...\n");
WaitForSignalledToComplete();
app.DebugPrintf("Shutdown manager: terminated.\n");
// Audio system shutdown
app.DebugPrintf("Shutdown manager: Audio shutdown.\n");
AIL_shutdown();
// Trophy system shutdown
app.DebugPrintf("Shutdown manager: Trophy system shutdown.\n");
ProfileManager.Terminate();
// Network manager shutdown
app.DebugPrintf("Shutdown manager: Network manager shutdown.\n");
g_NetworkManager.Terminate();
// Finally shut down the spurs job queue - leaving until last so there should be nothing else dependent on this still running
app.DebugPrintf("Shutdown manager: SPURS shutdown.\n");
C4JSpursJobQueue::getMainJobQueue().shutdown();
app.DebugPrintf("Shutdown manager: Complete.\n");
#endif
}
void ShutdownManager::HasStarted(ShutdownManager::EThreadId threadId)
{
#ifdef __PS3__
EnterCriticalSection(&s_threadRunningCS);
s_threadRunning[threadId]++;
LeaveCriticalSection(&s_threadRunningCS);
#endif
}
void ShutdownManager::HasStarted(ShutdownManager::EThreadId threadId, C4JThread::EventArray *eventArray)
{
#ifdef __PS3__
EnterCriticalSection(&s_threadRunningCS);
s_threadRunning[threadId]++;
LeaveCriticalSection(&s_threadRunningCS);
s_eventArray[threadId] = eventArray;
#endif
}
bool ShutdownManager::ShouldRun(ShutdownManager::EThreadId threadId)
{
#ifdef __PS3__
return s_threadShouldRun[threadId];
#else
return true;
#endif
}
void ShutdownManager::HasFinished(ShutdownManager::EThreadId threadId)
{
#ifdef __PS3__
EnterCriticalSection(&s_threadRunningCS);
s_threadRunning[threadId]--;
LeaveCriticalSection(&s_threadRunningCS);
#endif
}
#ifdef __PS3__
void ShutdownManager::SysUtilCallback(uint64_t status, uint64_t param, void *userdata)
{
Minecraft *minecraft = Minecraft::GetInstance();
switch(status)
{
case CELL_SYSUTIL_REQUEST_EXITGAME:
app.DebugPrintf("CELL_SYSUTIL_REQUEST_EXITGAME\n");
StartShutdown();
break;
case CELL_SYSUTIL_SYSTEM_MENU_OPEN:
// Tell the game UI to stop processing
StorageManager.SetSystemUIDisplaying(true);
break;
case CELL_SYSUTIL_DRAWING_END:
StorageManager.SetSystemUIDisplaying(false);
break;
case CELL_SYSUTIL_DRAWING_BEGIN:
case CELL_SYSUTIL_SYSTEM_MENU_CLOSE:
break;
case CELL_SYSUTIL_BGMPLAYBACK_PLAY:
if( minecraft )
{
minecraft->soundEngine->updateSystemMusicPlaying(true);
}
app.DebugPrintf("BGM playing\n");
break;
case CELL_SYSUTIL_BGMPLAYBACK_STOP:
if( minecraft )
{
minecraft->soundEngine->updateSystemMusicPlaying(false);
}
app.DebugPrintf("BGM stopped\n");
break;
}
}
#endif
#ifdef __PS3__
void ShutdownManager::WaitForSignalledToComplete()
{
bool allComplete;
do
{
cellSysutilCheckCallback();
Sleep(10);
allComplete = true;
for( int i = 0; i < eThreadIdCount; i++ )
{
if( !s_threadShouldRun[i] )
{
if( s_threadRunning[i] != 0 ) allComplete = false;
}
}
} while( !allComplete);
}
void ShutdownManager::RequestThreadToStop(int i)
{
s_threadShouldRun[i] = false;
if( s_eventArray[i] )
{
s_eventArray[i]->Cancel();
}
}
void ShutdownManager::StorageManagerCompleteFn()
{
HasFinished(eStorageManagerThreads);
}
#endif
@@ -0,0 +1,47 @@
#pragma once
class ShutdownManager
{
public:
typedef enum
{
eMainThread,
eLeaderboardThread,
eCommerceThread,
ePostProcessThread,
eRunUpdateThread,
eRenderChunkUpdateThread,
eServerThread,
eStorageManagerThreads,
eConnectionReadThreads,
eConnectionWriteThreads,
eEventQueueThreads,
eThreadIdCount
} EThreadId;
static void Initialise();
static void StartShutdown();
static void MainThreadHandleShutdown();
#ifdef __PS3__
static void SysUtilCallback(uint64_t status, uint64_t param, void *userdata);
#endif
static void HasStarted(EThreadId threadId);
static void HasStarted(EThreadId threadId, C4JThread::EventArray *eventArray);
static bool ShouldRun(EThreadId threadId);
static void HasFinished(EThreadId threadId);
private:
#ifdef __PS3__
static bool s_threadShouldRun[eThreadIdCount];
static int s_threadRunning[eThreadIdCount];
static CRITICAL_SECTION s_threadRunningCS;
static C4JThread::EventArray *s_eventArray[eThreadIdCount];
static void RequestThreadToStop(int i);
static void WaitForSignalledToComplete();
static void StorageManagerCompleteFn();
#endif
};
@@ -0,0 +1,72 @@
#include "stdafx.h"
TLSStoragePS3* TLSStoragePS3::m_pInstance = NULL;
BOOL TLSStoragePS3::m_activeList[sc_maxSlots];
__thread LPVOID TLSStoragePS3::m_values[sc_maxSlots];
TLSStoragePS3::TLSStoragePS3()
{
for(int i=0;i<sc_maxSlots; i++)
{
m_activeList[i] = false;
m_values[i] = NULL;
}
}
TLSStoragePS3* TLSStoragePS3::Instance()
{
if ( m_pInstance == 0 ) // Is this the first time?
{
m_pInstance = new TLSStoragePS3; // Create the singleton instance.
}
return m_pInstance;
}
int TLSStoragePS3::Alloc()
{
for(int i=0; i<sc_maxSlots; i++)
{
if(m_activeList[i] == false)
{
m_activeList[i] = true;
m_values[i] = NULL;
return i;
}
}
assert(0); // we've ran out of slots
return -1;
}
BOOL TLSStoragePS3::Free( DWORD _index )
{
if(m_activeList[_index] == false)
return false; // not been allocated
m_activeList[_index] = false;
m_values[_index] = NULL;
return true;
}
BOOL TLSStoragePS3::SetValue( DWORD _index, LPVOID _val )
{
if(m_activeList[_index] == false)
return false;
m_values[_index] = _val;
return true;
}
LPVOID TLSStoragePS3::GetValue( DWORD _index )
{
if(m_activeList[_index] == false)
return NULL;
return m_values[_index];
}
@@ -0,0 +1,25 @@
#pragma once
#pragma once
class TLSStoragePS3
{
static TLSStoragePS3* m_pInstance;
static const int sc_maxSlots = 64;
static BOOL m_activeList[sc_maxSlots];
static __thread LPVOID m_values[sc_maxSlots];
public:
TLSStoragePS3();
// Retrieve singleton instance.
static TLSStoragePS3* Instance();
int Alloc();
BOOL Free(DWORD _index);
BOOL SetValue(DWORD _index, LPVOID _val);
LPVOID GetValue(DWORD _index);
};
@@ -0,0 +1,27 @@
///////////////////////////////////////////////////////////////////////////////
/// \file accumulators.hpp
/// Includes all of the Accumulators Framework
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_ACCUMULATORS_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_ACCUMULATORS_HPP_EAN_28_10_2005
#include <boost/accumulators/framework/accumulator_set.hpp>
#include <boost/accumulators/framework/accumulator_concept.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/framework/external.hpp>
#include <boost/accumulators/framework/features.hpp>
#include <boost/accumulators/framework/parameters/accumulator.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/framework/parameters/weight.hpp>
#include <boost/accumulators/framework/parameters/weights.hpp>
#include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
#include <boost/accumulators/framework/accumulators/droppable_accumulator.hpp>
#include <boost/accumulators/framework/accumulators/reference_accumulator.hpp>
#include <boost/accumulators/framework/accumulators/value_accumulator.hpp>
#endif
@@ -0,0 +1,219 @@
///////////////////////////////////////////////////////////////////////////////
// accumulators_fwd.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_ACCUMULATORS_FWD_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_ACCUMULATORS_FWD_HPP_EAN_28_10_2005
#include <boost/config.hpp>
#include <boost/mpl/apply_fwd.hpp> // for mpl::na
#include <boost/mpl/limits/vector.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/accumulators/numeric/functional_fwd.hpp>
#ifndef BOOST_ACCUMULATORS_MAX_FEATURES
/// The maximum number of accumulators that may be put in an accumulator_set.
/// Defaults to BOOST_MPL_LIMIT_VECTOR_SIZE (which defaults to 20).
# define BOOST_ACCUMULATORS_MAX_FEATURES BOOST_MPL_LIMIT_VECTOR_SIZE
#endif
#if BOOST_ACCUMULATORS_MAX_FEATURES > BOOST_MPL_LIMIT_VECTOR_SIZE
# error BOOST_ACCUMULATORS_MAX_FEATURES cannot be larger than BOOST_MPL_LIMIT_VECTOR_SIZE
#endif
#ifndef BOOST_ACCUMULATORS_MAX_ARGS
/// The maximum number of arguments that may be specified to an accumulator_set's
/// accumulation function. Defaults to 15.
# define BOOST_ACCUMULATORS_MAX_ARGS 15
#endif
#if BOOST_WORKAROUND(__GNUC__, == 3) \
|| BOOST_WORKAROUND(__EDG_VERSION__, BOOST_TESTED_AT(306))
# define BOOST_ACCUMULATORS_BROKEN_CONST_OVERLOADS
#endif
#ifdef BOOST_ACCUMULATORS_BROKEN_CONST_OVERLOADS
# include <boost/utility/enable_if.hpp>
# include <boost/type_traits/is_const.hpp>
# define BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(T)\
, typename boost::disable_if<boost::is_const<T> >::type * = 0
#else
# define BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(T)
#endif
#define BOOST_ACCUMULATORS_GCC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
namespace boost { namespace accumulators
{
///////////////////////////////////////////////////////////////////////////////
// Named parameters tags
//
namespace tag
{
struct sample;
struct weight;
struct accumulator;
struct weights;
}
///////////////////////////////////////////////////////////////////////////////
// User-level features
//
namespace tag
{
template<typename ValueType, typename Tag>
struct value;
template<typename Tag>
struct value_tag;
template<typename Referent, typename Tag>
struct reference;
template<typename Tag>
struct reference_tag;
template<typename Type, typename Tag = void, typename AccumulatorSet = void>
struct external;
template<typename Feature>
struct droppable;
}
template<typename Accumulator>
struct droppable_accumulator_base;
template<typename Accumulator>
struct droppable_accumulator;
template<typename Accumulator>
struct with_cached_result;
template<typename Sample, typename Features, typename Weight = void>
struct accumulator_set;
template<typename Feature>
struct extractor;
template<typename Feature>
struct feature_of;
template<typename Feature>
struct as_feature;
template<typename Feature>
struct as_weighted_feature;
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
struct depends_on;
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
struct features;
template<typename Feature, typename AccumulatorSet>
typename mpl::apply<AccumulatorSet, Feature>::type const &
find_accumulator(AccumulatorSet const &acc);
template<typename Feature, typename AccumulatorSet>
typename mpl::apply<AccumulatorSet, Feature>::type::result_type
extract_result(AccumulatorSet const &acc);
template<typename Feature, typename AccumulatorSet, typename A1>
typename mpl::apply<AccumulatorSet, Feature>::type::result_type
extract_result(AccumulatorSet const &acc, A1 const &a1);
// ... other overloads generated by Boost.Preprocessor:
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_EXTRACT_RESULT_FWD(z, n, _) \
template< \
typename Feature \
, typename AccumulatorSet \
BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
> \
typename mpl::apply<AccumulatorSet, Feature>::type::result_type \
extract_result( \
AccumulatorSet const &acc \
BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \
);
/// INTERNAL ONLY
///
BOOST_PP_REPEAT_FROM_TO(
2
, BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
, BOOST_ACCUMULATORS_EXTRACT_RESULT_FWD
, _
)
#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
template<typename Feature, typename AccumulatorSet, typename A1, typename A2 ...>
typename mpl::apply<AccumulatorSet, Feature>::type::result_type
extract_result(AccumulatorSet const &acc, A1 const &a1, A2 const &a2 ...);
#endif
namespace impl
{
using namespace numeric::operators;
template<typename Accumulator, typename Tag>
struct external_impl;
}
namespace detail
{
template<typename Accumulator>
struct feature_tag;
template<typename Feature, typename Sample, typename Weight>
struct to_accumulator;
struct accumulator_set_base;
template<typename T>
struct is_accumulator_set;
inline void ignore_variable(void const *) {}
#define BOOST_ACCUMULATORS_IGNORE_GLOBAL(X)\
namespace detail { inline void BOOST_PP_CAT(ignore_, X)() { boost::accumulators::detail::ignore_variable(&X); } }
}
}} // namespace boost::accumulators
// For defining boost::parameter keywords that can be inherited from to
// get a nested, class-scoped keyword with the requested alias
#define BOOST_PARAMETER_NESTED_KEYWORD(tag_namespace, name, alias) \
namespace tag_namespace \
{ \
template<int Dummy = 0> \
struct name ## _ \
{ \
static char const* keyword_name() \
{ \
return #name; \
} \
static ::boost::parameter::keyword<name ## _<Dummy> > &alias; \
}; \
template<int Dummy> \
::boost::parameter::keyword<name ## _<Dummy> > &name ## _<Dummy>::alias = \
::boost::parameter::keyword<name ## _<Dummy> >::get(); \
typedef name ## _ <> name; \
} \
namespace \
{ \
::boost::parameter::keyword<tag_namespace::name> &name = \
::boost::parameter::keyword<tag_namespace::name>::get(); \
}
#endif
@@ -0,0 +1,65 @@
///////////////////////////////////////////////////////////////////////////////
// accumulator_base.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_BASE_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_BASE_HPP_EAN_28_10_2005
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/single_view.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/contains.hpp>
#include <boost/mpl/empty_sequence.hpp>
#include <boost/accumulators/framework/accumulator_concept.hpp>
namespace boost { namespace accumulators
{
namespace detail
{
typedef void void_;
}
///////////////////////////////////////////////////////////////////////////////
// dont_care
//
struct dont_care
{
template<typename Args>
dont_care(Args const &)
{
}
};
///////////////////////////////////////////////////////////////////////////////
// accumulator_base
//
struct accumulator_base
{
// hidden if defined in derived classes
detail::void_ operator ()(dont_care)
{
}
typedef mpl::false_ is_droppable;
detail::void_ add_ref(dont_care)
{
}
detail::void_ drop(dont_care)
{
}
detail::void_ on_drop(dont_care)
{
}
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,29 @@
///////////////////////////////////////////////////////////////////////////////
// accumulator_concept.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_CONCEPT_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_CONCEPT_HPP_EAN_28_10_2005
#include <boost/concept_check.hpp>
namespace boost { namespace accumulators
{
template<typename Stat>
struct accumulator_concept
{
void constraints()
{
// TODO: define the stat concept
}
Stat stat;
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,401 @@
///////////////////////////////////////////////////////////////////////////////
// accumulator_set.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_SET_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_SET_HPP_EAN_28_10_2005
#include <boost/version.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/protect.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/parameter/parameters.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/accumulators/accumulators_fwd.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/framework/accumulator_concept.hpp>
#include <boost/accumulators/framework/parameters/accumulator.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
#include <boost/accumulators/framework/accumulators/droppable_accumulator.hpp>
#include <boost/fusion/include/any.hpp>
#include <boost/fusion/include/find_if.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <boost/fusion/include/filter_view.hpp>
namespace boost { namespace accumulators
{
namespace detail
{
///////////////////////////////////////////////////////////////////////////////
// accumulator_visitor
// wrap a boost::parameter argument pack in a Fusion extractor object
template<typename Args>
struct accumulator_visitor
{
explicit accumulator_visitor(Args const &a)
: args(a)
{
}
template<typename Accumulator>
void operator ()(Accumulator &accumulator) const
{
accumulator(this->args);
}
private:
accumulator_visitor &operator =(accumulator_visitor const &);
Args const &args;
};
template<typename Args>
inline accumulator_visitor<Args> const make_accumulator_visitor(Args const &args)
{
return accumulator_visitor<Args>(args);
}
typedef
parameter::parameters<
parameter::required<tag::accumulator>
, parameter::optional<tag::sample>
// ... and others which are not specified here...
>
accumulator_params;
///////////////////////////////////////////////////////////////////////////////
// accumulator_set_base
struct accumulator_set_base
{
};
///////////////////////////////////////////////////////////////////////////////
// is_accumulator_set
template<typename T>
struct is_accumulator_set
: is_base_and_derived<accumulator_set_base, T>
{
};
} // namespace detail
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list
#endif
///////////////////////////////////////////////////////////////////////////////
/// \brief A set of accumulators.
///
/// accumulator_set resolves the dependencies between features and ensures that
/// the accumulators in the set are updated in the proper order.
///
/// acccumulator_set provides a general mechanism to visit the accumulators
/// in the set in order, with or without a filter. You can also fetch a reference
/// to an accumulator that corresponds to a feature.
///
template<typename Sample, typename Features, typename Weight>
struct accumulator_set
: detail::accumulator_set_base
{
typedef Sample sample_type; ///< The type of the samples that will be accumulated
typedef Features features_type; ///< An MPL sequence of the features that should be accumulated.
typedef Weight weight_type; ///< The type of the weight parameter. Must be a scalar. Defaults to void.
/// INTERNAL ONLY
///
typedef
typename detail::make_accumulator_tuple<
Features
, Sample
, Weight
>::type
accumulators_mpl_vector;
// generate a fusion::list of accumulators
/// INTERNAL ONLY
///
typedef
typename detail::meta::make_acc_list<
accumulators_mpl_vector
>::type
accumulators_type;
/// INTERNAL ONLY
///
//BOOST_MPL_ASSERT((mpl::is_sequence<accumulators_type>));
///////////////////////////////////////////////////////////////////////////////
/// default-construct all contained accumulators
accumulator_set()
: accumulators(
detail::make_acc_list(
accumulators_mpl_vector()
, detail::accumulator_params()(*this)
)
)
{
// Add-ref the Features that the user has specified
this->template visit_if<detail::contains_feature_of_<Features> >(
detail::make_add_ref_visitor(detail::accumulator_params()(*this))
);
}
/// \overload
///
/// \param a1 Optional named parameter to be passed to all the accumulators
template<typename A1>
explicit accumulator_set(A1 const &a1)
: accumulators(
detail::make_acc_list(
accumulators_mpl_vector()
, detail::accumulator_params()(*this, a1)
)
)
{
// Add-ref the Features that the user has specified
this->template visit_if<detail::contains_feature_of_<Features> >(
detail::make_add_ref_visitor(detail::accumulator_params()(*this))
);
}
// ... other overloads generated by Boost.Preprocessor:
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_ACCUMULATOR_SET_CTOR(z, n, _) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
accumulator_set(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a)) \
: accumulators( \
detail::make_acc_list( \
accumulators_mpl_vector() \
, detail::accumulator_params()( \
*this BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \
) \
) \
) \
{ \
/* Add-ref the Features that the user has specified */ \
this->template visit_if<detail::contains_feature_of_<Features> >( \
detail::make_add_ref_visitor(detail::accumulator_params()(*this)) \
); \
}
/// INTERNAL ONLY
///
BOOST_PP_REPEAT_FROM_TO(
2
, BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
, BOOST_ACCUMULATORS_ACCUMULATOR_SET_CTOR
, _
)
#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
/// \overload
///
template<typename A1, typename A2, ...>
accumulator_set(A1 const &a1, A2 const &a2, ...);
#endif
// ... other overloads generated by Boost.Preprocessor below ...
///////////////////////////////////////////////////////////////////////////////
/// Visitation
/// \param func UnaryFunction which is invoked with each accumulator in turn.
template<typename UnaryFunction>
void visit(UnaryFunction const &func)
{
fusion::for_each(this->accumulators, func);
}
///////////////////////////////////////////////////////////////////////////////
/// Conditional visitation
/// \param func UnaryFunction which is invoked with each accumulator in turn,
/// provided the accumulator satisfies the MPL predicate FilterPred.
template<typename FilterPred, typename UnaryFunction>
void visit_if(UnaryFunction const &func)
{
fusion::filter_view<accumulators_type, FilterPred> filtered_accs(this->accumulators);
fusion::for_each(filtered_accs, func);
}
///////////////////////////////////////////////////////////////////////////////
/// The return type of the operator() overloads is void.
typedef void result_type;
///////////////////////////////////////////////////////////////////////////////
/// Accumulation
/// \param a1 Optional named parameter to be passed to all the accumulators
void operator ()()
{
this->visit(
detail::make_accumulator_visitor(
detail::accumulator_params()(*this)
)
);
}
template<typename A1>
void operator ()(A1 const &a1)
{
this->visit(
detail::make_accumulator_visitor(
detail::accumulator_params()(*this, a1)
)
);
}
// ... other overloads generated by Boost.Preprocessor:
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_ACCUMULATOR_SET_FUN_OP(z, n, _) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
void operator ()(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a)) \
{ \
this->visit( \
detail::make_accumulator_visitor( \
detail::accumulator_params()( \
*this BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \
) \
) \
); \
}
/// INTERNAL ONLY
///
BOOST_PP_REPEAT_FROM_TO(
2
, BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
, BOOST_ACCUMULATORS_ACCUMULATOR_SET_FUN_OP
, _
)
#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
/// \overload
///
template<typename A1, typename A2, ...>
void operator ()(A1 const &a1, A2 const &a2, ...);
#endif
///////////////////////////////////////////////////////////////////////////////
/// Extraction
template<typename Feature>
struct apply
: fusion::result_of::value_of<
typename fusion::result_of::find_if<
accumulators_type
, detail::matches_feature<Feature>
>::type
>
{
};
///////////////////////////////////////////////////////////////////////////////
/// Extraction
template<typename Feature>
typename apply<Feature>::type &extract()
{
return *fusion::find_if<detail::matches_feature<Feature> >(this->accumulators);
}
/// \overload
template<typename Feature>
typename apply<Feature>::type const &extract() const
{
return *fusion::find_if<detail::matches_feature<Feature> >(this->accumulators);
}
///////////////////////////////////////////////////////////////////////////////
/// Drop
template<typename Feature>
void drop()
{
// You can only drop the features that you have specified explicitly
typedef typename apply<Feature>::type the_accumulator;
BOOST_MPL_ASSERT((detail::contains_feature_of<Features, the_accumulator>));
typedef
typename feature_of<typename as_feature<Feature>::type>::type
the_feature;
(*fusion::find_if<detail::matches_feature<Feature> >(this->accumulators))
.drop(detail::accumulator_params()(*this));
// Also drop accumulators that this feature depends on
typedef typename the_feature::dependencies dependencies;
this->template visit_if<detail::contains_feature_of_<dependencies> >(
detail::make_drop_visitor(detail::accumulator_params()(*this))
);
}
private:
accumulators_type accumulators;
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
///////////////////////////////////////////////////////////////////////////////
// find_accumulator
// find an accumulator in an accumulator_set corresponding to a feature
template<typename Feature, typename AccumulatorSet>
typename mpl::apply<AccumulatorSet, Feature>::type &
find_accumulator(AccumulatorSet &acc BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(AccumulatorSet))
{
return acc.template extract<Feature>();
}
/// \overload
template<typename Feature, typename AccumulatorSet>
typename mpl::apply<AccumulatorSet, Feature>::type const &
find_accumulator(AccumulatorSet const &acc)
{
return acc.template extract<Feature>();
}
///////////////////////////////////////////////////////////////////////////////
// extract_result
// extract a result from an accumulator set
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_EXTRACT_RESULT_FUN(z, n, _) \
template< \
typename Feature \
, typename AccumulatorSet \
BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
> \
typename mpl::apply<AccumulatorSet, Feature>::type::result_type \
extract_result( \
AccumulatorSet const &acc \
BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \
) \
{ \
return find_accumulator<Feature>(acc).result( \
detail::accumulator_params()( \
acc \
BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \
) \
); \
}
BOOST_PP_REPEAT(
BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
, BOOST_ACCUMULATORS_EXTRACT_RESULT_FUN
, _
)
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,328 @@
///////////////////////////////////////////////////////////////////////////////
// droppable_accumulator.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_DROPPABLE_ACCUMULATOR_HPP_EAN_13_12_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_DROPPABLE_ACCUMULATOR_HPP_EAN_13_12_2005
#include <new>
#include <boost/assert.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/aligned_storage.hpp>
#include <boost/accumulators/framework/depends_on.hpp> // for feature_of
#include <boost/accumulators/framework/parameters/accumulator.hpp> // for accumulator
namespace boost { namespace accumulators
{
template<typename Accumulator>
struct droppable_accumulator;
namespace detail
{
///////////////////////////////////////////////////////////////////////////////
// add_ref_visitor
// a fusion function object for add_ref'ing accumulators
template<typename Args>
struct add_ref_visitor
{
explicit add_ref_visitor(Args const &args)
: args_(args)
{
}
template<typename Accumulator>
void operator ()(Accumulator &acc) const
{
typedef typename Accumulator::feature_tag::dependencies dependencies;
acc.add_ref(this->args_);
// Also add_ref accumulators that this feature depends on
this->args_[accumulator].template
visit_if<detail::contains_feature_of_<dependencies> >(
*this
);
}
private:
add_ref_visitor &operator =(add_ref_visitor const &);
Args const &args_;
};
template<typename Args>
add_ref_visitor<Args> make_add_ref_visitor(Args const &args)
{
return add_ref_visitor<Args>(args);
}
///////////////////////////////////////////////////////////////////////////////
// drop_visitor
// a fusion function object for dropping accumulators
template<typename Args>
struct drop_visitor
{
explicit drop_visitor(Args const &args)
: args_(args)
{
}
template<typename Accumulator>
void operator ()(Accumulator &acc) const
{
if(typename Accumulator::is_droppable())
{
typedef typename Accumulator::feature_tag::dependencies dependencies;
acc.drop(this->args_);
// Also drop accumulators that this feature depends on
this->args_[accumulator].template
visit_if<detail::contains_feature_of_<dependencies> >(
*this
);
}
}
private:
drop_visitor &operator =(drop_visitor const &);
Args const &args_;
};
template<typename Args>
drop_visitor<Args> make_drop_visitor(Args const &args)
{
return drop_visitor<Args>(args);
}
}
//////////////////////////////////////////////////////////////////////////
// droppable_accumulator_base
template<typename Accumulator>
struct droppable_accumulator_base
: Accumulator
{
typedef droppable_accumulator_base base;
typedef mpl::true_ is_droppable;
typedef typename Accumulator::result_type result_type;
template<typename Args>
droppable_accumulator_base(Args const &args)
: Accumulator(args)
, ref_count_(0)
{
}
droppable_accumulator_base(droppable_accumulator_base const &that)
: Accumulator(*static_cast<Accumulator const *>(&that))
, ref_count_(that.ref_count_)
{
}
template<typename Args>
void operator ()(Args const &args)
{
if(!this->is_dropped())
{
this->Accumulator::operator ()(args);
}
}
template<typename Args>
void add_ref(Args const &)
{
++this->ref_count_;
}
template<typename Args>
void drop(Args const &args)
{
BOOST_ASSERT(0 < this->ref_count_);
if(1 == this->ref_count_)
{
static_cast<droppable_accumulator<Accumulator> *>(this)->on_drop(args);
}
--this->ref_count_;
}
bool is_dropped() const
{
return 0 == this->ref_count_;
}
private:
int ref_count_;
};
//////////////////////////////////////////////////////////////////////////
// droppable_accumulator
// this can be specialized for any type that needs special handling
template<typename Accumulator>
struct droppable_accumulator
: droppable_accumulator_base<Accumulator>
{
template<typename Args>
droppable_accumulator(Args const &args)
: droppable_accumulator::base(args)
{
}
droppable_accumulator(droppable_accumulator const &that)
: droppable_accumulator::base(*static_cast<typename droppable_accumulator::base const *>(&that))
{
}
};
//////////////////////////////////////////////////////////////////////////
// with_cached_result
template<typename Accumulator>
struct with_cached_result
: Accumulator
{
typedef typename Accumulator::result_type result_type;
template<typename Args>
with_cached_result(Args const &args)
: Accumulator(args)
, cache()
{
}
with_cached_result(with_cached_result const &that)
: Accumulator(*static_cast<Accumulator const *>(&that))
, cache()
{
if(that.has_result())
{
this->set(that.get());
}
}
~with_cached_result()
{
// Since this is a base class of droppable_accumulator_base,
// this destructor is called before any of droppable_accumulator_base's
// members get cleaned up, including is_dropped, so the following
// call to has_result() is valid.
if(this->has_result())
{
this->get().~result_type();
}
}
template<typename Args>
void on_drop(Args const &args)
{
// cache the result at the point this calcuation was dropped
BOOST_ASSERT(!this->has_result());
this->set(this->Accumulator::result(args));
}
template<typename Args>
result_type result(Args const &args) const
{
return this->has_result() ? this->get() : this->Accumulator::result(args);
}
private:
with_cached_result &operator =(with_cached_result const &);
void set(result_type const &r)
{
::new(this->cache.address()) result_type(r);
}
result_type const &get() const
{
return *static_cast<result_type const *>(this->cache.address());
}
bool has_result() const
{
typedef with_cached_result<Accumulator> this_type;
typedef droppable_accumulator_base<this_type> derived_type;
return static_cast<derived_type const *>(this)->is_dropped();
}
aligned_storage<sizeof(result_type)> cache;
};
namespace tag
{
template<typename Feature>
struct as_droppable
{
typedef droppable<Feature> type;
};
template<typename Feature>
struct as_droppable<droppable<Feature> >
{
typedef droppable<Feature> type;
};
//////////////////////////////////////////////////////////////////////////
// droppable
template<typename Feature>
struct droppable
: as_feature<Feature>::type
{
typedef typename as_feature<Feature>::type feature_type;
typedef typename feature_type::dependencies tmp_dependencies_;
typedef
typename mpl::transform<
typename feature_type::dependencies
, as_droppable<mpl::_1>
>::type
dependencies;
struct impl
{
template<typename Sample, typename Weight>
struct apply
{
typedef
droppable_accumulator<
typename mpl::apply2<typename feature_type::impl, Sample, Weight>::type
>
type;
};
};
};
}
// make droppable<tag::feature(modifier)> work
template<typename Feature>
struct as_feature<tag::droppable<Feature> >
{
typedef tag::droppable<typename as_feature<Feature>::type> type;
};
// make droppable<tag::mean> work with non-void weights (should become
// droppable<tag::weighted_mean>
template<typename Feature>
struct as_weighted_feature<tag::droppable<Feature> >
{
typedef tag::droppable<typename as_weighted_feature<Feature>::type> type;
};
// for the purposes of feature-based dependency resolution,
// droppable<Foo> provides the same feature as Foo
template<typename Feature>
struct feature_of<tag::droppable<Feature> >
: feature_of<Feature>
{
};
// Note: Usually, the extractor is pulled into the accumulators namespace with
// a using directive, not the tag. But the droppable<> feature doesn't have an
// extractor, so we can put the droppable tag in the accumulators namespace
// without fear of a name conflict.
using tag::droppable;
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,108 @@
///////////////////////////////////////////////////////////////////////////////
// external_accumulator.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_EXTERNAL_ACCUMULATOR_HPP_EAN_01_12_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_EXTERNAL_ACCUMULATOR_HPP_EAN_01_12_2005
#include <boost/mpl/placeholders.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/accumulators/reference_accumulator.hpp>
namespace boost { namespace accumulators { namespace impl
{
//////////////////////////////////////////////////////////////////////////
// external_impl
/// INTERNAL ONLY
///
template<typename Accumulator, typename Tag>
struct external_impl
: accumulator_base
{
typedef typename Accumulator::result_type result_type;
typedef typename detail::feature_tag<Accumulator>::type feature_tag;
external_impl(dont_care) {}
template<typename Args>
result_type result(Args const &args) const
{
return this->extract_(args, args[parameter::keyword<Tag>::get() | 0]);
}
private:
template<typename Args>
static result_type extract_(Args const &args, int)
{
// No named parameter passed to the extractor. Maybe the external
// feature is held by reference<>.
extractor<feature_tag> extract;
return extract(accumulators::reference_tag<Tag>(args));
}
template<typename Args, typename AccumulatorSet>
static result_type extract_(Args const &, AccumulatorSet const &acc)
{
// OK, a named parameter for this external feature was passed to the
// extractor, so use that.
extractor<feature_tag> extract;
return extract(acc);
}
};
} // namespace impl
namespace tag
{
//////////////////////////////////////////////////////////////////////////
// external
template<typename Feature, typename Tag, typename AccumulatorSet>
struct external
: depends_on<reference<AccumulatorSet, Tag> >
{
typedef
accumulators::impl::external_impl<
detail::to_accumulator<Feature, mpl::_1, mpl::_2>
, Tag
>
impl;
};
template<typename Feature, typename Tag>
struct external<Feature, Tag, void>
: depends_on<>
{
typedef
accumulators::impl::external_impl<
detail::to_accumulator<Feature, mpl::_1, mpl::_2>
, Tag
>
impl;
};
}
// for the purposes of feature-based dependency resolution,
// external_accumulator<Feature, Tag> provides the same feature as Feature
template<typename Feature, typename Tag, typename AccumulatorSet>
struct feature_of<tag::external<Feature, Tag, AccumulatorSet> >
: feature_of<Feature>
{
};
// Note: Usually, the extractor is pulled into the accumulators namespace with
// a using directive, not the tag. But the external<> feature doesn't have an
// extractor, so we can put the external tag in the accumulators namespace
// without fear of a name conflict.
using tag::external;
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,89 @@
///////////////////////////////////////////////////////////////////////////////
// reference_accumulator.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_REFERENCE_ACCUMULATOR_HPP_EAN_03_23_2006
#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_REFERENCE_ACCUMULATOR_HPP_EAN_03_23_2006
#include <boost/ref.hpp>
#include <boost/mpl/always.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
namespace boost { namespace accumulators
{
namespace impl
{
//////////////////////////////////////////////////////////////////////////
// reference_accumulator_impl
//
template<typename Referent, typename Tag>
struct reference_accumulator_impl
: accumulator_base
{
typedef Referent &result_type;
template<typename Args>
reference_accumulator_impl(Args const &args)
: ref(args[parameter::keyword<Tag>::get()])
{
}
result_type result(dont_care) const
{
return this->ref;
}
private:
reference_wrapper<Referent> ref;
};
} // namespace impl
namespace tag
{
//////////////////////////////////////////////////////////////////////////
// reference_tag
template<typename Tag>
struct reference_tag
{
};
//////////////////////////////////////////////////////////////////////////
// reference
template<typename Referent, typename Tag>
struct reference
: depends_on<>
{
/// INTERNAL ONLY
///
typedef mpl::always<accumulators::impl::reference_accumulator_impl<Referent, Tag> > impl;
};
}
namespace extract
{
BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, reference, (typename)(typename))
BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, reference_tag, (typename))
}
using extract::reference;
using extract::reference_tag;
// Map all reference<V,T> features to reference_tag<T> so
// that references can be extracted using reference_tag<T>
// without specifying the referent type.
template<typename ValueType, typename Tag>
struct feature_of<tag::reference<ValueType, Tag> >
: feature_of<tag::reference_tag<Tag> >
{
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,89 @@
///////////////////////////////////////////////////////////////////////////////
// value_accumulator.hpp
//
// Copyright 2005 Eric Niebler, Daniel Egloff. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_VALUE_ACCUMULATOR_HPP_EAN_03_23_2006
#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_VALUE_ACCUMULATOR_HPP_EAN_03_23_2006
#include <boost/mpl/always.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
namespace boost { namespace accumulators
{
namespace impl
{
//////////////////////////////////////////////////////////////////////////
// value_accumulator_impl
template<typename ValueType, typename Tag>
struct value_accumulator_impl
: accumulator_base
{
typedef ValueType result_type;
template<typename Args>
value_accumulator_impl(Args const &args)
: val(args[parameter::keyword<Tag>::get()])
{
}
result_type result(dont_care) const
{
return this->val;
}
private:
ValueType val;
};
} // namespace impl
namespace tag
{
//////////////////////////////////////////////////////////////////////////
// value_tag
template<typename Tag>
struct value_tag
{
};
//////////////////////////////////////////////////////////////////////////
// value
template<typename ValueType, typename Tag>
struct value
: depends_on<>
{
/// INTERNAL ONLY
///
typedef mpl::always<accumulators::impl::value_accumulator_impl<ValueType, Tag> > impl;
};
}
namespace extract
{
BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, value, (typename)(typename))
BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, value_tag, (typename))
}
using extract::value;
using extract::value_tag;
// Map all value<V,T> features to value_tag<T> so
// that values can be extracted using value_tag<T>
// without specifying the value type.
template<typename ValueType, typename Tag>
struct feature_of<tag::value<ValueType, Tag> >
: feature_of<tag::value_tag<Tag> >
{
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,448 @@
///////////////////////////////////////////////////////////////////////////////
// depends_on.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_DEPENDS_ON_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_DEPENDS_ON_HPP_EAN_28_10_2005
#include <boost/version.hpp>
#include <boost/mpl/end.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/set.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/sort.hpp>
#include <boost/mpl/insert.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/remove.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/inherit.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/contains.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/insert_range.hpp>
#include <boost/mpl/back_inserter.hpp>
#include <boost/mpl/transform_view.hpp>
#include <boost/mpl/inherit_linearly.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/facilities/intercept.hpp>
#include <boost/accumulators/accumulators_fwd.hpp>
#include <boost/fusion/include/next.hpp>
#include <boost/fusion/include/equal_to.hpp>
#include <boost/fusion/include/value_of.hpp>
#include <boost/fusion/include/mpl.hpp>
#include <boost/fusion/include/end.hpp>
#include <boost/fusion/include/begin.hpp>
#include <boost/fusion/include/cons.hpp>
namespace boost { namespace accumulators
{
///////////////////////////////////////////////////////////////////////////
// as_feature
template<typename Feature>
struct as_feature
{
typedef Feature type;
};
///////////////////////////////////////////////////////////////////////////
// weighted_feature
template<typename Feature>
struct as_weighted_feature
{
typedef Feature type;
};
///////////////////////////////////////////////////////////////////////////
// feature_of
template<typename Feature>
struct feature_of
{
typedef Feature type;
};
namespace detail
{
///////////////////////////////////////////////////////////////////////////
// feature_tag
template<typename Accumulator>
struct feature_tag
{
typedef typename Accumulator::feature_tag type;
};
template<typename Feature>
struct undroppable
{
typedef Feature type;
};
template<typename Feature>
struct undroppable<tag::droppable<Feature> >
{
typedef Feature type;
};
// For the purpose of determining whether one feature depends on another,
// disregard whether the feature is droppable or not.
template<typename A, typename B>
struct is_dependent_on
: is_base_and_derived<
typename feature_of<typename undroppable<B>::type>::type
, typename undroppable<A>::type
>
{};
template<typename Feature>
struct dependencies_of
{
typedef typename Feature::dependencies type;
};
// Should use mpl::insert_range, but doesn't seem to work with mpl sets
template<typename Set, typename Range>
struct set_insert_range
: mpl::fold<
Range
, Set
, mpl::insert<mpl::_1, mpl::_2>
>
{};
template<typename Features>
struct collect_abstract_features
: mpl::fold<
Features
, mpl::set0<>
, set_insert_range<
mpl::insert<mpl::_1, feature_of<mpl::_2> >
, collect_abstract_features<dependencies_of<mpl::_2> >
>
>
{};
template<typename Features>
struct depends_on_base
: mpl::inherit_linearly<
typename mpl::sort<
typename mpl::copy<
typename collect_abstract_features<Features>::type
, mpl::back_inserter<mpl::vector0<> >
>::type
, is_dependent_on<mpl::_1, mpl::_2>
>::type
// Don't inherit multiply from a feature
, mpl::if_<
is_dependent_on<mpl::_1, mpl::_2>
, mpl::_1
, mpl::inherit<mpl::_1, mpl::_2>
>
>::type
{
};
}
///////////////////////////////////////////////////////////////////////////
/// depends_on
template<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature)>
struct depends_on
: detail::depends_on_base<
typename mpl::transform<
mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Feature)>
, as_feature<mpl::_1>
>::type
>
{
typedef mpl::false_ is_weight_accumulator;
typedef
typename mpl::transform<
mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Feature)>
, as_feature<mpl::_1>
>::type
dependencies;
};
namespace detail
{
template<typename Feature>
struct matches_feature
{
template<typename Accumulator>
struct apply
: is_same<
typename feature_of<typename as_feature<Feature>::type>::type
, typename feature_of<typename as_feature<typename feature_tag<Accumulator>::type>::type>::type
>
{};
};
template<typename Features, typename Accumulator>
struct contains_feature_of
{
typedef
mpl::transform_view<Features, feature_of<as_feature<mpl::_> > >
features_list;
typedef
typename feature_of<typename feature_tag<Accumulator>::type>::type
the_feature;
typedef
typename mpl::contains<features_list, the_feature>::type
type;
};
// This is to work around a bug in early versions of Fusion which caused
// a compile error if contains_feature_of<List, mpl::_> is used as a
// predicate to fusion::find_if
template<typename Features>
struct contains_feature_of_
{
template<typename Accumulator>
struct apply
: contains_feature_of<Features, Accumulator>
{};
};
template<
typename First
, typename Last
, bool is_empty = fusion::result_of::equal_to<First, Last>::value
>
struct build_acc_list;
template<typename First, typename Last>
struct build_acc_list<First, Last, true>
{
typedef fusion::nil type;
template<typename Args>
static fusion::nil
call(Args const &, First const&, Last const&)
{
return fusion::nil();
}
};
template<typename First, typename Last>
struct build_acc_list<First, Last, false>
{
typedef
build_acc_list<typename fusion::result_of::next<First>::type, Last>
next_build_acc_list;
typedef fusion::cons<
typename fusion::result_of::value_of<First>::type
, typename next_build_acc_list::type>
type;
template<typename Args>
static type
call(Args const &args, First const& f, Last const& l)
{
return type(args, next_build_acc_list::call(args, fusion::next(f), l));
}
};
namespace meta
{
template<typename Sequence>
struct make_acc_list
: build_acc_list<
typename fusion::result_of::begin<Sequence>::type
, typename fusion::result_of::end<Sequence>::type
>
{};
}
template<typename Sequence, typename Args>
typename meta::make_acc_list<Sequence>::type
make_acc_list(Sequence const &seq, Args const &args)
{
return meta::make_acc_list<Sequence>::call(args, fusion::begin(seq), fusion::end(seq));
}
///////////////////////////////////////////////////////////////////////////
// checked_as_weighted_feature
template<typename Feature>
struct checked_as_weighted_feature
{
typedef typename as_feature<Feature>::type feature_type;
typedef typename as_weighted_feature<feature_type>::type type;
// weighted and non-weighted flavors should provide the same feature.
BOOST_MPL_ASSERT((
is_same<
typename feature_of<feature_type>::type
, typename feature_of<type>::type
>
));
};
///////////////////////////////////////////////////////////////////////////
// as_feature_list
template<typename Features, typename Weight>
struct as_feature_list
: mpl::transform_view<Features, checked_as_weighted_feature<mpl::_1> >
{
};
template<typename Features>
struct as_feature_list<Features, void>
: mpl::transform_view<Features, as_feature<mpl::_1> >
{
};
///////////////////////////////////////////////////////////////////////////
// accumulator_wrapper
template<typename Accumulator, typename Feature>
struct accumulator_wrapper
: Accumulator
{
typedef Feature feature_tag;
accumulator_wrapper(accumulator_wrapper const &that)
: Accumulator(*static_cast<Accumulator const *>(&that))
{
}
template<typename Args>
accumulator_wrapper(Args const &args)
: Accumulator(args)
{
}
};
///////////////////////////////////////////////////////////////////////////
// to_accumulator
template<typename Feature, typename Sample, typename Weight>
struct to_accumulator
{
typedef
accumulator_wrapper<
typename mpl::apply2<typename Feature::impl, Sample, Weight>::type
, Feature
>
type;
};
template<typename Feature, typename Sample, typename Weight, typename Tag, typename AccumulatorSet>
struct to_accumulator<Feature, Sample, tag::external<Weight, Tag, AccumulatorSet> >
{
BOOST_MPL_ASSERT((is_same<Tag, void>));
BOOST_MPL_ASSERT((is_same<AccumulatorSet, void>));
typedef
accumulator_wrapper<
typename mpl::apply2<typename Feature::impl, Sample, Weight>::type
, Feature
>
accumulator_type;
typedef
typename mpl::if_<
typename Feature::is_weight_accumulator
, accumulator_wrapper<impl::external_impl<accumulator_type, tag::weights>, Feature>
, accumulator_type
>::type
type;
};
// BUGBUG work around an MPL bug wrt map insertion
template<typename FeatureMap, typename Feature>
struct insert_feature
: mpl::eval_if<
mpl::has_key<FeatureMap, typename feature_of<Feature>::type>
, mpl::identity<FeatureMap>
, mpl::insert<FeatureMap, mpl::pair<typename feature_of<Feature>::type, Feature> >
>
{
};
template<typename FeatureMap, typename Feature, typename Weight>
struct insert_dependencies
: mpl::fold<
as_feature_list<typename Feature::dependencies, Weight>
, FeatureMap
, insert_dependencies<
insert_feature<mpl::_1, mpl::_2>
, mpl::_2
, Weight
>
>
{
};
template<typename FeatureMap, typename Features, typename Weight>
struct insert_sequence
: mpl::fold< // BUGBUG should use insert_range, but doesn't seem to work for maps
as_feature_list<Features, Weight>
, FeatureMap
, insert_feature<mpl::_1, mpl::_2>
>
{
};
template<typename Features, typename Sample, typename Weight>
struct make_accumulator_tuple
{
typedef
typename mpl::fold<
as_feature_list<Features, Weight>
, mpl::map0<>
, mpl::if_<
mpl::is_sequence<mpl::_2>
, insert_sequence<mpl::_1, mpl::_2, Weight>
, insert_feature<mpl::_1, mpl::_2>
>
>::type
feature_map;
// for each element in the map, add its dependencies also
typedef
typename mpl::fold<
feature_map
, feature_map
, insert_dependencies<mpl::_1, mpl::second<mpl::_2>, Weight>
>::type
feature_map_with_dependencies;
// turn the map into a vector so we can sort it
typedef
typename mpl::insert_range<
mpl::vector<>
, mpl::end<mpl::vector<> >::type
, mpl::transform_view<feature_map_with_dependencies, mpl::second<mpl::_1> >
>::type
feature_vector_with_dependencies;
// sort the features according to which is derived from which
typedef
typename mpl::sort<
feature_vector_with_dependencies
, is_dependent_on<mpl::_2, mpl::_1>
>::type
sorted_feature_vector;
// From the vector of features, construct a vector of accumulators
typedef
typename mpl::transform<
sorted_feature_vector
, to_accumulator<mpl::_1, Sample, Weight>
>::type
type;
};
} // namespace detail
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,27 @@
///////////////////////////////////////////////////////////////////////////////
// external.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_EXTERNAL_HPP_EAN_01_12_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_EXTERNAL_HPP_EAN_01_12_2005
#include <boost/mpl/apply.hpp>
#include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
//namespace boost { namespace accumulators
//{
//
/////////////////////////////////////////////////////////////////////////////////
//// external
////
//template<typename Type>
//struct external
//{
//};
//
//}} // namespace boost::accumulators
#endif
@@ -0,0 +1,229 @@
///////////////////////////////////////////////////////////////////////////////
// extractor.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_EXTRACTOR_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_EXTRACTOR_HPP_EAN_28_10_2005
#include <boost/preprocessor/tuple/rem.hpp>
#include <boost/preprocessor/array/size.hpp>
#include <boost/preprocessor/array/data.hpp>
#include <boost/preprocessor/array/elem.hpp>
#include <boost/preprocessor/seq/to_array.hpp>
#include <boost/preprocessor/seq/transform.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
#include <boost/parameter/binding.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/accumulators/accumulators_fwd.hpp>
#include <boost/accumulators/framework/parameters/accumulator.hpp>
namespace boost { namespace accumulators
{
namespace detail
{
template<typename AccumulatorSet, typename Feature>
struct accumulator_set_result
{
typedef typename as_feature<Feature>::type feature_type;
typedef typename mpl::apply<AccumulatorSet, feature_type>::type::result_type type;
};
template<typename Args, typename Feature>
struct argument_pack_result
: accumulator_set_result<
typename remove_reference<
typename parameter::binding<Args, tag::accumulator>::type
>::type
, Feature
>
{
};
template<typename A, typename Feature>
struct extractor_result
: mpl::eval_if<
detail::is_accumulator_set<A>
, accumulator_set_result<A, Feature>
, argument_pack_result<A, Feature>
>
{
};
template<typename Feature, typename AccumulatorSet>
typename extractor_result<AccumulatorSet, Feature>::type
do_extract(AccumulatorSet const &acc, mpl::true_)
{
typedef typename as_feature<Feature>::type feature_type;
return extract_result<feature_type>(acc);
}
template<typename Feature, typename Args>
typename extractor_result<Args, Feature>::type
do_extract(Args const &args, mpl::false_)
{
typedef typename as_feature<Feature>::type feature_type;
return find_accumulator<feature_type>(args[accumulator]).result(args);
}
} // namespace detail
///////////////////////////////////////////////////////////////////////////////
/// Extracts the result associated with Feature from the specified accumulator_set.
template<typename Feature>
struct extractor
{
typedef extractor<Feature> this_type;
/// The result meta-function for determining the return type of the extractor
template<typename F>
struct result;
template<typename A1>
struct result<this_type(A1)>
: detail::extractor_result<A1, Feature>
{
};
/// Extract the result associated with Feature from the accumulator set
/// \param acc The accumulator set object from which to extract the result
template<typename Arg1>
typename detail::extractor_result<Arg1, Feature>::type
operator ()(Arg1 const &arg1) const
{
// Arg1 could be an accumulator_set or an argument pack containing
// an accumulator_set. Dispatch accordingly.
return detail::do_extract<Feature>(arg1, detail::is_accumulator_set<Arg1>());
}
/// \overload
///
/// \param a1 Optional named parameter to be passed to the accumulator's result() function.
template<typename AccumulatorSet, typename A1>
typename detail::extractor_result<AccumulatorSet, Feature>::type
operator ()(AccumulatorSet const &acc, A1 const &a1) const
{
BOOST_MPL_ASSERT((detail::is_accumulator_set<AccumulatorSet>));
typedef typename as_feature<Feature>::type feature_type;
return extract_result<feature_type>(acc, a1);
}
// ... other overloads generated by Boost.Preprocessor:
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_EXTRACTOR_FUN_OP(z, n, _) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
struct result<this_type(BOOST_PP_ENUM_PARAMS_Z(z, n, A))> \
: detail::extractor_result<A1, Feature> \
{}; \
template< \
typename AccumulatorSet \
BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
> \
typename detail::extractor_result<AccumulatorSet, Feature>::type \
operator ()( \
AccumulatorSet const &acc \
BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \
) const \
{ \
BOOST_MPL_ASSERT((detail::is_accumulator_set<AccumulatorSet>)); \
typedef typename as_feature<Feature>::type feature_type; \
return extract_result<feature_type>(acc BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a));\
}
BOOST_PP_REPEAT_FROM_TO(
2
, BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
, BOOST_ACCUMULATORS_EXTRACTOR_FUN_OP
, _
)
#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
/// \overload
///
template<typename AccumulatorSet, typename A1, typename A2, ...>
typename detail::extractor_result<AccumulatorSet, Feature>::type
operator ()(AccumulatorSet const &acc, A1 const &a1, A2 const &a2, ...);
#endif
};
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_ARRAY_REM(Array) \
BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_ARRAY_SIZE(Array), BOOST_PP_ARRAY_DATA(Array))
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_SEQ_REM(Seq) \
BOOST_ACCUMULATORS_ARRAY_REM(BOOST_PP_SEQ_TO_ARRAY(Seq))
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_ARGS_OP(s, data, elem) \
T ## s
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_PARAMS_OP(s, data, elem) \
elem T ## s
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq) \
Tag::Feature< \
BOOST_ACCUMULATORS_SEQ_REM( \
BOOST_PP_SEQ_TRANSFORM(BOOST_ACCUMULATORS_ARGS_OP, ~, ParamsSeq) \
) \
>
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN_IMPL(z, n, Tag, Feature, ParamsSeq) \
template< \
BOOST_ACCUMULATORS_SEQ_REM( \
BOOST_PP_SEQ_TRANSFORM(BOOST_ACCUMULATORS_PARAMS_OP, ~, ParamsSeq) \
) \
, typename Arg1 \
BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
> \
typename boost::accumulators::detail::extractor_result< \
Arg1 \
, BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq) \
>::type \
Feature(Arg1 const &arg1 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) ) \
{ \
typedef BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq) feature_type; \
return boost::accumulators::extractor<feature_type>()( \
arg1 BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a)); \
}
/// INTERNAL ONLY
///
#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN(z, n, _) \
BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN_IMPL( \
z \
, n \
, BOOST_PP_ARRAY_ELEM(0, _) \
, BOOST_PP_ARRAY_ELEM(1, _) \
, BOOST_PP_ARRAY_ELEM(2, _) \
)
#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(Tag, Feature, ParamSeq) \
BOOST_PP_REPEAT( \
BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS) \
, BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN \
, (3, (Tag, Feature, ParamSeq)) \
)
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,29 @@
///////////////////////////////////////////////////////////////////////////////
// features.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_08_12_2005
#define BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_08_12_2005
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/accumulators/accumulators_fwd.hpp>
namespace boost { namespace accumulators
{
///////////////////////////////////////////////////////////////////////////////
// features
//
template<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature)>
struct features
: mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Feature)>
{
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,20 @@
///////////////////////////////////////////////////////////////////////////////
// accumulator.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005
#include <boost/parameter/keyword.hpp>
namespace boost { namespace accumulators
{
BOOST_PARAMETER_KEYWORD(tag, accumulator)
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,20 @@
///////////////////////////////////////////////////////////////////////////////
// sample.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005
#include <boost/parameter/keyword.hpp>
namespace boost { namespace accumulators
{
BOOST_PARAMETER_KEYWORD(tag, sample)
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,21 @@
///////////////////////////////////////////////////////////////////////////////
// weight.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005
#include <boost/parameter/keyword.hpp>
namespace boost { namespace accumulators
{
// The weight of a single sample
BOOST_PARAMETER_KEYWORD(tag, weight)
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,21 @@
///////////////////////////////////////////////////////////////////////////////
// weights.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005
#include <boost/parameter/keyword.hpp>
namespace boost { namespace accumulators
{
// The weight accumulator
BOOST_PARAMETER_KEYWORD(tag, weights)
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,75 @@
// Copyright David Abrahams 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DETAIL_FUNCTION1_DWA200655_HPP
# define BOOST_DETAIL_FUNCTION1_DWA200655_HPP
# include <boost/concept_check.hpp>
# include <boost/type_traits/remove_reference.hpp>
# include <boost/type_traits/add_const.hpp>
# include <boost/mpl/apply.hpp>
namespace boost { namespace detail {
// A utility for creating unary function objects that play nicely with
// boost::result_of and that handle the forwarding problem.
//
// mpl::apply<F, A0>::type is expected to be a stateless function
// object that accepts an argument of type A0&. It is also expected
// to have a nested ::result_type identical to its return type.
template<typename F>
struct function1
{
template<typename Signature>
struct result
{};
template<typename This, typename A0>
struct result<This(A0)>
{
// How adding const to arguments handles rvalues.
//
// if A0 is arg0 is represents actual argument
// -------- ------- --------------------------
// T const & T const const T lvalue
// T & T non-const T lvalue
// T const T const const T rvalue
// T T const non-const T rvalue
typedef typename remove_reference<
typename add_const< A0 >::type
>::type arg0;
typedef typename mpl::apply1<F, arg0>::type impl;
typedef typename impl::result_type type;
};
// Handles mutable lvalues
template<typename A0>
typename result<function1(A0 &)>::type
operator ()(A0 &a0) const
{
typedef typename result<function1(A0 &)>::impl impl;
typedef typename result<function1(A0 &)>::type type;
typedef A0 &arg0;
BOOST_CONCEPT_ASSERT((UnaryFunction<impl, type, arg0>));
//boost::function_requires<UnaryFunctionConcept<impl, type, arg0> >();
return impl()(a0);
}
// Handles const lvalues and all rvalues
template<typename A0>
typename result<function1(A0 const &)>::type
operator ()(A0 const &a0) const
{
typedef typename result<function1(A0 const &)>::impl impl;
typedef typename result<function1(A0 const &)>::type type;
typedef A0 const &arg0;
BOOST_CONCEPT_ASSERT((UnaryFunction<impl, type, arg0>));
//boost::function_requires<UnaryFunctionConcept<impl, type, arg0> >();
return impl()(a0);
}
};
}} // namespace boost::detail
#endif // BOOST_DETAIL_FUNCTION1_DWA200655_HPP
@@ -0,0 +1,10 @@
// Copyright David Abrahams 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DETAIL_FUNCTION2_DWA200655_HPP
# define BOOST_DETAIL_FUNCTION2_DWA200655_HPP
# define args (2)
# include <boost/accumulators/numeric/detail/function_n.hpp>
#endif // BOOST_DETAIL_FUNCTION2_DWA200655_HPP
@@ -0,0 +1,10 @@
// Copyright David Abrahams 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DETAIL_FUNCTION3_DWA2006514_HPP
# define BOOST_DETAIL_FUNCTION3_DWA2006514_HPP
# define args (3)
# include <boost/accumulators/numeric/detail/function_n.hpp>
#endif // BOOST_DETAIL_FUNCTION3_DWA2006514_HPP
@@ -0,0 +1,10 @@
// Copyright David Abrahams 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DETAIL_FUNCTION4_DWA2006514_HPP
# define BOOST_DETAIL_FUNCTION4_DWA2006514_HPP
# define args (4)
# include <boost/accumulators/numeric/detail/function_n.hpp>
#endif // BOOST_DETAIL_FUNCTION4_DWA2006514_HPP
@@ -0,0 +1,148 @@
// Copyright David Abrahams 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// #include guards intentionally disabled.
// #ifndef BOOST_DETAIL_FUNCTION_N_DWA2006514_HPP
// # define BOOST_DETAIL_FUNCTION_N_DWA2006514_HPP
#include <boost/mpl/void.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/seq/fold_left.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/seq/for_each_product.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
namespace boost { namespace detail {
# define BOOST_DETAIL_default_arg(z, n, _) \
typedef mpl::void_ BOOST_PP_CAT(arg, n);
# define BOOST_DETAIL_function_arg(z, n, _) \
typedef typename remove_reference< \
typename add_const< BOOST_PP_CAT(A, n) >::type \
>::type BOOST_PP_CAT(arg, n);
#define BOOST_DETAIL_cat_arg_counts(s, state, n) \
BOOST_PP_IF( \
n \
, BOOST_PP_CAT(state, BOOST_PP_CAT(_, n)) \
, state \
) \
/**/
#define function_name \
BOOST_PP_SEQ_FOLD_LEFT( \
BOOST_DETAIL_cat_arg_counts \
, BOOST_PP_CAT(function, BOOST_PP_SEQ_HEAD(args)) \
, BOOST_PP_SEQ_TAIL(args)(0) \
) \
/**/
template<typename F>
struct function_name
{
BOOST_PP_REPEAT(
BOOST_MPL_LIMIT_METAFUNCTION_ARITY
, BOOST_DETAIL_default_arg
, ~
)
template<typename Signature>
struct result {};
#define BOOST_DETAIL_function_result(r, _, n) \
template<typename This BOOST_PP_ENUM_TRAILING_PARAMS(n, typename A)> \
struct result<This(BOOST_PP_ENUM_PARAMS(n, A))> \
{ \
BOOST_PP_REPEAT(n, BOOST_DETAIL_function_arg, ~) \
typedef \
typename BOOST_PP_CAT(mpl::apply, BOOST_MPL_LIMIT_METAFUNCTION_ARITY)<\
F \
BOOST_PP_ENUM_TRAILING_PARAMS( \
BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
, arg \
) \
>::type \
impl; \
typedef typename impl::result_type type; \
}; \
/**/
BOOST_PP_SEQ_FOR_EACH(BOOST_DETAIL_function_result, _, args)
# define arg_type(r, _, i, is_const) \
BOOST_PP_COMMA_IF(i) BOOST_PP_CAT(A, i) BOOST_PP_CAT(const_if, is_const) &
# define result_(r, n, constness) \
typename result< \
function_name( \
BOOST_PP_SEQ_FOR_EACH_I_R(r, arg_type, ~, constness) \
) \
> \
/**/
# define param(r, _, i, is_const) BOOST_PP_COMMA_IF(i) \
BOOST_PP_CAT(A, i) BOOST_PP_CAT(const_if, is_const) & BOOST_PP_CAT(x, i)
# define param_list(r, n, constness) \
BOOST_PP_SEQ_FOR_EACH_I_R(r, param, ~, constness)
# define call_operator(r, constness) \
template<BOOST_PP_ENUM_PARAMS(BOOST_PP_SEQ_SIZE(constness), typename A)> \
result_(r, BOOST_PP_SEQ_SIZE(constness), constness)::type \
operator ()( param_list(r, BOOST_PP_SEQ_SIZE(constness), constness) ) const \
{ \
typedef result_(r, BOOST_PP_SEQ_SIZE(constness), constness)::impl impl; \
return impl()(BOOST_PP_ENUM_PARAMS(BOOST_PP_SEQ_SIZE(constness), x)); \
} \
/**/
# define const_if0
# define const_if1 const
# define bits(z, n, _) ((0)(1))
# define gen_operator(r, _, n) \
BOOST_PP_SEQ_FOR_EACH_PRODUCT_R( \
r \
, call_operator \
, BOOST_PP_REPEAT(n, bits, ~) \
) \
/**/
BOOST_PP_SEQ_FOR_EACH(
gen_operator
, ~
, args
)
# undef bits
# undef const_if1
# undef const_if0
# undef call_operator
# undef param_list
# undef param
# undef result_
# undef default_
# undef arg_type
# undef gen_operator
# undef function_name
# undef args
};
}} // namespace boost::detail
//#endif // BOOST_DETAIL_FUNCTION_N_DWA2006514_HPP
@@ -0,0 +1,20 @@
// Copyright David Abrahams 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DETAIL_POD_SINGLETON_DWA200655_HPP
# define BOOST_DETAIL_POD_SINGLETON_DWA200655_HPP
namespace boost { namespace detail {
template<typename T>
struct pod_singleton
{
static T instance;
};
template<typename T>
T pod_singleton<T>::instance;
}} // namespace boost::detail
#endif // BOOST_DETAIL_POD_SINGLETON_DWA200655_HPP
@@ -0,0 +1,497 @@
///////////////////////////////////////////////////////////////////////////////
/// \file functional.hpp
///
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_NUMERIC_FUNCTIONAL_HPP_EAN_08_12_2005
#define BOOST_NUMERIC_FUNCTIONAL_HPP_EAN_08_12_2005
#include <limits>
#include <functional>
#include <boost/static_assert.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/and.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_empty.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/typeof/typeof.hpp>
#include <boost/accumulators/numeric/functional_fwd.hpp>
#include <boost/accumulators/numeric/detail/function1.hpp>
#include <boost/accumulators/numeric/detail/function2.hpp>
#include <boost/accumulators/numeric/detail/pod_singleton.hpp>
#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
# include <boost/accumulators/numeric/functional/vector.hpp>
#endif
#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
# include <boost/accumulators/numeric/functional/valarray.hpp>
#endif
#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
# include <boost/accumulators/numeric/functional/complex.hpp>
#endif
/// INTERNAL ONLY
///
#define BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
#ifdef BOOST_NUMERIC_FUNCTIONAL_DOXYGEN_INVOKED
// Hack to make Doxygen show the inheritance relationships
/// INTERNAL ONLY
///
namespace std
{
/// INTERNAL ONLY
///
template<class Arg, class Ret> struct unary_function {};
/// INTERNAL ONLY
///
template<class Left, class Right, class Ret> struct binary_function {};
}
#endif
namespace boost { namespace numeric
{
namespace functional
{
/// INTERNAL ONLY
///
template<typename A0, typename A1>
struct are_integral
: mpl::and_<is_integral<A0>, is_integral<A1> >
{};
template<typename Left, typename Right>
struct left_ref
{
typedef Left &type;
};
namespace detail
{
template<typename T>
T &lvalue_of();
}
}
// TODO: handle complex weight, valarray, MTL vectors
/// INTERNAL ONLY
///
#define BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(Name, Op) \
namespace functional \
{ \
template<typename Arg> \
struct result_of_ ## Name \
{ \
BOOST_TYPEOF_NESTED_TYPEDEF_TPL( \
nested \
, Op boost::numeric::functional::detail::lvalue_of<Arg>() \
) \
typedef typename nested::type type; \
}; \
template<typename Arg, typename EnableIf> \
struct Name ## _base \
: std::unary_function< \
typename remove_const<Arg>::type \
, typename result_of_ ## Name<Arg>::type \
> \
{ \
typename result_of_ ## Name<Arg>::type operator ()(Arg &arg) const \
{ \
return Op arg; \
} \
}; \
template<typename Arg, typename ArgTag> \
struct Name \
: Name ## _base<Arg, void> \
{}; \
} \
namespace op \
{ \
struct Name \
: boost::detail::function1<functional::Name<_, functional::tag<_> > > \
{}; \
} \
namespace \
{ \
op::Name const &Name = boost::detail::pod_singleton<op::Name>::instance; \
} \
/**/
/// INTERNAL ONLY
///
#define BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(Name, Op, RetType) \
namespace functional \
{ \
template<typename Left, typename Right, typename EnableIf> \
struct result_of_ ## Name \
{ \
RetType(Left, Op, Right) \
}; \
template<typename Left, typename Right, typename EnableIf> \
struct Name ## _base \
: std::binary_function< \
typename remove_const<Left>::type \
, typename remove_const<Right>::type \
, typename result_of_ ## Name<Left, Right>::type \
> \
{ \
typename result_of_ ## Name<Left, Right>::type \
operator ()(Left &left, Right &right) const \
{ \
return left Op right; \
} \
}; \
template<typename Left, typename Right, typename LeftTag, typename RightTag> \
struct Name \
: Name ## _base<Left, Right, void> \
{}; \
} \
namespace op \
{ \
struct Name \
: boost::detail::function2< \
functional::Name<_1, _2, functional::tag<_1>, functional::tag<_2> > \
> \
{}; \
} \
namespace \
{ \
op::Name const &Name = boost::detail::pod_singleton<op::Name>::instance; \
} \
/**/
/// INTERNAL ONLY
///
#define BOOST_NUMERIC_FUNCTIONAL_DEDUCED(Left, Op, Right) \
BOOST_TYPEOF_NESTED_TYPEDEF_TPL( \
nested \
, boost::numeric::functional::detail::lvalue_of<Left>() Op \
boost::numeric::functional::detail::lvalue_of<Right>() \
) \
typedef typename nested::type type; \
/**/
/// INTERNAL ONLY
///
#define BOOST_NUMERIC_FUNCTIONAL_LEFT(Left, Op, Right) \
typedef Left &type; \
/**/
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(plus, +, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(minus, -, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(multiplies, *, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(divides, /, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(modulus, %, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(greater, >, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(greater_equal, >=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(less, <, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(less_equal, <=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(equal_to, ==, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(not_equal_to, !=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(assign, =, BOOST_NUMERIC_FUNCTIONAL_LEFT)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(plus_assign, +=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(minus_assign, -=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(multiplies_assign, *=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(divides_assign, /=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(modulus_assign, %=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(unary_plus, +)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(unary_minus, -)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(complement, ~)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(logical_not, !)
#undef BOOST_NUMERIC_FUNCTIONAL_LEFT
#undef BOOST_NUMERIC_FUNCTIONAL_DEDUCED
#undef BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP
#undef BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP
namespace functional
{
template<typename Left, typename Right, typename EnableIf>
struct min_assign_base
: std::binary_function<Left, Right, void>
{
void operator ()(Left &left, Right &right) const
{
if(numeric::less(right, left))
{
left = right;
}
}
};
template<typename Left, typename Right, typename EnableIf>
struct max_assign_base
: std::binary_function<Left, Right, void>
{
void operator ()(Left &left, Right &right) const
{
if(numeric::greater(right, left))
{
left = right;
}
}
};
template<typename Left, typename Right, typename EnableIf>
struct average_base
: functional::divides<Left, Right>
{};
// partial specialization that promotes the arguments to double for
// integral division.
template<typename Left, typename Right>
struct average_base<Left, Right, typename enable_if<are_integral<Left, Right> >::type>
: functional::divides<double const, double const>
{};
template<typename To, typename From, typename EnableIf>
struct promote_base
: std::unary_function<From, To>
{
To operator ()(From &from) const
{
return from;
}
};
template<typename ToFrom>
struct promote_base<ToFrom, ToFrom, void>
: std::unary_function<ToFrom, ToFrom>
{
ToFrom &operator ()(ToFrom &tofrom)
{
return tofrom;
}
};
template<typename Arg, typename EnableIf>
struct as_min_base
: std::unary_function<Arg, typename remove_const<Arg>::type>
{
BOOST_STATIC_ASSERT(std::numeric_limits<typename remove_const<Arg>::type>::is_specialized);
typename remove_const<Arg>::type operator ()(Arg &) const
{
return (std::numeric_limits<typename remove_const<Arg>::type>::min)();
}
};
template<typename Arg>
struct as_min_base<Arg, typename enable_if<is_floating_point<Arg> >::type>
: std::unary_function<Arg, typename remove_const<Arg>::type>
{
BOOST_STATIC_ASSERT(std::numeric_limits<typename remove_const<Arg>::type>::is_specialized);
typename remove_const<Arg>::type operator ()(Arg &) const
{
return -(std::numeric_limits<typename remove_const<Arg>::type>::max)();
}
};
template<typename Arg, typename EnableIf>
struct as_max_base
: std::unary_function<Arg, typename remove_const<Arg>::type>
{
BOOST_STATIC_ASSERT(std::numeric_limits<typename remove_const<Arg>::type>::is_specialized);
typename remove_const<Arg>::type operator ()(Arg &) const
{
return (std::numeric_limits<typename remove_const<Arg>::type>::max)();
}
};
template<typename Arg, typename EnableIf>
struct as_zero_base
: std::unary_function<Arg, typename remove_const<Arg>::type>
{
typename remove_const<Arg>::type operator ()(Arg &) const
{
return numeric::zero<typename remove_const<Arg>::type>::value;
}
};
template<typename Arg, typename EnableIf>
struct as_one_base
: std::unary_function<Arg, typename remove_const<Arg>::type>
{
typename remove_const<Arg>::type operator ()(Arg &) const
{
return numeric::one<typename remove_const<Arg>::type>::value;
}
};
template<typename To, typename From, typename ToTag, typename FromTag>
struct promote
: promote_base<To, From, void>
{};
template<typename Left, typename Right, typename LeftTag, typename RightTag>
struct min_assign
: min_assign_base<Left, Right, void>
{};
template<typename Left, typename Right, typename LeftTag, typename RightTag>
struct max_assign
: max_assign_base<Left, Right, void>
{};
template<typename Left, typename Right, typename LeftTag, typename RightTag>
struct average
: average_base<Left, Right, void>
{};
template<typename Arg, typename Tag>
struct as_min
: as_min_base<Arg, void>
{};
template<typename Arg, typename Tag>
struct as_max
: as_max_base<Arg, void>
{};
template<typename Arg, typename Tag>
struct as_zero
: as_zero_base<Arg, void>
{};
template<typename Arg, typename Tag>
struct as_one
: as_one_base<Arg, void>
{};
}
namespace op
{
template<typename To>
struct promote
: boost::detail::function1<functional::promote<To, _, typename functional::tag<To>::type, functional::tag<_> > >
{};
struct min_assign
: boost::detail::function2<functional::min_assign<_1, _2, functional::tag<_1>, functional::tag<_2> > >
{};
struct max_assign
: boost::detail::function2<functional::max_assign<_1, _2, functional::tag<_1>, functional::tag<_2> > >
{};
struct average
: boost::detail::function2<functional::average<_1, _2, functional::tag<_1>, functional::tag<_2> > >
{};
struct as_min
: boost::detail::function1<functional::as_min<_, functional::tag<_> > >
{};
struct as_max
: boost::detail::function1<functional::as_max<_, functional::tag<_> > >
{};
struct as_zero
: boost::detail::function1<functional::as_zero<_, functional::tag<_> > >
{};
struct as_one
: boost::detail::function1<functional::as_one<_, functional::tag<_> > >
{};
}
namespace
{
op::min_assign const &min_assign = boost::detail::pod_singleton<op::min_assign>::instance;
op::max_assign const &max_assign = boost::detail::pod_singleton<op::max_assign>::instance;
op::average const &average = boost::detail::pod_singleton<op::average>::instance;
op::as_min const &as_min = boost::detail::pod_singleton<op::as_min>::instance;
op::as_max const &as_max = boost::detail::pod_singleton<op::as_max>::instance;
op::as_zero const &as_zero = boost::detail::pod_singleton<op::as_zero>::instance;
op::as_one const &as_one = boost::detail::pod_singleton<op::as_one>::instance;
}
///////////////////////////////////////////////////////////////////////////////
// promote
template<typename To, typename From>
typename lazy_disable_if<is_const<From>, mpl::if_<is_same<To, From>, To &, To> >::type
promote(From &from)
{
return functional::promote<To, From>()(from);
}
template<typename To, typename From>
typename mpl::if_<is_same<To const, From const>, To const &, To const>::type
promote(From const &from)
{
return functional::promote<To const, From const>()(from);
}
template<typename T>
struct default_
{
typedef default_ type;
typedef T value_type;
static T const value;
operator T const & () const
{
return default_::value;
}
};
template<typename T>
T const default_<T>::value = T();
template<typename T>
struct one
{
typedef one type;
typedef T value_type;
static T const value;
operator T const & () const
{
return one::value;
}
};
template<typename T>
T const one<T>::value = T(1);
template<typename T>
struct zero
{
typedef zero type;
typedef T value_type;
static T const value;
operator T const & () const
{
return zero::value;
}
};
template<typename T>
T const zero<T>::value = T();
template<typename T>
struct one_or_default
: mpl::if_<is_empty<T>, default_<T>, one<T> >::type
{};
template<typename T>
struct zero_or_default
: mpl::if_<is_empty<T>, default_<T>, zero<T> >::type
{};
}} // namespace boost::numeric
#endif
@@ -0,0 +1,82 @@
///////////////////////////////////////////////////////////////////////////////
/// \file complex.hpp
///
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
#define BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
#ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
# error Include this file before boost/accumulators/numeric/functional.hpp
#endif
#include <complex>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/typeof/std/complex.hpp>
#include <boost/accumulators/numeric/functional_fwd.hpp>
namespace boost { namespace numeric { namespace operators
{
// So that the stats compile when Sample type is std::complex
template<typename T, typename U>
typename
disable_if<
mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
, std::complex<T>
>::type
operator *(std::complex<T> ri, U const &u)
{
// BUGBUG promote result to typeof(T()*u) ?
return ri *= static_cast<T>(u);
}
template<typename T, typename U>
typename
disable_if<
mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
, std::complex<T>
>::type
operator /(std::complex<T> ri, U const &u)
{
// BUGBUG promote result to typeof(T()*u) ?
return ri /= static_cast<T>(u);
}
}}} // namespace boost::numeric::operators
namespace boost { namespace numeric
{
namespace detail
{
template<typename T>
struct one_complex
{
static std::complex<T> const value;
};
template<typename T>
std::complex<T> const one_complex<T>::value
= std::complex<T>(numeric::one<T>::value, numeric::one<T>::value);
}
/// INTERNAL ONLY
///
template<typename T>
struct one<std::complex<T> >
: detail::one_complex<T>
{
typedef one type;
typedef std::complex<T> value_type;
operator value_type const & () const
{
return detail::one_complex<T>::value;
}
};
}} // namespace boost::numeric
#endif
@@ -0,0 +1,360 @@
///////////////////////////////////////////////////////////////////////////////
/// \file valarray.hpp
///
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_NUMERIC_FUNCTIONAL_VALARRAY_HPP_EAN_12_12_2005
#define BOOST_NUMERIC_FUNCTIONAL_VALARRAY_HPP_EAN_12_12_2005
#ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
# error Include this file before boost/accumulators/numeric/functional.hpp
#endif
#include <valarray>
#include <functional>
#include <boost/assert.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_scalar.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/typeof/std/valarray.hpp>
#include <boost/accumulators/numeric/functional_fwd.hpp>
namespace boost { namespace numeric
{
namespace operators
{
namespace acc_detail
{
template<typename Fun>
struct make_valarray
{
typedef std::valarray<typename Fun::result_type> type;
};
}
///////////////////////////////////////////////////////////////////////////////
// Handle valarray<Left> / Right where Right is a scalar and Right != Left.
template<typename Left, typename Right>
typename lazy_enable_if<
mpl::and_<is_scalar<Right>, mpl::not_<is_same<Left, Right> > >
, acc_detail::make_valarray<functional::divides<Left, Right> >
>::type
operator /(std::valarray<Left> const &left, Right const &right)
{
typedef typename functional::divides<Left, Right>::result_type value_type;
std::valarray<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::divides(left[i], right);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle valarray<Left> * Right where Right is a scalar and Right != Left.
template<typename Left, typename Right>
typename lazy_enable_if<
mpl::and_<is_scalar<Right>, mpl::not_<is_same<Left, Right> > >
, acc_detail::make_valarray<functional::multiplies<Left, Right> >
>::type
operator *(std::valarray<Left> const &left, Right const &right)
{
typedef typename functional::multiplies<Left, Right>::result_type value_type;
std::valarray<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::multiplies(left[i], right);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle valarray<Left> + valarray<Right> where Right != Left.
template<typename Left, typename Right>
typename lazy_disable_if<
is_same<Left, Right>
, acc_detail::make_valarray<functional::plus<Left, Right> >
>::type
operator +(std::valarray<Left> const &left, std::valarray<Right> const &right)
{
typedef typename functional::plus<Left, Right>::result_type value_type;
std::valarray<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::plus(left[i], right[i]);
}
return result;
}
}
namespace functional
{
struct std_valarray_tag;
template<typename T>
struct tag<std::valarray<T> >
{
typedef std_valarray_tag type;
};
#ifdef __GLIBCXX__
template<typename T, typename U>
struct tag<std::_Expr<T, U> >
{
typedef std_valarray_tag type;
};
#endif
/// INTERNAL ONLY
///
// This is necessary because the GCC stdlib uses expression templates, and
// typeof(som-valarray-expression) is not an instance of std::valarray
#define BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(Name, Op) \
template<typename Left, typename Right> \
struct Name<Left, Right, std_valarray_tag, std_valarray_tag> \
: std::binary_function< \
Left \
, Right \
, std::valarray< \
typename Name< \
typename Left::value_type \
, typename Right::value_type \
>::result_type \
> \
> \
{ \
typedef typename Left::value_type left_value_type; \
typedef typename Right::value_type right_value_type; \
typedef \
std::valarray< \
typename Name<left_value_type, right_value_type>::result_type \
> \
result_type; \
result_type \
operator ()(Left &left, Right &right) const \
{ \
return numeric::promote<std::valarray<left_value_type> >(left) \
Op numeric::promote<std::valarray<right_value_type> >(right); \
} \
}; \
template<typename Left, typename Right> \
struct Name<Left, Right, std_valarray_tag, void> \
: std::binary_function< \
Left \
, Right \
, std::valarray< \
typename Name<typename Left::value_type, Right>::result_type \
> \
> \
{ \
typedef typename Left::value_type left_value_type; \
typedef \
std::valarray< \
typename Name<left_value_type, Right>::result_type \
> \
result_type; \
result_type \
operator ()(Left &left, Right &right) const \
{ \
return numeric::promote<std::valarray<left_value_type> >(left) Op right;\
} \
}; \
template<typename Left, typename Right> \
struct Name<Left, Right, void, std_valarray_tag> \
: std::binary_function< \
Left \
, Right \
, std::valarray< \
typename Name<Left, typename Right::value_type>::result_type \
> \
> \
{ \
typedef typename Right::value_type right_value_type; \
typedef \
std::valarray< \
typename Name<Left, right_value_type>::result_type \
> \
result_type; \
result_type \
operator ()(Left &left, Right &right) const \
{ \
return left Op numeric::promote<std::valarray<right_value_type> >(right);\
} \
};
BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(plus, +)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(minus, -)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(multiplies, *)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(divides, /)
BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(modulus, %)
#undef BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP
///////////////////////////////////////////////////////////////////////////////
// element-wise min of std::valarray
template<typename Left, typename Right>
struct min_assign<Left, Right, std_valarray_tag, std_valarray_tag>
: std::binary_function<Left, Right, void>
{
void operator ()(Left &left, Right &right) const
{
BOOST_ASSERT(left.size() == right.size());
for(std::size_t i = 0, size = left.size(); i != size; ++i)
{
if(numeric::less(right[i], left[i]))
{
left[i] = right[i];
}
}
}
};
///////////////////////////////////////////////////////////////////////////////
// element-wise max of std::valarray
template<typename Left, typename Right>
struct max_assign<Left, Right, std_valarray_tag, std_valarray_tag>
: std::binary_function<Left, Right, void>
{
void operator ()(Left &left, Right &right) const
{
BOOST_ASSERT(left.size() == right.size());
for(std::size_t i = 0, size = left.size(); i != size; ++i)
{
if(numeric::greater(right[i], left[i]))
{
left[i] = right[i];
}
}
}
};
// partial specialization of numeric::average<> for std::valarray.
template<typename Left, typename Right, typename RightTag>
struct average<Left, Right, std_valarray_tag, RightTag>
: mpl::if_<
are_integral<typename Left::value_type, Right>
, divides<Left, double const>
, divides<Left, Right>
>::type
{};
// promote
template<typename To, typename From>
struct promote<To, From, std_valarray_tag, std_valarray_tag>
: std::unary_function<From, To>
{
To operator ()(From &arr) const
{
typename remove_const<To>::type res(arr.size());
for(std::size_t i = 0, size = arr.size(); i != size; ++i)
{
res[i] = numeric::promote<typename To::value_type>(arr[i]);
}
return res;
}
};
template<typename ToFrom>
struct promote<ToFrom, ToFrom, std_valarray_tag, std_valarray_tag>
: std::unary_function<ToFrom, ToFrom>
{
ToFrom &operator ()(ToFrom &tofrom) const
{
return tofrom;
}
};
// for "promoting" a std::valarray<bool> to a bool, useful for
// comparing 2 valarrays for equality:
// if(numeric::promote<bool>(a == b))
template<typename From>
struct promote<bool, From, void, std_valarray_tag>
: std::unary_function<From, bool>
{
bool operator ()(From &arr) const
{
BOOST_MPL_ASSERT((is_same<bool, typename From::value_type>));
for(std::size_t i = 0, size = arr.size(); i != size; ++i)
{
if(!arr[i])
{
return false;
}
}
return true;
}
};
template<typename From>
struct promote<bool const, From, void, std_valarray_tag>
: promote<bool, From, void, std_valarray_tag>
{};
///////////////////////////////////////////////////////////////////////////////
// functional::as_min
template<typename T>
struct as_min<T, std_valarray_tag>
: std::unary_function<T, typename remove_const<T>::type>
{
typename remove_const<T>::type operator ()(T &arr) const
{
return 0 == arr.size()
? T()
: T(numeric::as_min(arr[0]), arr.size());
}
};
///////////////////////////////////////////////////////////////////////////////
// functional::as_max
template<typename T>
struct as_max<T, std_valarray_tag>
: std::unary_function<T, typename remove_const<T>::type>
{
typename remove_const<T>::type operator ()(T &arr) const
{
return 0 == arr.size()
? T()
: T(numeric::as_max(arr[0]), arr.size());
}
};
///////////////////////////////////////////////////////////////////////////////
// functional::as_zero
template<typename T>
struct as_zero<T, std_valarray_tag>
: std::unary_function<T, typename remove_const<T>::type>
{
typename remove_const<T>::type operator ()(T &arr) const
{
return 0 == arr.size()
? T()
: T(numeric::as_zero(arr[0]), arr.size());
}
};
///////////////////////////////////////////////////////////////////////////////
// functional::as_one
template<typename T>
struct as_one<T, std_valarray_tag>
: std::unary_function<T, typename remove_const<T>::type>
{
typename remove_const<T>::type operator ()(T &arr) const
{
return 0 == arr.size()
? T()
: T(numeric::as_one(arr[0]), arr.size());
}
};
} // namespace functional
}} // namespace boost::numeric
#endif
@@ -0,0 +1,329 @@
///////////////////////////////////////////////////////////////////////////////
/// \file vector.hpp
///
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_NUMERIC_FUNCTIONAL_VECTOR_HPP_EAN_12_12_2005
#define BOOST_NUMERIC_FUNCTIONAL_VECTOR_HPP_EAN_12_12_2005
#ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
# error Include this file before boost/accumulators/numeric/functional.hpp
#endif
#include <vector>
#include <functional>
#include <boost/assert.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_scalar.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/typeof/std/vector.hpp>
#include <boost/accumulators/numeric/functional_fwd.hpp>
namespace boost { namespace numeric
{
namespace operators
{
namespace acc_detail
{
template<typename Fun>
struct make_vector
{
typedef std::vector<typename Fun::result_type> type;
};
}
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> / Right where Right is a scalar.
template<typename Left, typename Right>
typename lazy_enable_if<
is_scalar<Right>
, acc_detail::make_vector<functional::divides<Left, Right> >
>::type
operator /(std::vector<Left> const &left, Right const &right)
{
typedef typename functional::divides<Left, Right>::result_type value_type;
std::vector<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::divides(left[i], right);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> / vector<Right>.
template<typename Left, typename Right>
std::vector<typename functional::divides<Left, Right>::result_type>
operator /(std::vector<Left> const &left, std::vector<Right> const &right)
{
typedef typename functional::divides<Left, Right>::result_type value_type;
std::vector<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::divides(left[i], right[i]);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> * Right where Right is a scalar.
template<typename Left, typename Right>
typename lazy_enable_if<
is_scalar<Right>
, acc_detail::make_vector<functional::multiplies<Left, Right> >
>::type
operator *(std::vector<Left> const &left, Right const &right)
{
typedef typename functional::multiplies<Left, Right>::result_type value_type;
std::vector<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::multiplies(left[i], right);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle Left * vector<Right> where Left is a scalar.
template<typename Left, typename Right>
typename lazy_enable_if<
is_scalar<Left>
, acc_detail::make_vector<functional::multiplies<Left, Right> >
>::type
operator *(Left const &left, std::vector<Right> const &right)
{
typedef typename functional::multiplies<Left, Right>::result_type value_type;
std::vector<value_type> result(right.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::multiplies(left, right[i]);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> * vector<Right>
template<typename Left, typename Right>
std::vector<typename functional::multiplies<Left, Right>::result_type>
operator *(std::vector<Left> const &left, std::vector<Right> const &right)
{
typedef typename functional::multiplies<Left, Right>::result_type value_type;
std::vector<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::multiplies(left[i], right[i]);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> + vector<Right>
template<typename Left, typename Right>
std::vector<typename functional::plus<Left, Right>::result_type>
operator +(std::vector<Left> const &left, std::vector<Right> const &right)
{
typedef typename functional::plus<Left, Right>::result_type value_type;
std::vector<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::plus(left[i], right[i]);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> - vector<Right>
template<typename Left, typename Right>
std::vector<typename functional::minus<Left, Right>::result_type>
operator -(std::vector<Left> const &left, std::vector<Right> const &right)
{
typedef typename functional::minus<Left, Right>::result_type value_type;
std::vector<value_type> result(left.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::minus(left[i], right[i]);
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> += vector<Left>
template<typename Left>
std::vector<Left> &
operator +=(std::vector<Left> &left, std::vector<Left> const &right)
{
BOOST_ASSERT(left.size() == right.size());
for(std::size_t i = 0, size = left.size(); i != size; ++i)
{
numeric::plus_assign(left[i], right[i]);
}
return left;
}
///////////////////////////////////////////////////////////////////////////////
// Handle -vector<Arg>
template<typename Arg>
std::vector<typename functional::unary_minus<Arg>::result_type>
operator -(std::vector<Arg> const &arg)
{
typedef typename functional::unary_minus<Arg>::result_type value_type;
std::vector<value_type> result(arg.size());
for(std::size_t i = 0, size = result.size(); i != size; ++i)
{
result[i] = numeric::unary_minus(arg[i]);
}
return result;
}
}
namespace functional
{
struct std_vector_tag;
template<typename T, typename Al>
struct tag<std::vector<T, Al> >
{
typedef std_vector_tag type;
};
///////////////////////////////////////////////////////////////////////////////
// element-wise min of std::vector
template<typename Left, typename Right>
struct min_assign<Left, Right, std_vector_tag, std_vector_tag>
: std::binary_function<Left, Right, void>
{
void operator ()(Left &left, Right &right) const
{
BOOST_ASSERT(left.size() == right.size());
for(std::size_t i = 0, size = left.size(); i != size; ++i)
{
if(numeric::less(right[i], left[i]))
{
left[i] = right[i];
}
}
}
};
///////////////////////////////////////////////////////////////////////////////
// element-wise max of std::vector
template<typename Left, typename Right>
struct max_assign<Left, Right, std_vector_tag, std_vector_tag>
: std::binary_function<Left, Right, void>
{
void operator ()(Left &left, Right &right) const
{
BOOST_ASSERT(left.size() == right.size());
for(std::size_t i = 0, size = left.size(); i != size; ++i)
{
if(numeric::greater(right[i], left[i]))
{
left[i] = right[i];
}
}
}
};
// partial specialization for std::vector.
template<typename Left, typename Right>
struct average<Left, Right, std_vector_tag, void>
: mpl::if_<
are_integral<typename Left::value_type, Right>
, divides<Left, double const>
, divides<Left, Right>
>::type
{};
// promote
template<typename To, typename From>
struct promote<To, From, std_vector_tag, std_vector_tag>
: std::unary_function<From, To>
{
To operator ()(From &arr) const
{
typename remove_const<To>::type res(arr.size());
for(std::size_t i = 0, size = arr.size(); i != size; ++i)
{
res[i] = numeric::promote<typename To::value_type>(arr[i]);
}
return res;
}
};
template<typename ToFrom>
struct promote<ToFrom, ToFrom, std_vector_tag, std_vector_tag>
: std::unary_function<ToFrom, ToFrom>
{
ToFrom &operator ()(ToFrom &tofrom) const
{
return tofrom;
}
};
///////////////////////////////////////////////////////////////////////////////
// functional::as_min
template<typename T>
struct as_min<T, std_vector_tag>
: std::unary_function<T, typename remove_const<T>::type>
{
typename remove_const<T>::type operator ()(T &arr) const
{
return 0 == arr.size()
? T()
: T(arr.size(), numeric::as_min(arr[0]));
}
};
///////////////////////////////////////////////////////////////////////////////
// functional::as_max
template<typename T>
struct as_max<T, std_vector_tag>
: std::unary_function<T, typename remove_const<T>::type>
{
typename remove_const<T>::type operator ()(T &arr) const
{
return 0 == arr.size()
? T()
: T(arr.size(), numeric::as_max(arr[0]));
}
};
///////////////////////////////////////////////////////////////////////////////
// functional::as_zero
template<typename T>
struct as_zero<T, std_vector_tag>
: std::unary_function<T, typename remove_const<T>::type>
{
typename remove_const<T>::type operator ()(T &arr) const
{
return 0 == arr.size()
? T()
: T(arr.size(), numeric::as_zero(arr[0]));
}
};
///////////////////////////////////////////////////////////////////////////////
// functional::as_one
template<typename T>
struct as_one<T, std_vector_tag>
: std::unary_function<T, typename remove_const<T>::type>
{
typename remove_const<T>::type operator ()(T &arr) const
{
return 0 == arr.size()
? T()
: T(arr.size(), numeric::as_one(arr[0]));
}
};
} // namespace functional
}} // namespace boost::numeric
#endif
@@ -0,0 +1,221 @@
///////////////////////////////////////////////////////////////////////////////
/// \file functional_fwd.hpp
///
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_NUMERIC_FUNCTIONAL_FWD_HPP_EAN_08_12_2005
#define BOOST_NUMERIC_FUNCTIONAL_FWD_HPP_EAN_08_12_2005
#include <boost/mpl/if.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_const.hpp>
namespace boost { namespace numeric
{
// For using directives -- this namespace may be re-opened elsewhere
namespace operators
{}
namespace op
{
using mpl::_;
using mpl::_1;
using mpl::_2;
}
namespace functional
{
using namespace operators;
template<typename T>
struct tag
{
typedef void type;
};
template<typename T>
struct tag<T const>
: tag<T>
{};
template<typename T>
struct tag<T volatile>
: tag<T>
{};
template<typename T>
struct tag<T const volatile>
: tag<T>
{};
template<typename T>
struct static_;
template<typename A0, typename A1>
struct are_integral;
}
/// INTERNAL ONLY
///
#define BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(Name, Op) \
namespace functional \
{ \
template<typename Arg, typename EnableIf = void> \
struct Name ## _base; \
template<typename Arg, typename ArgTag = typename tag<Arg>::type> \
struct Name; \
} \
namespace op \
{ \
struct Name; \
} \
namespace \
{ \
extern op::Name const &Name; \
}
/// INTERNAL ONLY
///
#define BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(Name) \
namespace functional \
{ \
template<typename Left, typename Right, typename EnableIf = void> \
struct result_of_ ## Name; \
template<typename Left, typename Right, typename EnableIf = void> \
struct Name ## _base; \
template< \
typename Left \
, typename Right \
, typename LeftTag = typename tag<Left>::type \
, typename RightTag = typename tag<Right>::type \
> \
struct Name; \
} \
namespace op \
{ \
struct Name; \
} \
namespace \
{ \
extern op::Name const &Name; \
}
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(plus)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(minus)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(multiplies)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(divides)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(modulus)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(greater)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(greater_equal)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(less)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(less_equal)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(equal_to)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(not_equal_to)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(assign)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(plus_assign)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(minus_assign)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(multiplies_assign)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(divides_assign)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(modulus_assign)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(unary_plus, +)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(unary_minus, -)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(complement, ~)
BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(logical_not, !)
#undef BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP
#undef BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP
namespace functional
{
template<typename To, typename From, typename EnableIf = void>
struct promote_base;
template<typename Left, typename Right, typename EnableIf = void>
struct min_assign_base;
template<typename Left, typename Right, typename EnableIf = void>
struct max_assign_base;
template<typename Left, typename Right, typename EnableIf = void>
struct average_base;
template<typename Arg, typename EnableIf = void>
struct as_min_base;
template<typename Arg, typename EnableIf = void>
struct as_max_base;
template<typename Arg, typename EnableIf = void>
struct as_zero_base;
template<typename Arg, typename EnableIf = void>
struct as_one_base;
template<typename To, typename From, typename ToTag = typename tag<To>::type, typename FromTag = typename tag<From>::type>
struct promote;
template<typename Left, typename Right, typename LeftTag = typename tag<Left>::type, typename RightTag = typename tag<Right>::type>
struct min_assign;
template<typename Left, typename Right, typename LeftTag = typename tag<Left>::type, typename RightTag = typename tag<Right>::type>
struct max_assign;
template<typename Left, typename Right, typename LeftTag = typename tag<Left>::type, typename RightTag = typename tag<Right>::type>
struct average;
template<typename Arg, typename Tag = typename tag<Arg>::type>
struct as_min;
template<typename Arg, typename Tag = typename tag<Arg>::type>
struct as_max;
template<typename Arg, typename Tag = typename tag<Arg>::type>
struct as_zero;
template<typename Arg, typename Tag = typename tag<Arg>::type>
struct as_one;
}
namespace op
{
template<typename To>
struct promote;
struct min_assign;
struct max_assign;
struct average;
struct as_min;
struct as_max;
struct as_zero;
struct as_one;
}
namespace
{
extern op::min_assign const &min_assign;
extern op::max_assign const &max_assign;
extern op::average const &average;
extern op::as_min const &as_min;
extern op::as_max const &as_max;
extern op::as_zero const &as_zero;
extern op::as_one const &as_one;
}
template<typename To, typename From>
typename lazy_disable_if<is_const<From>, mpl::if_<is_same<To, From>, To &, To> >::type
promote(From &from);
template<typename To, typename From>
typename mpl::if_<is_same<To const, From const>, To const &, To const>::type
promote(From const &from);
template<typename T>
struct default_;
template<typename T>
struct one;
template<typename T>
struct zero;
template<typename T>
struct one_or_default;
template<typename T>
struct zero_or_default;
}} // namespace boost::numeric
#endif
@@ -0,0 +1,61 @@
///////////////////////////////////////////////////////////////////////////////
/// \file statistics.hpp
/// Includes all of the Statistical Accumulators Library
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_HPP_EAN_01_17_2006
#define BOOST_ACCUMULATORS_STATISTICS_HPP_EAN_01_17_2006
#include <boost/accumulators/statistics/count.hpp>
#include <boost/accumulators/statistics/covariance.hpp>
#include <boost/accumulators/statistics/density.hpp>
#include <boost/accumulators/statistics/error_of.hpp>
#include <boost/accumulators/statistics/error_of_mean.hpp>
#include <boost/accumulators/statistics/extended_p_square.hpp>
#include <boost/accumulators/statistics/extended_p_square_quantile.hpp>
#include <boost/accumulators/statistics/kurtosis.hpp>
#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/median.hpp>
#include <boost/accumulators/statistics/min.hpp>
#include <boost/accumulators/statistics/moment.hpp>
#include <boost/accumulators/statistics/peaks_over_threshold.hpp>
#include <boost/accumulators/statistics/pot_tail_mean.hpp>
#include <boost/accumulators/statistics/pot_quantile.hpp>
#include <boost/accumulators/statistics/p_square_cumul_dist.hpp>
#include <boost/accumulators/statistics/p_square_quantile.hpp>
#include <boost/accumulators/statistics/skewness.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/sum.hpp>
#include <boost/accumulators/statistics/sum_kahan.hpp>
#include <boost/accumulators/statistics/tail.hpp>
#include <boost/accumulators/statistics/tail_quantile.hpp>
#include <boost/accumulators/statistics/tail_mean.hpp>
#include <boost/accumulators/statistics/tail_variate.hpp>
#include <boost/accumulators/statistics/tail_variate_means.hpp>
#include <boost/accumulators/statistics/variance.hpp>
#include <boost/accumulators/statistics/weighted_covariance.hpp>
#include <boost/accumulators/statistics/weighted_density.hpp>
#include <boost/accumulators/statistics/weighted_kurtosis.hpp>
#include <boost/accumulators/statistics/weighted_extended_p_square.hpp>
#include <boost/accumulators/statistics/weighted_mean.hpp>
#include <boost/accumulators/statistics/weighted_median.hpp>
#include <boost/accumulators/statistics/weighted_moment.hpp>
#include <boost/accumulators/statistics/weighted_peaks_over_threshold.hpp>
#include <boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp>
#include <boost/accumulators/statistics/weighted_p_square_quantile.hpp>
#include <boost/accumulators/statistics/weighted_skewness.hpp>
#include <boost/accumulators/statistics/weighted_sum.hpp>
#include <boost/accumulators/statistics/weighted_sum_kahan.hpp>
#include <boost/accumulators/statistics/weighted_tail_quantile.hpp>
#include <boost/accumulators/statistics/weighted_tail_mean.hpp>
#include <boost/accumulators/statistics/weighted_tail_variate_means.hpp>
#include <boost/accumulators/statistics/weighted_variance.hpp>
#include <boost/accumulators/statistics/with_error.hpp>
#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
#include <boost/accumulators/statistics/variates/covariate.hpp>
#endif
@@ -0,0 +1,80 @@
///////////////////////////////////////////////////////////////////////////////
// count.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005
#include <boost/mpl/always.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
namespace boost { namespace accumulators
{
namespace impl
{
///////////////////////////////////////////////////////////////////////////////
// count_impl
struct count_impl
: accumulator_base
{
// for boost::result_of
typedef std::size_t result_type;
count_impl(dont_care)
: cnt(0)
{
}
void operator ()(dont_care)
{
++this->cnt;
}
result_type result(dont_care) const
{
return this->cnt;
}
private:
std::size_t cnt;
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::count
//
namespace tag
{
struct count
: depends_on<>
{
/// INTERNAL ONLY
///
typedef mpl::always<accumulators::impl::count_impl> impl;
};
}
///////////////////////////////////////////////////////////////////////////////
// extract::count
//
namespace extract
{
extractor<tag::count> const count = {};
BOOST_ACCUMULATORS_IGNORE_GLOBAL(count)
}
using extract::count;
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,220 @@
///////////////////////////////////////////////////////////////////////////////
// covariance.hpp
//
// Copyright 2006 Daniel Egloff, Olivier Gygi. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_COVARIANCE_HPP_DE_01_01_2006
#define BOOST_ACCUMULATORS_STATISTICS_COVARIANCE_HPP_DE_01_01_2006
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <complex>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/range.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/type_traits/is_scalar.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/numeric/functional.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#include <boost/accumulators/statistics/count.hpp>
#include <boost/accumulators/statistics/mean.hpp>
namespace boost { namespace numeric
{
namespace functional
{
struct std_vector_tag;
///////////////////////////////////////////////////////////////////////////////
// functional::outer_product
template<typename Left, typename Right, typename EnableIf = void>
struct outer_product_base
: functional::multiplies<Left, Right>
{};
template<typename Left, typename Right, typename LeftTag = typename tag<Left>::type, typename RightTag = typename tag<Right>::type>
struct outer_product
: outer_product_base<Left, Right, void>
{};
template<typename Left, typename Right>
struct outer_product<Left, Right, std_vector_tag, std_vector_tag>
: std::binary_function<
Left
, Right
, ublas::matrix<
typename functional::multiplies<
typename Left::value_type
, typename Right::value_type
>::result_type
>
>
{
typedef
ublas::matrix<
typename functional::multiplies<
typename Left::value_type
, typename Right::value_type
>::result_type
>
result_type;
result_type
operator ()(Left & left, Right & right) const
{
std::size_t left_size = left.size();
std::size_t right_size = right.size();
result_type result(left_size, right_size);
for (std::size_t i = 0; i < left_size; ++i)
for (std::size_t j = 0; j < right_size; ++j)
result(i,j) = numeric::multiplies(left[i], right[j]);
return result;
}
};
}
namespace op
{
struct outer_product
: boost::detail::function2<functional::outer_product<_1, _2, functional::tag<_1>, functional::tag<_2> > >
{};
}
namespace
{
op::outer_product const &outer_product = boost::detail::pod_singleton<op::outer_product>::instance;
}
}}
namespace boost { namespace accumulators
{
namespace impl
{
///////////////////////////////////////////////////////////////////////////////
// covariance_impl
//
/**
@brief Covariance Estimator
An iterative Monte Carlo estimator for the covariance \f$\mathrm{Cov}(X,X')\f$, where \f$X\f$ is a sample
and \f$X'\f$ is a variate, is given by:
\f[
\hat{c}_n = \frac{n-1}{n} \hat{c}_{n-1} + \frac{1}{n-1}(X_n - \hat{\mu}_n)(X_n' - \hat{\mu}_n'),\quad n\ge2,\quad\hat{c}_1 = 0,
\f]
\f$\hat{\mu}_n\f$ and \f$\hat{\mu}_n'\f$ being the means of the samples and variates.
*/
template<typename Sample, typename VariateType, typename VariateTag>
struct covariance_impl
: accumulator_base
{
typedef typename numeric::functional::average<Sample, std::size_t>::result_type sample_type;
typedef typename numeric::functional::average<VariateType, std::size_t>::result_type variate_type;
// for boost::result_of
typedef typename numeric::functional::outer_product<sample_type, variate_type>::result_type result_type;
template<typename Args>
covariance_impl(Args const &args)
: cov_(
numeric::outer_product(
numeric::average(args[sample | Sample()], (std::size_t)1)
, numeric::average(args[parameter::keyword<VariateTag>::get() | VariateType()], (std::size_t)1)
)
)
{
}
template<typename Args>
void operator ()(Args const &args)
{
std::size_t cnt = count(args);
if (cnt > 1)
{
extractor<tag::mean_of_variates<VariateType, VariateTag> > const some_mean_of_variates = {};
this->cov_ = this->cov_*(cnt-1.)/cnt
+ numeric::outer_product(
some_mean_of_variates(args) - args[parameter::keyword<VariateTag>::get()]
, mean(args) - args[sample]
) / (cnt-1.);
}
}
result_type result(dont_care) const
{
return this->cov_;
}
private:
result_type cov_;
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::covariance
//
namespace tag
{
template<typename VariateType, typename VariateTag>
struct covariance
: depends_on<count, mean, mean_of_variates<VariateType, VariateTag> >
{
typedef accumulators::impl::covariance_impl<mpl::_1, VariateType, VariateTag> impl;
};
struct abstract_covariance
: depends_on<>
{
};
}
///////////////////////////////////////////////////////////////////////////////
// extract::covariance
//
namespace extract
{
extractor<tag::abstract_covariance> const covariance = {};
BOOST_ACCUMULATORS_IGNORE_GLOBAL(covariance)
}
using extract::covariance;
template<typename VariateType, typename VariateTag>
struct feature_of<tag::covariance<VariateType, VariateTag> >
: feature_of<tag::abstract_covariance>
{
};
// So that covariance can be automatically substituted with
// weighted_covariance when the weight parameter is non-void.
template<typename VariateType, typename VariateTag>
struct as_weighted_feature<tag::covariance<VariateType, VariateTag> >
{
typedef tag::weighted_covariance<VariateType, VariateTag> type;
};
template<typename VariateType, typename VariateTag>
struct feature_of<tag::weighted_covariance<VariateType, VariateTag> >
: feature_of<tag::covariance<VariateType, VariateTag> >
{};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,246 @@
///////////////////////////////////////////////////////////////////////////////
// density.hpp
//
// Copyright 2006 Daniel Egloff, Olivier Gygi. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_DENSITY_HPP_DE_01_01_2006
#define BOOST_ACCUMULATORS_STATISTICS_DENSITY_HPP_DE_01_01_2006
#include <vector>
#include <limits>
#include <functional>
#include <boost/range.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/numeric/functional.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#include <boost/accumulators/statistics/count.hpp>
#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/min.hpp>
namespace boost { namespace accumulators
{
///////////////////////////////////////////////////////////////////////////////
// cache_size and num_bins named parameters
//
BOOST_PARAMETER_NESTED_KEYWORD(tag, density_cache_size, cache_size)
BOOST_PARAMETER_NESTED_KEYWORD(tag, density_num_bins, num_bins)
namespace impl
{
///////////////////////////////////////////////////////////////////////////////
// density_impl
// density histogram
/**
@brief Histogram density estimator
The histogram density estimator returns a histogram of the sample distribution. The positions and sizes of the bins
are determined using a specifiable number of cached samples (cache_size). The range between the minimum and the
maximum of the cached samples is subdivided into a specifiable number of bins (num_bins) of same size. Additionally,
an under- and an overflow bin is added to capture future under- and overflow samples. Once the bins are determined,
the cached samples and all subsequent samples are added to the correct bins. At the end, a range of std::pair is
return, where each pair contains the position of the bin (lower bound) and the samples count (normalized with the
total number of samples).
@param density_cache_size Number of first samples used to determine min and max.
@param density_num_bins Number of bins (two additional bins collect under- and overflow samples).
*/
template<typename Sample>
struct density_impl
: accumulator_base
{
typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
typedef std::vector<std::pair<float_type, float_type> > histogram_type;
typedef std::vector<float_type> array_type;
// for boost::result_of
typedef iterator_range<typename histogram_type::iterator> result_type;
template<typename Args>
density_impl(Args const &args)
: cache_size(args[density_cache_size])
, cache(cache_size)
, num_bins(args[density_num_bins])
, samples_in_bin(num_bins + 2, 0.)
, bin_positions(num_bins + 2)
, histogram(
num_bins + 2
, std::make_pair(
numeric::average(args[sample | Sample()],(std::size_t)1)
, numeric::average(args[sample | Sample()],(std::size_t)1)
)
)
, is_dirty(true)
{
}
template<typename Args>
void operator ()(Args const &args)
{
this->is_dirty = true;
std::size_t cnt = count(args);
// Fill up cache with cache_size first samples
if (cnt <= this->cache_size)
{
this->cache[cnt - 1] = args[sample];
}
// Once cache_size samples have been accumulated, create num_bins bins of same size between
// the minimum and maximum of the cached samples as well as under and overflow bins.
// Store their lower bounds (bin_positions) and fill the bins with the cached samples (samples_in_bin).
if (cnt == this->cache_size)
{
float_type minimum = numeric::average((min)(args), (std::size_t)1);
float_type maximum = numeric::average((max)(args), (std::size_t)1);
float_type bin_size = numeric::average(maximum - minimum, this->num_bins );
// determine bin positions (their lower bounds)
for (std::size_t i = 0; i < this->num_bins + 2; ++i)
{
this->bin_positions[i] = minimum + (i - 1.) * bin_size;
}
for (typename array_type::const_iterator iter = this->cache.begin(); iter != this->cache.end(); ++iter)
{
if (*iter < this->bin_positions[1])
{
++(this->samples_in_bin[0]);
}
else if (*iter >= this->bin_positions[this->num_bins + 1])
{
++(this->samples_in_bin[this->num_bins + 1]);
}
else
{
typename array_type::iterator it = std::upper_bound(
this->bin_positions.begin()
, this->bin_positions.end()
, *iter
);
std::size_t d = std::distance(this->bin_positions.begin(), it);
++(this->samples_in_bin[d - 1]);
}
}
}
// Add each subsequent sample to the correct bin
else if (cnt > this->cache_size)
{
if (args[sample] < this->bin_positions[1])
{
++(this->samples_in_bin[0]);
}
else if (args[sample] >= this->bin_positions[this->num_bins + 1])
{
++(this->samples_in_bin[this->num_bins + 1]);
}
else
{
typename array_type::iterator it = std::upper_bound(
this->bin_positions.begin()
, this->bin_positions.end()
, args[sample]
);
std::size_t d = std::distance(this->bin_positions.begin(), it);
++(this->samples_in_bin[d - 1]);
}
}
}
/**
@pre The number of samples must meet or exceed the cache size
*/
template<typename Args>
result_type result(Args const &args) const
{
if (this->is_dirty)
{
this->is_dirty = false;
// creates a vector of std::pair where each pair i holds
// the values bin_positions[i] (x-axis of histogram) and
// samples_in_bin[i] / cnt (y-axis of histogram).
for (std::size_t i = 0; i < this->num_bins + 2; ++i)
{
this->histogram[i] = std::make_pair(this->bin_positions[i], numeric::average(this->samples_in_bin[i], count(args)));
}
}
// returns a range of pairs
return make_iterator_range(this->histogram);
}
private:
std::size_t cache_size; // number of cached samples
array_type cache; // cache to store the first cache_size samples
std::size_t num_bins; // number of bins
array_type samples_in_bin; // number of samples in each bin
array_type bin_positions; // lower bounds of bins
mutable histogram_type histogram; // histogram
mutable bool is_dirty;
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::density
//
namespace tag
{
struct density
: depends_on<count, min, max>
, density_cache_size
, density_num_bins
{
/// INTERNAL ONLY
///
typedef accumulators::impl::density_impl<mpl::_1> impl;
#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
/// tag::density::cache_size named parameter
/// tag::density::num_bins named parameter
static boost::parameter::keyword<density_cache_size> const cache_size;
static boost::parameter::keyword<density_num_bins> const num_bins;
#endif
};
}
///////////////////////////////////////////////////////////////////////////////
// extract::density
//
namespace extract
{
extractor<tag::density> const density = {};
BOOST_ACCUMULATORS_IGNORE_GLOBAL(density)
}
using extract::density;
// So that density can be automatically substituted
// with weighted_density when the weight parameter is non-void.
template<>
struct as_weighted_feature<tag::density>
{
typedef tag::weighted_density type;
};
template<>
struct feature_of<tag::weighted_density>
: feature_of<tag::density>
{
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,99 @@
///////////////////////////////////////////////////////////////////////////////
// error_of.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_HPP_EAN_29_11_2005
#define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_HPP_EAN_29_11_2005
#include <boost/mpl/placeholders.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
namespace boost { namespace accumulators
{
namespace impl
{
/// INTERNAL ONLY
///
template<typename Feature>
struct this_feature_has_no_error_calculation
: mpl::false_
{
};
///////////////////////////////////////////////////////////////////////////////
// error_of_impl
/// INTERNAL ONLY
///
template<typename Sample, typename Feature>
struct error_of_impl
: accumulator_base
{
// TODO: specialize this on the specific features that have errors we're
// interested in.
BOOST_MPL_ASSERT((this_feature_has_no_error_calculation<Feature>));
// for boost::result_of
typedef int result_type;
error_of_impl(dont_care)
{
}
result_type result(dont_care) const
{
return 0;
}
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::error_of
//
namespace tag
{
template<typename Feature>
struct error_of
: depends_on<Feature>
{
/// INTERNAL ONLY
///
typedef accumulators::impl::error_of_impl<mpl::_1, Feature> impl;
};
}
///////////////////////////////////////////////////////////////////////////////
// extract::error_of
//
namespace extract
{
BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, error_of, (typename))
}
using extract::error_of;
// make tag::error_of<tag::feature(modifier)> work
template<typename Feature>
struct as_feature<tag::error_of<Feature> >
{
typedef tag::error_of<typename as_feature<Feature>::type> type;
};
// make error_of<tag::mean> work with non-void weights (should become
// error_of<tag::weighted_mean>
template<typename Feature>
struct as_weighted_feature<tag::error_of<Feature> >
{
typedef tag::error_of<typename as_weighted_feature<Feature>::type> type;
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,73 @@
///////////////////////////////////////////////////////////////////////////////
// error_of.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
#define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
#include <boost/mpl/placeholders.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#include <boost/accumulators/statistics/error_of.hpp>
#include <boost/accumulators/statistics/variance.hpp>
#include <boost/accumulators/statistics/count.hpp>
namespace boost { namespace accumulators
{
namespace impl
{
///////////////////////////////////////////////////////////////////////////////
// error_of_mean_impl
template<typename Sample, typename Variance>
struct error_of_mean_impl
: accumulator_base
{
// for boost::result_of
typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
error_of_mean_impl(dont_care) {}
template<typename Args>
result_type result(Args const &args) const
{
using namespace std;
extractor<Variance> const variance = {};
return sqrt(numeric::average(variance(args), count(args) - 1));
}
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::error_of
//
namespace tag
{
template<>
struct error_of<mean>
: depends_on<lazy_variance, count>
{
/// INTERNAL ONLY
///
typedef accumulators::impl::error_of_mean_impl<mpl::_1, lazy_variance> impl;
};
template<>
struct error_of<immediate_mean>
: depends_on<variance, count>
{
/// INTERNAL ONLY
///
typedef accumulators::impl::error_of_mean_impl<mpl::_1, variance> impl;
};
}
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,293 @@
///////////////////////////////////////////////////////////////////////////////
// extended_p_square.hpp
//
// Copyright 2005 Daniel Egloff. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_EXTENDED_SINGLE_HPP_DE_01_01_2006
#define BOOST_ACCUMULATORS_STATISTICS_EXTENDED_SINGLE_HPP_DE_01_01_2006
#include <vector>
#include <functional>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/iterator/permutation_iterator.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/numeric/functional.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#include <boost/accumulators/statistics/count.hpp>
#include <boost/accumulators/statistics/times2_iterator.hpp>
namespace boost { namespace accumulators
{
///////////////////////////////////////////////////////////////////////////////
// probabilities named parameter
//
BOOST_PARAMETER_NESTED_KEYWORD(tag, extended_p_square_probabilities, probabilities)
namespace impl
{
///////////////////////////////////////////////////////////////////////////////
// extended_p_square_impl
// multiple quantile estimation
/**
@brief Multiple quantile estimation with the extended \f$P^2\f$ algorithm
Extended \f$P^2\f$ algorithm for estimation of several quantiles without storing samples.
Assume that \f$m\f$ quantiles \f$\xi_{p_1}, \ldots, \xi_{p_m}\f$ are to be estimated.
Instead of storing the whole sample cumulative distribution, the algorithm maintains only
\f$m+2\f$ principal markers and \f$m+1\f$ middle markers, whose positions are updated
with each sample and whose heights are adjusted (if necessary) using a piecewise-parablic
formula. The heights of these central markers are the current estimates of the quantiles
and returned as an iterator range.
For further details, see
K. E. E. Raatikainen, Simultaneous estimation of several quantiles, Simulation, Volume 49,
Number 4 (October), 1986, p. 159-164.
The extended \f$ P^2 \f$ algorithm generalizess the \f$ P^2 \f$ algorithm of
R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and
histograms without storing observations, Communications of the ACM,
Volume 28 (October), Number 10, 1985, p. 1076-1085.
@param extended_p_square_probabilities A vector of quantile probabilities.
*/
template<typename Sample>
struct extended_p_square_impl
: accumulator_base
{
typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
typedef std::vector<float_type> array_type;
// for boost::result_of
typedef iterator_range<
detail::lvalue_index_iterator<
permutation_iterator<
typename array_type::const_iterator
, detail::times2_iterator
>
>
> result_type;
template<typename Args>
extended_p_square_impl(Args const &args)
: probabilities(
boost::begin(args[extended_p_square_probabilities])
, boost::end(args[extended_p_square_probabilities])
)
, heights(2 * probabilities.size() + 3)
, actual_positions(heights.size())
, desired_positions(heights.size())
, positions_increments(heights.size())
{
std::size_t num_quantiles = this->probabilities.size();
std::size_t num_markers = this->heights.size();
for(std::size_t i = 0; i < num_markers; ++i)
{
this->actual_positions[i] = i + 1;
}
this->positions_increments[0] = 0.;
this->positions_increments[num_markers - 1] = 1.;
for(std::size_t i = 0; i < num_quantiles; ++i)
{
this->positions_increments[2 * i + 2] = probabilities[i];
}
for(std::size_t i = 0; i <= num_quantiles; ++i)
{
this->positions_increments[2 * i + 1] =
0.5 * (this->positions_increments[2 * i] + this->positions_increments[2 * i + 2]);
}
for(std::size_t i = 0; i < num_markers; ++i)
{
this->desired_positions[i] = 1. + 2. * (num_quantiles + 1.) * this->positions_increments[i];
}
}
template<typename Args>
void operator ()(Args const &args)
{
std::size_t cnt = count(args);
// m+2 principal markers and m+1 middle markers
std::size_t num_markers = 2 * this->probabilities.size() + 3;
// first accumulate num_markers samples
if(cnt <= num_markers)
{
this->heights[cnt - 1] = args[sample];
// complete the initialization of heights by sorting
if(cnt == num_markers)
{
std::sort(this->heights.begin(), this->heights.end());
}
}
else
{
std::size_t sample_cell = 1;
// find cell k = sample_cell such that heights[k-1] <= sample < heights[k]
if(args[sample] < this->heights[0])
{
this->heights[0] = args[sample];
sample_cell = 1;
}
else if(args[sample] >= this->heights[num_markers - 1])
{
this->heights[num_markers - 1] = args[sample];
sample_cell = num_markers - 1;
}
else
{
typedef typename array_type::iterator iterator;
iterator it = std::upper_bound(
this->heights.begin()
, this->heights.end()
, args[sample]
);
sample_cell = std::distance(this->heights.begin(), it);
}
// update actual positions of all markers above sample_cell index
for(std::size_t i = sample_cell; i < num_markers; ++i)
{
++this->actual_positions[i];
}
// update desired positions of all markers
for(std::size_t i = 0; i < num_markers; ++i)
{
this->desired_positions[i] += this->positions_increments[i];
}
// adjust heights and actual positions of markers 1 to num_markers-2 if necessary
for(std::size_t i = 1; i <= num_markers - 2; ++i)
{
// offset to desired position
float_type d = this->desired_positions[i] - this->actual_positions[i];
// offset to next position
float_type dp = this->actual_positions[i+1] - this->actual_positions[i];
// offset to previous position
float_type dm = this->actual_positions[i-1] - this->actual_positions[i];
// height ds
float_type hp = (this->heights[i+1] - this->heights[i]) / dp;
float_type hm = (this->heights[i-1] - this->heights[i]) / dm;
if((d >= 1 && dp > 1) || (d <= -1 && dm < -1))
{
short sign_d = static_cast<short>(d / std::abs(d));
float_type h = this->heights[i] + sign_d / (dp - dm) * ((sign_d - dm)*hp
+ (dp - sign_d) * hm);
// try adjusting heights[i] using p-squared formula
if(this->heights[i - 1] < h && h < this->heights[i + 1])
{
this->heights[i] = h;
}
else
{
// use linear formula
if(d > 0)
{
this->heights[i] += hp;
}
if(d < 0)
{
this->heights[i] -= hm;
}
}
this->actual_positions[i] += sign_d;
}
}
}
}
result_type result(dont_care) const
{
// for i in [1,probabilities.size()], return heights[i * 2]
detail::times2_iterator idx_begin = detail::make_times2_iterator(1);
detail::times2_iterator idx_end = detail::make_times2_iterator(this->probabilities.size() + 1);
return result_type(
make_permutation_iterator(this->heights.begin(), idx_begin)
, make_permutation_iterator(this->heights.begin(), idx_end)
);
}
private:
array_type probabilities; // the quantile probabilities
array_type heights; // q_i
array_type actual_positions; // n_i
array_type desired_positions; // d_i
array_type positions_increments; // f_i
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::extended_p_square
//
namespace tag
{
struct extended_p_square
: depends_on<count>
, extended_p_square_probabilities
{
typedef accumulators::impl::extended_p_square_impl<mpl::_1> impl;
#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
/// tag::extended_p_square::probabilities named paramter
static boost::parameter::keyword<tag::probabilities> const probabilities;
#endif
};
}
///////////////////////////////////////////////////////////////////////////////
// extract::extended_p_square
//
namespace extract
{
extractor<tag::extended_p_square> const extended_p_square = {};
BOOST_ACCUMULATORS_IGNORE_GLOBAL(extended_p_square)
}
using extract::extended_p_square;
// So that extended_p_square can be automatically substituted with
// weighted_extended_p_square when the weight parameter is non-void
template<>
struct as_weighted_feature<tag::extended_p_square>
{
typedef tag::weighted_extended_p_square type;
};
template<>
struct feature_of<tag::weighted_extended_p_square>
: feature_of<tag::extended_p_square>
{
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,320 @@
///////////////////////////////////////////////////////////////////////////////
// extended_p_square_quantile.hpp
//
// Copyright 2005 Daniel Egloff. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_EXTENDED_SINGLE_QUANTILE_HPP_DE_01_01_2006
#define BOOST_ACCUMULATORS_STATISTICS_EXTENDED_SINGLE_QUANTILE_HPP_DE_01_01_2006
#include <vector>
#include <functional>
#include <boost/throw_exception.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/iterator/permutation_iterator.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/numeric/functional.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#include <boost/accumulators/statistics/count.hpp>
#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
#include <boost/accumulators/statistics/extended_p_square.hpp>
#include <boost/accumulators/statistics/weighted_extended_p_square.hpp>
#include <boost/accumulators/statistics/times2_iterator.hpp>
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4127) // conditional expression is constant
#endif
namespace boost { namespace accumulators
{
namespace impl
{
///////////////////////////////////////////////////////////////////////////////
// extended_p_square_quantile_impl
// single quantile estimation
/**
@brief Quantile estimation using the extended \f$P^2\f$ algorithm for weighted and unweighted samples
Uses the quantile estimates calculated by the extended \f$P^2\f$ algorithm to compute
intermediate quantile estimates by means of quadratic interpolation.
@param quantile_probability The probability of the quantile to be estimated.
*/
template<typename Sample, typename Impl1, typename Impl2> // Impl1: weighted/unweighted // Impl2: linear/quadratic
struct extended_p_square_quantile_impl
: accumulator_base
{
typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
typedef std::vector<float_type> array_type;
typedef iterator_range<
detail::lvalue_index_iterator<
permutation_iterator<
typename array_type::const_iterator
, detail::times2_iterator
>
>
> range_type;
// for boost::result_of
typedef float_type result_type;
template<typename Args>
extended_p_square_quantile_impl(Args const &args)
: probabilities(
boost::begin(args[extended_p_square_probabilities])
, boost::end(args[extended_p_square_probabilities])
)
{
}
template<typename Args>
result_type result(Args const &args) const
{
typedef
typename mpl::if_<
is_same<Impl1, weighted>
, tag::weighted_extended_p_square
, tag::extended_p_square
>::type
extended_p_square_tag;
extractor<extended_p_square_tag> const some_extended_p_square = {};
array_type heights(some_extended_p_square(args).size());
std::copy(some_extended_p_square(args).begin(), some_extended_p_square(args).end(), heights.begin());
this->probability = args[quantile_probability];
typename array_type::const_iterator iter_probs = std::lower_bound(this->probabilities.begin(), this->probabilities.end(), this->probability);
std::size_t dist = std::distance(this->probabilities.begin(), iter_probs);
typename array_type::const_iterator iter_heights = heights.begin() + dist;
// If this->probability is not in a valid range return NaN or throw exception
if (this->probability < *this->probabilities.begin() || this->probability > *(this->probabilities.end() - 1))
{
if (std::numeric_limits<result_type>::has_quiet_NaN)
{
return std::numeric_limits<result_type>::quiet_NaN();
}
else
{
std::ostringstream msg;
msg << "probability = " << this->probability << " is not in valid range (";
msg << *this->probabilities.begin() << ", " << *(this->probabilities.end() - 1) << ")";
boost::throw_exception(std::runtime_error(msg.str()));
return Sample(0);
}
}
if (*iter_probs == this->probability)
{
return heights[dist];
}
else
{
result_type res;
if (is_same<Impl2, linear>::value)
{
/////////////////////////////////////////////////////////////////////////////////
// LINEAR INTERPOLATION
//
float_type p1 = *iter_probs;
float_type p0 = *(iter_probs - 1);
float_type h1 = *iter_heights;
float_type h0 = *(iter_heights - 1);
float_type a = numeric::average(h1 - h0, p1 - p0);
float_type b = h1 - p1 * a;
res = a * this->probability + b;
}
else
{
/////////////////////////////////////////////////////////////////////////////////
// QUADRATIC INTERPOLATION
//
float_type p0, p1, p2;
float_type h0, h1, h2;
if ( (dist == 1 || *iter_probs - this->probability <= this->probability - *(iter_probs - 1) ) && dist != this->probabilities.size() - 1 )
{
p0 = *(iter_probs - 1);
p1 = *iter_probs;
p2 = *(iter_probs + 1);
h0 = *(iter_heights - 1);
h1 = *iter_heights;
h2 = *(iter_heights + 1);
}
else
{
p0 = *(iter_probs - 2);
p1 = *(iter_probs - 1);
p2 = *iter_probs;
h0 = *(iter_heights - 2);
h1 = *(iter_heights - 1);
h2 = *iter_heights;
}
float_type hp21 = numeric::average(h2 - h1, p2 - p1);
float_type hp10 = numeric::average(h1 - h0, p1 - p0);
float_type p21 = numeric::average(p2 * p2 - p1 * p1, p2 - p1);
float_type p10 = numeric::average(p1 * p1 - p0 * p0, p1 - p0);
float_type a = numeric::average(hp21 - hp10, p21 - p10);
float_type b = hp21 - a * p21;
float_type c = h2 - a * p2 * p2 - b * p2;
res = a * this->probability * this-> probability + b * this->probability + c;
}
return res;
}
}
private:
array_type probabilities;
mutable float_type probability;
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::extended_p_square_quantile
//
namespace tag
{
struct extended_p_square_quantile
: depends_on<extended_p_square>
{
typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, unweighted, linear> impl;
};
struct extended_p_square_quantile_quadratic
: depends_on<extended_p_square>
{
typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, unweighted, quadratic> impl;
};
struct weighted_extended_p_square_quantile
: depends_on<weighted_extended_p_square>
{
typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, weighted, linear> impl;
};
struct weighted_extended_p_square_quantile_quadratic
: depends_on<weighted_extended_p_square>
{
typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, weighted, quadratic> impl;
};
}
///////////////////////////////////////////////////////////////////////////////
// extract::extended_p_square_quantile
// extract::weighted_extended_p_square_quantile
//
namespace extract
{
extractor<tag::extended_p_square_quantile> const extended_p_square_quantile = {};
extractor<tag::extended_p_square_quantile_quadratic> const extended_p_square_quantile_quadratic = {};
extractor<tag::weighted_extended_p_square_quantile> const weighted_extended_p_square_quantile = {};
extractor<tag::weighted_extended_p_square_quantile_quadratic> const weighted_extended_p_square_quantile_quadratic = {};
BOOST_ACCUMULATORS_IGNORE_GLOBAL(extended_p_square_quantile)
BOOST_ACCUMULATORS_IGNORE_GLOBAL(extended_p_square_quantile_quadratic)
BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_extended_p_square_quantile)
BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_extended_p_square_quantile_quadratic)
}
using extract::extended_p_square_quantile;
using extract::extended_p_square_quantile_quadratic;
using extract::weighted_extended_p_square_quantile;
using extract::weighted_extended_p_square_quantile_quadratic;
// extended_p_square_quantile(linear) -> extended_p_square_quantile
template<>
struct as_feature<tag::extended_p_square_quantile(linear)>
{
typedef tag::extended_p_square_quantile type;
};
// extended_p_square_quantile(quadratic) -> extended_p_square_quantile_quadratic
template<>
struct as_feature<tag::extended_p_square_quantile(quadratic)>
{
typedef tag::extended_p_square_quantile_quadratic type;
};
// weighted_extended_p_square_quantile(linear) -> weighted_extended_p_square_quantile
template<>
struct as_feature<tag::weighted_extended_p_square_quantile(linear)>
{
typedef tag::weighted_extended_p_square_quantile type;
};
// weighted_extended_p_square_quantile(quadratic) -> weighted_extended_p_square_quantile_quadratic
template<>
struct as_feature<tag::weighted_extended_p_square_quantile(quadratic)>
{
typedef tag::weighted_extended_p_square_quantile_quadratic type;
};
// for the purposes of feature-based dependency resolution,
// extended_p_square_quantile and weighted_extended_p_square_quantile
// provide the same feature as quantile
template<>
struct feature_of<tag::extended_p_square_quantile>
: feature_of<tag::quantile>
{
};
template<>
struct feature_of<tag::extended_p_square_quantile_quadratic>
: feature_of<tag::quantile>
{
};
// So that extended_p_square_quantile can be automatically substituted with
// weighted_extended_p_square_quantile when the weight parameter is non-void
template<>
struct as_weighted_feature<tag::extended_p_square_quantile>
{
typedef tag::weighted_extended_p_square_quantile type;
};
template<>
struct feature_of<tag::weighted_extended_p_square_quantile>
: feature_of<tag::extended_p_square_quantile>
{
};
// So that extended_p_square_quantile_quadratic can be automatically substituted with
// weighted_extended_p_square_quantile_quadratic when the weight parameter is non-void
template<>
struct as_weighted_feature<tag::extended_p_square_quantile_quadratic>
{
typedef tag::weighted_extended_p_square_quantile_quadratic type;
};
template<>
struct feature_of<tag::weighted_extended_p_square_quantile_quadratic>
: feature_of<tag::extended_p_square_quantile_quadratic>
{
};
}} // namespace boost::accumulators
#ifdef _MSC_VER
# pragma warning(pop)
#endif
#endif
@@ -0,0 +1,112 @@
///////////////////////////////////////////////////////////////////////////////
// kurtosis.hpp
//
// Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
#include <limits>
#include <boost/mpl/placeholders.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/numeric/functional.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/moment.hpp>
namespace boost { namespace accumulators
{
namespace impl
{
///////////////////////////////////////////////////////////////////////////////
// kurtosis_impl
/**
@brief Kurtosis estimation
The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the square of the 2nd central
moment (the variance) of the samples, minus 3. The term \f$ -3 \f$ is added in order to ensure that the normal distribution
has zero kurtosis. The kurtosis can also be expressed by the simple moments:
\f[
\hat{g}_2 =
\frac
{\widehat{m}_n^{(4)}-4\widehat{m}_n^{(3)}\hat{\mu}_n+6\widehat{m}_n^{(2)}\hat{\mu}_n^2-3\hat{\mu}_n^4}
{\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
\f]
where \f$ \widehat{m}_n^{(i)} \f$ are the \f$ i \f$-th moment and \f$ \hat{\mu}_n \f$ the mean (first moment) of the
\f$ n \f$ samples.
*/
template<typename Sample>
struct kurtosis_impl
: accumulator_base
{
// for boost::result_of
typedef typename numeric::functional::average<Sample, Sample>::result_type result_type;
kurtosis_impl(dont_care) {}
template<typename Args>
result_type result(Args const &args) const
{
return numeric::average(
accumulators::moment<4>(args)
- 4. * accumulators::moment<3>(args) * mean(args)
+ 6. * accumulators::moment<2>(args) * mean(args) * mean(args)
- 3. * mean(args) * mean(args) * mean(args) * mean(args)
, ( accumulators::moment<2>(args) - mean(args) * mean(args) )
* ( accumulators::moment<2>(args) - mean(args) * mean(args) )
) - 3.;
}
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::kurtosis
//
namespace tag
{
struct kurtosis
: depends_on<mean, moment<2>, moment<3>, moment<4> >
{
/// INTERNAL ONLY
///
typedef accumulators::impl::kurtosis_impl<mpl::_1> impl;
};
}
///////////////////////////////////////////////////////////////////////////////
// extract::kurtosis
//
namespace extract
{
extractor<tag::kurtosis> const kurtosis = {};
BOOST_ACCUMULATORS_IGNORE_GLOBAL(kurtosis)
}
using extract::kurtosis;
// So that kurtosis can be automatically substituted with
// weighted_kurtosis when the weight parameter is non-void
template<>
struct as_weighted_feature<tag::kurtosis>
{
typedef tag::weighted_kurtosis type;
};
template<>
struct feature_of<tag::weighted_kurtosis>
: feature_of<tag::kurtosis>
{
};
}} // namespace boost::accumulators
#endif
@@ -0,0 +1,85 @@
///////////////////////////////////////////////////////////////////////////////
// max.hpp
//
// Copyright 2005 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ACCUMULATORS_STATISTICS_MAX_HPP_EAN_28_10_2005
#define BOOST_ACCUMULATORS_STATISTICS_MAX_HPP_EAN_28_10_2005
#include <limits>
#include <boost/mpl/placeholders.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/numeric/functional.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
namespace boost { namespace accumulators
{
namespace impl
{
///////////////////////////////////////////////////////////////////////////////
// max_impl
template<typename Sample>
struct max_impl
: accumulator_base
{
// for boost::result_of
typedef Sample result_type;
template<typename Args>
max_impl(Args const &args)
: max_(numeric::as_min(args[sample | Sample()]))
{
}
template<typename Args>
void operator ()(Args const &args)
{
numeric::max_assign(this->max_, args[sample]);
}
result_type result(dont_care) const
{
return this->max_;
}
private:
Sample max_;
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// tag::max
//
namespace tag
{
struct max
: depends_on<>
{
/// INTERNAL ONLY
///
typedef accumulators::impl::max_impl<mpl::_1> impl;
};
}
///////////////////////////////////////////////////////////////////////////////
// extract::max
//
namespace extract
{
extractor<tag::max> const max = {};
BOOST_ACCUMULATORS_IGNORE_GLOBAL(max)
}
using extract::max;
}} // namespace boost::accumulators
#endif
Loaded 100 of 16345 files, more files were not shown because too many files have changed in this diff. Show more