本文整理汇总了C++中USStream类的典型用法代码示例。如果您正苦于以下问题:C++ USStream类的具体用法?C++ USStream怎么用?C++ USStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了USStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteStream
//----------------------------------------------------------------//
size_t USStream::WriteStream ( USStream& source, size_t size ) {
if ( !( source.GetCaps () & CAN_READ )) return 0;
if ( !( this->GetCaps () & CAN_WRITE )) return 0;
u8 buffer [ LOCAL_BUFFER ];
size_t readSize = 0;
size_t total = 0;
do {
if (( total + LOCAL_BUFFER ) > size ) {
readSize = source.ReadBytes ( buffer, size - total );
}
else {
readSize = source.ReadBytes ( buffer, LOCAL_BUFFER );
}
if ( readSize ) {
total += this->WriteBytes ( buffer, readSize );
}
} while ( readSize == LOCAL_BUFFER );
return total;
}
示例2: WriteDecls
//----------------------------------------------------------------//
void USLuaSerializer::WriteDecls ( USStream& stream ) {
stream.Print ( "--Declaring Objects\n" );
stream.Print ( "local objects = {\n\n" );
this->WriteTableDecls ( stream );
this->WriteInstanceDecls ( stream );
stream.Print ( "}\n\n" );
}
示例3: WriteTableDecls
//----------------------------------------------------------------//
void USLuaSerializer::WriteTableDecls ( USStream& stream ) {
if ( !this->mTableMap.size ()) return;
stream.Print ( "\t--Declaring Tables\n" );
TableMapIt tableIt = this->mTableMap.begin ();
for ( ; tableIt != this->mTableMap.end (); ++tableIt ) {
uintptr tableID = tableIt->first;
stream.Print ( "\t[ 0x%08X ] = {},\n", tableID );
}
stream.Print ( "\n" );
}
示例4: WriteTableInitializer
//----------------------------------------------------------------//
u32 USLuaSerializer::WriteTableInitializer ( USStream& stream, USLuaState& state, int idx, cc8* prefix ) {
u32 count = 0;
u32 itr = state.PushTableItr ( idx );
while ( state.TableItrNext ( itr )) {
switch ( lua_type ( state, -2 )) {
case LUA_TSTRING: {
stream.Print ( "\t%s [ \"%s\" ] = ", prefix, lua_tostring ( state, -2 ));
break;
}
case LUA_TNUMBER: {
stream.Print ( "\t%s [ %s ]\t= ", prefix, lua_tostring ( state, -2 ));
break;
}
};
switch ( lua_type ( state, -1 )) {
case LUA_TBOOLEAN: {
int value = lua_toboolean ( state, -1 );
cc8* str = ( value ) ? "true": "false";
stream.Print ( "%s\n", str );
break;
}
case LUA_TTABLE: {
uintptr tableID = ( uintptr )lua_topointer ( state, -1 );
if ( this->mTableMap.contains ( tableID )) {
stream.Print ( "objects [ 0x%08X ]\n", tableID );
}
break;
}
case LUA_TSTRING: {
STLString str = _escapeString ( lua_tostring ( state, -1 ));
stream.Print ( "\"%s\"\n", str.c_str ());
break;
}
case LUA_TNUMBER: {
stream.Print ( "%s\n", lua_tostring ( state, -1 ));
break;
}
case LUA_TUSERDATA: {
USLuaObject* object = state.GetLuaObject < USLuaObject >( -1 );
u32 instanceID = this->GetID ( object );
stream.Print ( "objects [ 0x%08X ]\n", instanceID );
break;
}
case LUA_TLIGHTUSERDATA: {
stream.Print ( "%p,\n", lua_touserdata ( state, -1 ));
break;
}
};
++count;
}
return count;
}
示例5: WriteObjectInits
//----------------------------------------------------------------//
void MOAISerializer::WriteObjectInits ( USStream& stream ) {
if ( !this->mPending.size ()) return;
while ( this->mPending.size ()) {
MOAILuaObject* object = this->mPending.front ();
assert ( object );
this->mPending.pop_front ();
u32 id = this->GetID ( object );
stream.Print ( "\t--%s\n", object->TypeName ());
stream.Print ( "\tserializer:initObject (\n" );
MOAILuaClass* type = object->GetLuaClass ();
if ( type->IsSingleton ()) {
stream.Print ( "\t\t%s.get (),\n", object->TypeName ());
}
else {
stream.Print ( "\t\tobjects [ 0x%08X ],\n", id );
}
MOAILuaStateHandle state = MOAILuaRuntime::Get ().State ();
object->PushMemberTable ( state );
stream.Print ( "\t\tobjects [ 0x%08X ],\n", this->AffirmMemberID ( state, -1 ));
state.Pop ( 1 );
// this should fill the table for the class
lua_newtable ( state );
object->SerializeOut ( state, *this );
stream.Print ( "\t\t{" );
if ( this->WriteTable ( stream, state, -1, 3 )) {
stream.Print ( "\t\t}\n" );
}
else {
stream.Print ( "}\n" );
}
state.Pop ( 1 );
stream.Print ( "\t)\n\n" );
}
}
示例6: WriteInstanceDecls
//----------------------------------------------------------------//
void USLuaSerializer::WriteInstanceDecls ( USStream& stream ) {
if ( !this->mInstanceMap.size ()) return;
stream.Print ( "\t--Declaring Instances\n" );
InstanceMapIt instanceIt;
instanceIt = this->mInstanceMap.begin ();
for ( ; instanceIt != this->mInstanceMap.end (); ++instanceIt ) {
USLuaObject* object = instanceIt->second;
if ( !object ) continue;
uintptr id = this->GetID ( object );
USLuaClass* type = object->GetLuaClass ();
if ( !type->IsSingleton ()) {
stream.Print ( "\t[ 0x%08X ] = serializer:register ( %s.new (), 0x%08X ),\n", id, object->TypeName (), id );
}
}
stream.Print ( "\n" );
}
示例7: WriteObjectDecls
//----------------------------------------------------------------//
void MOAISerializer::WriteObjectDecls ( USStream& stream ) {
if ( !this->mObjectMap.size ()) return;
stream.Print ( "\t--Declaring Instances\n" );
ObjectMapIt objectIt;
objectIt = this->mObjectMap.begin ();
for ( ; objectIt != this->mObjectMap.end (); ++objectIt ) {
MOAILuaObject* object = objectIt->second;
if ( !object ) continue;
uintptr id = this->GetID ( object );
MOAILuaClass* type = object->GetLuaClass ();
if ( !type->IsSingleton ()) {
stream.Print ( "\t[ 0x%08X ] = serializer:registerObjectID ( %s.new (), 0x%08X ),\n", id, object->TypeName (), id );
}
}
stream.Print ( "\n" );
}
示例8: DebugTimeStamp
UString DebugTimeStamp()
{
using namespace std::chrono;
USStream ss;
system_clock::time_point now_point = system_clock::now();
std::time_t now_time = system_clock::to_time_t(now_point);
#ifdef VIX_SYS_WINDOWS
tm pTime;
localtime_s(&pTime, &now_time);
char buffer[VIX_BUFSIZE];
asctime_s(buffer, &pTime);
ss << buffer;
#else
ss << asctime(localtime(&now_time));
#endif
return ss.str();
}
示例9: WriteTableInits
//----------------------------------------------------------------//
void USLuaSerializer::WriteTableInits ( USStream& stream ) {
if ( !this->mTableMap.size ()) return;
stream.Print ( "\t--Initializing Tables\n" );
stream.Print ( "\tlocal table\n\n" );
USLuaStateHandle state = USLuaRuntime::Get ().State ();
TableMapIt tableIt = this->mTableMap.begin ();
for ( ; tableIt != this->mTableMap.end (); ++tableIt ) {
uintptr tableID = tableIt->first;
stream.Print ( "\ttable = objects [ 0x%08X ]\n", tableID );
USLuaRef& tableRef = tableIt->second;
state.Push ( tableRef );
this->WriteTableInitializer ( stream, state, -1, "table" );
state.Pop ( 1 );
stream.Print ( "\n" );
}
}
示例10: Pipe
//----------------------------------------------------------------//
u32 USStream::Pipe ( USStream& source, u32 size ) {
u8 buffer [ LOCAL_BUFFER ];
u32 readSize = 0;
u32 total = 0;
do {
if (( total + LOCAL_BUFFER ) > size ) {
readSize = source.ReadBytes ( buffer, size - total );
}
else {
readSize = source.ReadBytes ( buffer, LOCAL_BUFFER );
}
if ( readSize ) {
total += this->WriteBytes ( buffer, readSize );
}
} while ( readSize == LOCAL_BUFFER );
return total;
}
示例11: OpenCipher
//----------------------------------------------------------------//
void USCipherStream::OpenCipher ( USStream& stream, USCipher& cipher ) {
assert ( &stream != this );
this->Clear ();
this->mStream = &stream;
this->mCipher = &cipher;
this->mPlainBlockSize = cipher.GetPlainBlockSize ();
this->mCryptBlockSize = cipher.GetCryptBlockSize ();
this->mCryptBaseAddr = stream.GetCursor ();
this->mPlaintext = ( u8* )calloc ( 1, this->mPlainBlockSize );
this->mCrypttext = ( u8* )calloc ( 1, this->mCryptBlockSize );
this->mIsDirty = false;
this->mPlainCursor = 0;
this->mBlockID = 0xffffffff;
this->SyncBlock ( true );
}
示例12: WriteReturnList
//----------------------------------------------------------------//
void MOAISerializer::WriteReturnList ( USStream& stream ) {
if ( !this->mReturnList.size ()) return;
stream.Print ( "\n" );
stream.Print ( "--Returning Tables\n" );
stream.Print ( "return " );
ReturnListIt returnListIt = this->mReturnList.begin ();
for ( ; returnListIt != this->mReturnList.end (); ++returnListIt ) {
if ( returnListIt != this->mReturnList.begin ()) {
stream.Print ( ", " );
}
u32 id = *returnListIt;
stream.Print ( "objects [ 0x%08X ]", id );
}
stream.Print ( "\n" );
}
示例13: SerializeToStream
//----------------------------------------------------------------//
void USLuaSerializer::SerializeToStream ( USStream& stream ) {
stream.Print ( "%s\n", this->GetFileMagic ());
stream.Print ( "serializer = ... or %s.new ()\n", this->TypeName ());
stream.Print ( "\n" );
// write the initializer first, in a function
stream.Print ( "local function init ( objects )\n\n" );
this->WriteTableInits ( stream );
this->WriteInstanceInits ( stream );
stream.Print ( "end\n\n" );
// now write the decls
this->WriteDecls ( stream );
// call the initializer
stream.Print ( "init ( objects )\n" );
this->WriteReturnList ( stream );
}
示例14: WriteInstanceInits
//----------------------------------------------------------------//
void USLuaSerializer::WriteInstanceInits ( USStream& stream ) {
if ( !this->mPending.size ()) return;
while ( this->mPending.size ()) {
USLuaObject* object = this->mPending.front ();
assert ( object );
this->mPending.pop_front ();
u32 id = this->GetID ( object );
stream.Print ( "\t--%s\n", object->TypeName ());
USLuaClass* type = object->GetLuaClass ();
if ( type->IsSingleton ()) {
stream.Print ( "\tserializer:initInstance ( %s.get (), {", object->TypeName ());
}
else {
stream.Print ( "\tserializer:initInstance ( objects [ 0x%08X ], {", id );
}
USLuaStateHandle state = USLuaRuntime::Get ().State ();
lua_newtable ( state );
// this should push the table for the class
object->SerializeOut ( state, *this );
if ( this->WriteTable ( stream, state, -1, 2 )) {
stream.Print ( "\t})\n" );
}
else {
stream.Print ( "})\n" );
}
stream.Print ( "\n" );
}
}
示例15: DumpAsCPPHeader
//----------------------------------------------------------------//
void USHexDump::DumpAsCPPHeader ( USStream& stream, cc8* name, const void* data, size_t size, u32 columns ) {
size_t count;
u8 buffer;
stream.Print ( "#ifndef _%s_H\n", name );
stream.Print ( "#define _%s_H\n", name );
stream.Print ( "\n" );
stream.Print ( "#define %s_SIZE 0x%08X\n", name, ( uint )size );
stream.Print ( "\n" );
stream.Print ( "unsigned char %s [] = {\n\t", name );
for ( count = 0; count < size; count ++ ) {
if ( count ) {
if ( !( count % columns )) {
stream.Print ( "\n\t" );
}
else {
stream.Print ( " " );
}
}
buffer = (( u8* )data )[ count ];
stream.Print ( "0x%02X,", buffer );
};
if ((( count - 1 ) % columns )) {
stream.Print ( "\n" );
}
stream.Print ( "};\n" );
stream.Print ( "\n" );
stream.Print ( "#endif\n" );
}