mirror of
https://github.com/copyrighttxt/watrbx-game-engine.git
synced 2026-09-05 21:27:48 +00:00
GEEKING
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(_WIN32) && !defined(RBX_PLATFORM_DURANGO)
|
||||
#include "pdh.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace RBX {
|
||||
|
||||
/**
|
||||
Provides generalized Windows registry querying.
|
||||
|
||||
All key names are one string in the format:
|
||||
"[base key]\[sub-keys]\value"
|
||||
|
||||
[base key] can be any of the following:
|
||||
HKEY_CLASSES_ROOT
|
||||
HKEY_CURRENT_CONFIG
|
||||
HKEY_CURRENT_USER
|
||||
HKEY_LOCAL_MACHINE
|
||||
HKEY_PERFORMANCE_DATA
|
||||
HKEY_PERFORMANCE_NLSTEXT
|
||||
HKEY_PERFORMANCE_TEXT
|
||||
HKEY_USERS
|
||||
|
||||
keyExists() should be used to validate a key before reading or writing
|
||||
to ensure that a debug assert or false return is for a different error.
|
||||
*/
|
||||
class RegistryUtil {
|
||||
|
||||
public:
|
||||
/** returns true if the key exists */
|
||||
static bool keyExists(const std::string& key);
|
||||
|
||||
/** returns false if the key could not be read for any reason. */
|
||||
static bool read32bitNumber(const std::string& key, INT32& valueData);
|
||||
|
||||
/**
|
||||
Reads an arbitrary amount of data from a binary registry key.
|
||||
returns false if the key could not be read for any reason.
|
||||
|
||||
@param valueData pointer to the output buffer of sufficient size. Pass NULL as valueData in order to have available data size returned in dataSize.
|
||||
@param dataSize size of the output buffer. When NULL is passed for valueData, contains the size of available data on successful return.
|
||||
*/
|
||||
static bool readBinaryData(const std::string& key, BYTE* valueData, UINT32& dataSize);
|
||||
|
||||
/** returns false if the key could not be read for any reason. */
|
||||
static bool readString(const std::string& key, std::string& valueData);
|
||||
|
||||
/** returns false if the key could not be written for any reason. */
|
||||
static bool write32bitNumber(const std::string& key, INT32 valueData);
|
||||
|
||||
/**
|
||||
Writes an arbitrary amount of data to a binary registry key.
|
||||
returns false if the key could not be written for any reason.
|
||||
|
||||
@param valueData pointer to the input buffer
|
||||
@param dataSize size of the input buffer that should be written
|
||||
*/
|
||||
static bool writeBinaryData(const std::string& key, const BYTE* valueData, UINT32 dataSize);
|
||||
|
||||
/** returns false if the key could not be written for any reason. */
|
||||
static bool writeString(const std::string& key, const std::string& valueData);
|
||||
|
||||
};
|
||||
|
||||
} // namespace RBX
|
||||
|
||||
#endif // _WIN32
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
namespace RBX {
|
||||
|
||||
inline void safeToLower(std::string& s)
|
||||
{
|
||||
for(unsigned i = 0; i<s.size(); ++i){
|
||||
if(isupper(s[i])){
|
||||
s[i] = tolower(s[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
//#include "pdh.h"
|
||||
|
||||
#include "boost/weak_ptr.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include "rbx/Debug.h"
|
||||
#include "rbx/threadsafe.h"
|
||||
|
||||
namespace RBX
|
||||
{
|
||||
template<class T>
|
||||
class ScopedSingleton
|
||||
{
|
||||
private:
|
||||
static int& initCount()
|
||||
{
|
||||
static int initcount = 0;
|
||||
return initcount;
|
||||
}
|
||||
protected:
|
||||
// use this to validate usage pattern.
|
||||
// some usage patterns will want to check that this doesn't
|
||||
// increase more than 1.
|
||||
static int getInitCount()
|
||||
{
|
||||
return initCount();
|
||||
}
|
||||
SAFE_STATIC(rbx::spin_mutex, sync)
|
||||
SAFE_STATIC(boost::weak_ptr<T>, s_instance)
|
||||
public:
|
||||
static boost::shared_ptr<T> getInstance()
|
||||
{
|
||||
rbx::spin_mutex::scoped_lock lock(sync());
|
||||
|
||||
shared_ptr<T> result = s_instance().lock();
|
||||
|
||||
if (!result)
|
||||
{
|
||||
initCount()++;
|
||||
result = shared_ptr<T>(new T());
|
||||
s_instance() = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
static boost::shared_ptr<T> getInstanceOptional()
|
||||
{
|
||||
return s_instance().lock();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <istream>
|
||||
#include <string>
|
||||
|
||||
namespace RBX
|
||||
{
|
||||
void readStreamIntoString(std::istream &stream, std::string& content);
|
||||
} // RBX
|
||||
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
#include "rbx/Debug.h"
|
||||
#include <string>
|
||||
|
||||
namespace RBX {
|
||||
class StringReadBuffer
|
||||
{
|
||||
std::string::const_iterator cur;
|
||||
const std::string& buffer;
|
||||
|
||||
public:
|
||||
StringReadBuffer(const std::string& str) : buffer(str)
|
||||
{
|
||||
cur = buffer.begin();
|
||||
}
|
||||
|
||||
StringReadBuffer& operator >> (unsigned char& value)
|
||||
{
|
||||
RBXASSERT(cur != buffer.end());
|
||||
if(cur == buffer.end()) {
|
||||
throw RBX::runtime_error("Reading past end of string");
|
||||
} else {
|
||||
value = *cur++;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool eof()
|
||||
{
|
||||
return cur == buffer.end();
|
||||
}
|
||||
};
|
||||
|
||||
class StringWriteBuffer
|
||||
{
|
||||
std::string buffer;
|
||||
|
||||
public:
|
||||
StringWriteBuffer() : buffer(std::string())
|
||||
{
|
||||
}
|
||||
|
||||
StringWriteBuffer& operator << (unsigned char value)
|
||||
{
|
||||
buffer.push_back(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::string& str()
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
|
||||
#ifndef _UBLAS_EXT_H
|
||||
#define _UBLAS_EXT_H
|
||||
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/vector_proxy.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/lu.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
|
||||
//should we put this in a different namespace???
|
||||
namespace boost { namespace numeric { namespace ublas {
|
||||
|
||||
/* Matrix inversion routine.
|
||||
Uses lu_factorize and lu_substitute in uBLAS to invert a matrix */
|
||||
template<class T>
|
||||
bool invert_matrix (const matrix<T>& input, matrix<T>& inverse)
|
||||
{
|
||||
typedef permutation_matrix<std::size_t> pmatrix;
|
||||
// create a working copy of the input
|
||||
matrix<T> A(input);
|
||||
// create a permutation matrix for the LU-factorization
|
||||
pmatrix pm(A.size1());
|
||||
|
||||
// perform LU-factorization
|
||||
int res = lu_factorize(A,pm);
|
||||
if( res != 0 )
|
||||
return false;
|
||||
|
||||
// create identity matrix of "inverse"
|
||||
inverse.assign(ublas::identity_matrix<T>(A.size1()));
|
||||
|
||||
// backsubstitute to get the inverse
|
||||
lu_substitute(A, pm, inverse);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// LU factorization with partial pivoting
|
||||
// keeps factorizing even singular matrices.
|
||||
// returns number of independent columns!
|
||||
template<class M, class PM, class IsZeroFunctor>
|
||||
typename M::size_type lu_factorize_singular (M &m, PM &pm, const IsZeroFunctor& iszero ) {
|
||||
typedef M matrix_type;
|
||||
typedef typename M::size_type size_type;
|
||||
typedef typename M::value_type value_type;
|
||||
|
||||
#if BOOST_UBLAS_TYPE_CHECK
|
||||
matrix_type cm (m);
|
||||
#endif
|
||||
//int singular = 0;
|
||||
size_type size1 = m.size1 ();
|
||||
size_type size2 = m.size2 ();
|
||||
size_type size = (std::min) (size1, size2);
|
||||
size_type columni = 0;
|
||||
size_type rowi = 0;
|
||||
for (; rowi < size && columni < size2; ++ rowi, ++ columni) {
|
||||
matrix_column<M> mci (column (m, columni));
|
||||
matrix_row<M> mri (row (m, rowi));
|
||||
size_type i_norm_inf = rowi + index_norm_inf (project (mci, range (rowi, size1)));
|
||||
BOOST_UBLAS_CHECK (i_norm_inf < size1, external_logic ());
|
||||
if (!iszero(m (i_norm_inf, columni)) ) {
|
||||
if (i_norm_inf != rowi) {
|
||||
pm (rowi) = i_norm_inf;
|
||||
row (m, i_norm_inf).swap (mri);
|
||||
} else {
|
||||
BOOST_UBLAS_CHECK (pm (rowi) == i_norm_inf, external_logic ());
|
||||
}
|
||||
project (mci, range (rowi + 1, size1)) *= value_type (1) / m (rowi, columni);
|
||||
} else {
|
||||
// whole column is zero.
|
||||
// move to next column.
|
||||
rowi--; continue;
|
||||
}
|
||||
project (m, range (rowi + 1, size1), range (columni + 1, size2)).minus_assign (
|
||||
outer_prod (project (mci, range (rowi + 1, size1)),
|
||||
project (mri, range (columni + 1, size2))));
|
||||
}
|
||||
return rowi;
|
||||
}
|
||||
|
||||
template<class PM, class MV>
|
||||
BOOST_UBLAS_INLINE
|
||||
void unswap_rows (const PM &pm, MV &mv, vector_tag) {
|
||||
typedef typename PM::size_type size_type;
|
||||
typedef typename MV::value_type value_type;
|
||||
|
||||
size_type size = pm.size ();
|
||||
for (size_type i = size-1; i != ~0; -- i) {
|
||||
if (i != pm (i))
|
||||
std::swap (mv (i), mv (pm (i)));
|
||||
}
|
||||
}
|
||||
template<class PM, class MV>
|
||||
BOOST_UBLAS_INLINE
|
||||
void unswap_rows (const PM &pm, MV &mv, matrix_tag) {
|
||||
typedef typename PM::size_type size_type;
|
||||
typedef typename MV::value_type value_type;
|
||||
|
||||
size_type size = pm.size ();
|
||||
for (size_type i = size-1; i != ~0; -- i) {
|
||||
if (i != pm (i))
|
||||
row (mv, i).swap (row (mv, pm (i)));
|
||||
}
|
||||
}
|
||||
// Dispatcher
|
||||
template<class PM, class MV>
|
||||
BOOST_UBLAS_INLINE
|
||||
void unswap_rows (const PM &pm, MV &mv) {
|
||||
unswap_rows (pm, mv, typename MV::type_category ());
|
||||
}
|
||||
|
||||
}}} // namespace
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user