Beispiel #1
0
//============================================================
void MProperties32::Unpack(TChar32C* pPack){
   TString32Refer value(pPack);
   TInt count = value.Length();
   TInt offset = 0;
   while(offset < count){
      // name
      TFsName32 nameLenLenStr = value.SubStrC(offset, offset + 1);
      offset++;
      TInt nameLenLen = RNumber<TInt32>::ParseSign<TChar32>(nameLenLenStr);
      MO_ASSERT(nameLenLen >0 && nameLenLen <=9);
      TFsName32 nameLenStr = value.SubStrC(offset, offset + nameLenLen);
      offset += nameLenLen;
      TInt nameLen = RNumber<TInt32>::ParseSign<TChar32>(nameLenStr);
      _pNames->Push(value.SubStrC(offset, offset + nameLen));
      offset+= nameLen;
      // value
      TFsName32 valueLenLenStr = value.SubStrC(offset, offset + 1);
      offset++;
      TInt valueLenLen = RNumber<TInt32>::ParseSign<TChar32>(valueLenLenStr);
      MO_ASSERT((valueLenLen > 0) && (valueLenLen <= 9));
      TFsName32 valueLenStr = value.SubStrC(offset, offset + valueLenLen);
      offset += valueLenLen;
      TInt valueLen = RNumber<TInt32>::ParseSign<TChar32>(valueLenStr);
      _pNames->Push(value.SubStrC(offset, offset + valueLen));
      offset+= valueLen;
      ++_count;
   }
}
//============================================================
// <T>从管道内弹出一个完整的数据。</T>
// <P>先读出数据长度(4byte),再读出数据内容。</P>
//
// @param pData 数据指针
// @param capacity 数据长度
// @return 读出数据的长度,为0表示没有读出有效数据,为-1表示读出缓冲不够
//============================================================
EStreamResult FBufferedQueueBlock::Pop(TAny* pData, TInt capacity, TInt* pLength){
   // 检查参数
   MO_ASSERT(pData);
   MO_ASSERT(capacity > 0);
   // 检查容量
   TInt position = _position + sizeof(TInt32);
   if(position >= _length){
      return EStreamResult_ReadEnd;
   }
   // 检查数据长度
   FStreamBlockHead* pHead = (FStreamBlockHead*)(_pMemory + _position);
   // 检查长度
   if(pHead->length > capacity){
      MO_WARN(TC("Current data capacity is not enouth. (data=0x%08X, capacity=%d, length=%d)"), pData, capacity, pHead->length);
      return EStreamResult_ReadCapacity;
   }
   // 检查有效
   if(position + pHead->length > _length){
      MO_WARN(TC("Current data is invalid. (data=0x%08X, capacity=%d, length=%d)"), pData, capacity, pHead->length);
      return EStreamResult_ReadEnd;
   }
   // 读取数据
   MO_LIB_MEMORY_COPY(pData, capacity, pHead->data, pHead->length);
   // 设置位置
#ifdef _MO_DEBUG
   _count--;
#endif // _DEBUG
   _position += sizeof(TInt32) + pHead->length;
   *pLength = pHead->length;
   return EStreamResult_Success;
}
Beispiel #3
0
//============================================================
// <T>将字符串转化为16位字符串</T>
//
// @param pTarget转换后的字符串
// @param size pTarget容量
// @param pValue 被转换字符串
// @return 所需要长度,如果失败返回-1
//============================================================
TInt RString16::ConvertToString16(TChar16* pTarget, TInt size, TChar16C* pValue){
   MO_ASSERT(pTarget);
   MO_ASSERT(pValue);
   TSize length = MO_LIB_STRING_LENGTH16(pValue);
   MO_LIB_MEMORY_COPY(pTarget, sizeof(TChar16) * length, pValue, sizeof(TChar16) * length);
   return length;
}
//============================================================
TBool FNetMessageConsole::ConnectionUnregister(FNetMessageConnection* pConnection){
   MO_ASSERT(pConnection);
   MO_ASSERT(_pConnections->Contains(pConnection));
   _pConnections->Remove(pConnection);
   _pReceiveThread->Unregister(pConnection);
   return ETrue;
}
Beispiel #5
0
//============================================================
// <T>将字符串转化为8位字符串</T>
//
// @param pTarget转换后的字符串
// @param size pTarget容量
// @param pValue 被转换字符串
// @return 所需要长度,如果失败返回-1
//============================================================
TInt RString16::ConvertToString8(TChar8* pTarget, TInt size, TChar16C* pValue){
   MO_ASSERT(pTarget);
   MO_ASSERT(pValue);
   TSize length = MO_LIB_STRING_LENGTH16(pValue);
#ifdef _MO_WINDOWS
   TInt result = WideCharToMultiByte(CP_ACP, 0, pValue, length, pTarget, size, NULL, NULL);
#endif // _MO_WINDOWS
#ifdef _MO_LINUX
   iconv_t code = iconv_open("GBK", "UTF-8");
   if(NULL == code){
      MO_STATIC_FATAL("Iconv open failure.");
   }
   TChar8* pInput = (TChar8*)pValue;
   TSize inputLength = length;
   TSize outputLength = size;
   TInt result = iconv(code, &pInput, &inputLength, &pTarget, &outputLength);
   if(-1 == result){
      MO_STATIC_FATAL("Iconv convert failure.");
      return -1;
   }
   iconv_close(code);
   pTarget[outputLength] = 0;
#endif // _MO_LINUX
#ifdef _MO_ANDROID
   TInt result = length;
   // g_lpdlIcuuc = dlopen("/system/lib/libicuuc.so", RTLD_LAZY);
#endif // _MO_ANDROID
   return result;
}
Beispiel #6
0
//============================================================
// <T>获得运行信息。</T>
//
// @param pDump 运行内容
// @param capacity 容量
// @return 运行信息
//============================================================
TCharC* FClassFactory::Dump(TChar* pDump, TInt capacity){
   MO_ASSERT(pDump);
   MO_ASSERT(capacity > 0);
   TStringRefer dump(pDump, capacity);
   dump.AppendFormat(TC("count=%d"), _pClasses->Count());
   return pDump;
}
Beispiel #7
0
//============================================================
// <T>收集一块指定大小的内存。</T>
//
// @param size 内存大小
// @return 内存指针
//============================================================
TAny* FMemoryAllocator::Alloc(TInt size){
   MO_ASSERT(size > 0);
   SMemoryEntry* pEntry = EntryAlloc();
   MO_ASSERT(pEntry);
   TByte* pMemory = (TByte*)MO_ALIGNED_ALLOC(size, sizeof(TInt));
   pEntry->Link(pMemory, size);
   return pEntry->pMemory;
}
Beispiel #8
0
//============================================================
// <T>收集一块指定大小的内存。</T>
//
// @param pOwnerName 拥有者名称
// @param pTypeName 类型名称
// @param size 内存大小
// @param pFileName 文件名称
// @param fileLine 文件行数
// @return 内存指针
//============================================================
TAny* FMemoryAllocator::Alloc(TCharC* pOwnerName, TCharC* pTypeName, TInt size, TChar8C* pFileName, TInt lineNumber){
   MO_ASSERT(size > 0);
   SMemoryEntry* pEntry = EntryAlloc();
   MO_ASSERT(pEntry);
   TByte* pMemory = (TByte*)MO_ALIGNED_ALLOC(size, sizeof(TInt));
   pEntry->SetTypeName(pTypeName);
   pEntry->SetFileInfo(pFileName, lineNumber);
   pEntry->Link(pMemory, size);
   return pEntry->pMemory;
}
Beispiel #9
0
//============================================================
// <T>将一个完整信息写入管道。</T>
// <P>先写入数据长度(4byte),再写入数据内容。
//    数据内容可能被分成两端放入管道的尾部和首部。</P>
//    每次结尾位置的偏移只能为4byte的倍数(sizeof(TUint32))。
// </P>
//
// @param pData 数据指针
// @param capacity 数据长度
// @return 压入是否成功
//============================================================
TBool FQueue::Push(TAnyC* pData, TInt size){
   // 检查参数
   MO_ASSERT(pData);
   if(0 == size){
      return ETrue;
   }
   // 获取变量
   SPipeAtom atom = Atom();
   // 判断是否可以写入
   if((atom.capacity - atom.length) < (size + MoPipeReserveLength)){
      return EFalse;
   }
   // 写入数据
   TInt position = 0;
   if(atom.first <= atom.last){
      // 处理写入数据 [---F===L----]
      TInt remain = atom.capacity - atom.last;
      MO_ASSERT(remain >= (TInt)sizeof(TUint32));
      *(TUint32*)(atom.memoryPtr + atom.last) = size;
      remain -= sizeof(TUint32);
      TByte* pLast = atom.memoryPtr + atom.last + sizeof(TUint32);
      // 写入数据
      if(size < remain){
         memcpy(pLast, pData, size);
         position = atom.last + sizeof(TUint32) + size;
      }else if(size == remain){
         memcpy(pLast, pData, size);
         position = 0;
      }else{
         memcpy(pLast, pData, remain);
         memcpy(atom.memoryPtr, (TByte*)pData + remain, size - remain);
         position = size - remain;
      }
   }else{
      // 处理写入数据 [===L---F====]
      TByte* pWrite = atom.memoryPtr + atom.last;
      *(TUint32*)pWrite = size;
      pWrite += sizeof(TUint32);
      // 写入数据
      memcpy(pWrite, pData, size);
      position = atom.last + sizeof(TUint32) + size;
   }
   // 设置结尾位置
   TInt mod = position % sizeof(TUint32);
   if(0 != mod){
      position += sizeof(TUint32) - mod;
   }
   if(position == atom.capacity){
      position = 0;
   }
   atom.SetLast(position);
   return ETrue;
}
Beispiel #10
0
//============================================================
// <T>从管道内弹出一个完整的消息。</T>
// <P>先读出数据长度(4byte),再读出数据内容。
//    数据内容可能被分成两端放入管道的尾部和首部。</P>
//    每次开始位置的偏移只能为4byte的倍数(sizeof(TUint32))。
// </P>
//
// @param pData 数据指针
// @param capacity 数据长度
// @return 读出数据的长度,为0表示没有读出有效数据
//============================================================
TInt FQueue::Pop(TAny* pData, TInt capacity){
   // 检查参数
   MO_ASSERT(pData);
   MO_ASSERT(capacity > 0);
   // 获取变量
   SPipeAtom atom = Atom();
   // 判断是否可以读出
   if(atom.length <= (TInt)sizeof(TUint32)){
      return 0;
   }
   TByte* pRead = atom.memoryPtr + atom.first;
   TInt size = *(TUint32*)pRead;
   MO_ASSERT(size > 0);
   MO_ASSERT(size <= atom.capacity);
   MO_ASSERT(size <= atom.length);
   pRead += sizeof(TUint32);
   // 读取数据
   TInt position = 0;
   if(atom.first < atom.last){
      // 处理读取数据 [---F===L----]
      memcpy(pData, pRead, size);
      position = atom.first + sizeof(TUint32) + size;
   }else{
      // 处理读取数据 [===L---F====]
      TInt remain = atom.capacity - atom.first - sizeof(TUint32);
      if(size < remain){
         memcpy(pData, pRead, size);
         position = atom.first + sizeof(TUint32) + size;
      }else if(size == remain){
         memcpy(pData, pRead, size);
         position = 0;
      }else{
         memcpy(pData, pRead, remain);
         memcpy((TByte*)pData + remain, atom.memoryPtr, size - remain);
         position = size - remain;
      }
   }
   // 设置开始位置
   TInt mod = position % sizeof(TUint32);
   if(0 != mod){
      position += sizeof(TUint32) - mod;
   }
   if(position == atom.capacity){
      position = 0;
   }
   atom.SetFirst(position);
   return size;
}
Beispiel #11
0
//============================================================
// <T>反序列化数据区到内部数据。</T>
//
// @param pMemory 数据指针
// @param size 数据长度
// @param [out] length 读取长度
//============================================================
TBool TNetMessageBuffer::UnserializeMask(TAnyC* pMemory, TInt size, TInt* length){
   MO_ASSERT(pMemory);
   TByteC* pPtr = (TByteC*)pMemory;
   // 反序列化头数据
   TInt offset = 0;
   offset += _netHead.Unserialize(pPtr);
   TNetLength netLength = _netHead.Length();
   TNetHash netHash = _netHead.Hash();
   offset += _messageHead.Unserialize(pPtr + offset);
   TNetSerial messageSerial = _messageHead.Serial();
   TNetTick messageTick = _messageHead.Tick();
   // 获取数据
   TByteC* pData = pPtr + offset;
   TInt dataLength = netLength - offset;
   // 还原数据
   TByte buffer[MO_NETMESSAGE_MAXLENGTH];
   MaskData(buffer, MO_NETMESSAGE_MAXLENGTH, pData, dataLength, netHash);
   //TChar dump[MO_FS_DUMP_LENGTH];
   //MO_ERROR("Receive message data failure.\n%s",
   //      RByte::Dump(buffer, dataLength, dump, MO_FS_DUMP_LENGTH));
   // 检查哈希
   TNetHash hash = CalculateHash(messageSerial, messageTick, buffer, dataLength);
   if(netHash != hash){
      MO_WARN(TC("Unserialize message invalid hash. (head_hash=0x%08X, data_hash=0x%08X)"), netHash, hash);
      return EFalse;
   }
   // 设置数据
   if(dataLength > 0){
      memcpy(_buffer, buffer, dataLength);
   }
   _dataLength = dataLength;
   *length = netLength;
   return ETrue;
}
Beispiel #12
0
 void serialize(AR& ar, cv::Matx<T, rows, cols>& mat){
     cereal::size_type size = rows * cols;;
     ar(cereal::make_size_tag(size));
     MO_ASSERT(size == rows * cols);
     for(int i = 0; i < rows * cols; ++i)
         ar(mat.val[i]);
 }
Beispiel #13
0
//============================================================
// <T>配置处理。</T>
//
// @return 处理结果
//============================================================
TResult FDisplayLayer::Setup(){
   MO_ASSERT(!_pParticleController);
   _pParticleController = MO_CREATE(FParticleController);
   _visualRegion = FVisualRegion::InstanceCreate();
   RVisualManager::Instance().RegionRegister(_visualRegion);
   return ESuccess;
}
Beispiel #14
0
//============================================================
// <T>压缩内部数据到数据区。</T>
//
// @param pMemory 数据指针
// @param size 数据长度
// @param [out] length 读取长度
//============================================================
TBool TNetMessageBuffer::Compress(TAny* pMemory, TInt size, TInt* pLength){
   MO_ASSERT(pMemory);
   TByte* pPtr = (TByte*)pMemory;
   // 获得头长度
   TInt netCapacity = _netHead.Capacity();
   TInt messageCapacity = _messageHead.Capacity();
   TNetSerial messageSerial = _messageHead.Serial();
   TNetTick messageTick = _messageHead.Tick();
   TInt headCapacity = netCapacity + messageCapacity;
   TSize capacity = headCapacity + _dataLength;
   // 设置头信息
   TNetHash hash = CalculateHash(messageSerial, messageTick, _pData, _dataLength);
   _netHead.SetLength((TNetLength)capacity);
   _netHead.SetHash(hash);
   // 序列头信息
   _netHead.Serialize(pPtr);
   _messageHead.Serialize(pPtr + headCapacity);
   // 压缩数据
   TInt length = 0;
   if(!RCompress::CompressRLE(pPtr + headCapacity, size, _pData, _dataLength, &length)){
      return EFalse;
   }
   // 设置序列化后大小
   *pLength = headCapacity + length;
   return ETrue;
}
Beispiel #15
0
//============================================================
// <T>释放内存。</T>
//
// @param pMemory 内存指针
//============================================================
void FMemoryAllocator::Free(TAny* pMemory){
   // 获得当前使用的实例
   MO_ASSERT(pMemory);
   TInt* pAlloc = ((TInt*)pMemory) - 1;
   SMemoryEntry* pEntry = (SMemoryEntry*)pAlloc[0];
   MO_ASSERT(pEntry);
   // 检查内存转换正确性
   MO_ASSERT(pEntry->pAllocator == this);
   MO_ASSERT(pEntry->pMemory == pMemory);
   // 释放内存
   MO_ALIGNED_FREE(pEntry->pAlloc);
   // 记录释放操作
   pEntry->Free();
   // 压入未使用的队列
   //MLinkedEntryC<SMemoryEntry*>::EntryFree(pEntry);
}
Beispiel #16
0
//============================================================
// <T>调整内存大小。</T>
//
// @param size 大小
// @param copy 复制
// @param extends 扩展
//============================================================
void TStringBuffer8::InnerResize(TInt size, TBool copy, TBool extends, TBool force){
   if(size > _capacity){
      // 当内存不足时,重新计算内存容量
      TInt capacity = size;
      if(extends){
         capacity = RTypes<TChar8>::CalculateTypeCapacity(_capacity, size);
      }
      // 如果收集不成功,则不进行复制数据处理
      TChar8* pAlloc = MO_TYPES_ALLOC(TChar8, capacity);
      MO_ASSERT(pAlloc);
      // 如果存在以前内存
      if(NULL != _pMemory){
         // 如果是缩小内存,则检查长度
         if(_length > capacity){
            _length = capacity;
         }
         // 复制有效数据
         if(copy && (_length > 0)){
            MO_LIB_TYPES_COPY(TChar8, pAlloc, capacity, _pMemory, _length);
         }
         // 释放以前内存
         MO_FREE(_pMemory);
      }
      // 设置新的内存
      _pMemory = pAlloc;
      _pMemory[_length] = 0;
      _capacity = capacity;
   }
}
Beispiel #17
0
//============================================================
void TNetMessageBuffer::AssignData(TByteC* pData, TInt length){
   MO_ASSERT(pData);
   if(length > 0){
      memcpy(_buffer, pData, length);
   }
   _dataLength = length;
}
//============================================================
// <T>将一个数据写入管道。</T>
//
// @param pData 数据指针
// @param length 数据长度
// @return 压入是否成功
//============================================================
EStreamResult FBufferedQueueBlock::Push(TAnyC* pData, TInt length){
   // 检查参数
   MO_ASSERT(pData);
   // 检查长度
   if(0 == length){
      MO_WARN(TC("Write empty data. (data=0x%08X, length=%d)"), pData, length);
      return EStreamResult_WriteEmpty;
   }
   // 判断管道是否可以写入
   TInt free = _length - _position;
   TInt dataSize = sizeof(TInt32) + length;
   if(dataSize > free){
      MO_WARN(TC("Current queue is full. (data=0x%08X, capacity=%d, position=%d, free=%d, length=%d)"), pData, _capacity, _position, free, length);
      return EStreamResult_WriteFull;
   }
   // 写入数据
   FStreamBlockHead* pHead = (FStreamBlockHead*)(_pMemory + _position);
   pHead->length = length;
   MO_LIB_MEMORY_COPY(pHead->data, free, pData, length);
   // 设置位置
   _position += sizeof(TInt32) + length;
#ifdef _MO_DEBUG
   _count++;
   if(_count > _countMax){
      _countMax = _count;
   }
#endif // _DEBUG
   return EStreamResult_Success;
}
Beispiel #19
0
//============================================================
// <T>压入一个消息。</T>
//
// @param pMessage 消息对象
// @return  处理结果
//============================================================
TBool FNetBufferedQueue::PushTransfer(TNetTransfer* pTransfer){
   MO_ASSERT(pTransfer);
   // 序列化路由数据
   TInt length = 0;
   TByte buffer[MO_NETMESSAGE_MAXLENGTH];
   if(!pTransfer->Serialize(buffer, MO_NETMESSAGE_MAXLENGTH, &length)){
      MO_FATAL("Transfer serialize failure. (message_code=%d)", pTransfer->MessageHead().Code());
      return EFalse;
   }
   if(length <= 0){
      MO_FATAL("Transfer serialize failure. (message_code=%d, length=%d)", pTransfer->MessageHead().Code(), length);
      return EFalse;
   }
   // 消息检查
   TInt bufferLength = *(TInt32*)(TAny*)buffer;
   if(bufferLength > MO_NETMESSAGE_MAXLENGTH){
      MO_FATAL("Write message length is error. (memory=0x%08X, block_length=%d)", buffer, bufferLength);
   }
   if(length > MO_NETMESSAGE_MAXLENGTH){
      MO_FATAL("Write data length is error. (memory=0x%08X, data_length=%d)", buffer, length);
   }
   if(bufferLength != length){
      MO_FATAL("Write data length is not equals. (memory=0x%08X, block_length=%d, data_length=%d)", buffer, bufferLength, length);
   }
   // 将数据放入管道
   return FBufferedQueue::Push(buffer, length);
}
Beispiel #20
0
//============================================================
// <T>序列化路由数据到数据区。</T>
//
// @param pMemory 数据指针
// @param size 数据大小
// @param length 处理大小
//============================================================
TBool TNetRouter::SerializeRouter(TAny* pMemory, TInt size, TInt* length){
   MO_ASSERT(pMemory);
   TByte* pPtr = (TByte*)pMemory;
   // 获取头大小
   TInt netCapacity = _netHead.Capacity();
   TInt messageCapacity = _messageHead.Capacity();
   TNetSerial messageSerial = _messageHead.Serial();
   TNetTick messageTick = _messageHead.Tick();
   TInt routerCapacity = _routerHead.Capacity();
   TInt headCapacity = netCapacity + messageCapacity + routerCapacity;
   TInt capacity = headCapacity + _dataLength;
   TByte* pData = pPtr + headCapacity;
   // 设置头信息
   TNetHash hash = CalculateHash(messageSerial, messageTick, _pData, _dataLength);
   _netHead.SetLength((TNetLength)capacity);
   _netHead.SetProtocol(ENetProtocol_Router);
   _netHead.SetHash(hash);
   // 序列化头数据
   TInt offset = 0;
   offset += _netHead.Serialize(pPtr);
   offset += _messageHead.Serialize(pPtr + offset);
   offset += _routerHead.Serialize(pPtr + offset);
   if(_dataLength > 0){
      memcpy(pData, _pData, _dataLength);
   }
   // 设置序列化后大小
   *length = capacity;
   return ETrue;
}
Beispiel #21
0
//============================================================
// <T>反序列化数据区到内部数据。</T>
//
// @param pMemory 数据指针
// @param size 数据长度
// @param [out] length 读取长度
//============================================================
TBool TNetMessageBuffer::Unserialize(TAnyC* pMemory, TInt size, TInt* length){
   MO_ASSERT(pMemory);
   TByteC* pPtr = (TByteC*)pMemory;
   // 反序列化头数据
   TInt offset = 0;
   offset += _netHead.Unserialize(pPtr);
   offset += _messageHead.Unserialize(pPtr + offset);
   TNetSerial messageSerial = _messageHead.Serial();
   TNetTick messageTick = _messageHead.Tick();
   // 获取数据
   TNetLength netLength = _netHead.Length();
   TByteC* pData = pPtr + offset;
   TInt dataLength = netLength - offset;
   // 检查哈希
   TNetHash hash = CalculateHash(messageSerial, messageTick, pData, dataLength);
   if(_netHead.Hash() != hash){
      MO_WARN(TC("Unserialize message invalid hash. (head_hash=0x%08X, data_hash=0x%08X)"),
            _netHead.Hash(), hash);
      return EFalse;
   }
   // 设置数据
   if(dataLength > 0){
      memcpy(_buffer, pData, dataLength);
   }
   _dataLength = dataLength;
   *length = netLength;
   return ETrue;
}
Beispiel #22
0
//============================================================
// <T>序列化内部数据到数据区。</T>
//
// @param pMessage 消息对象
//============================================================
TBool TNetMessageBuffer::Serialize(TAny* pMemory, TInt size, TInt* length){
   MO_ASSERT(pMemory);
   TByte* pPtr = (TByte*)pMemory;
   // 获得头长度
   TInt netCapacity = _netHead.Capacity();
   TInt messageCapacity = _messageHead.Capacity();
   TNetSerial messageSerial = _messageHead.Serial();
   TNetTick messageTick = _messageHead.Tick();
   TInt headCapacity = netCapacity + messageCapacity;
   TSize capacity = headCapacity + _dataLength;
   // 设置头信息
   TNetHash hash = CalculateHash(messageSerial, messageTick, _pData, _dataLength);
   _netHead.SetLength((TNetLength)capacity);
   _netHead.SetHash(hash);
   // 序列头信息
   _netHead.Serialize(pPtr);
   _messageHead.Serialize(pPtr + headCapacity);
   // 序列化数据
   if(_dataLength > 0){
      memcpy(pPtr + headCapacity, _pData, _dataLength);
   }
   // 设置序列化后大小
   *length = capacity;
   return ETrue;
}
Beispiel #23
0
//============================================================
void MProperties32::Set(TChar32C* pName, TChar32C* pValue){
   TInt index = _pNames->IndexOf(pName);
   MO_ASSERT(ENotFound != index);
   while(ENotFound != index){
      _pValues->Set(index, pValue);
      index = _pNames->IndexOf(pName);
   }
}
Beispiel #24
0
//============================================================
// <T>弹出陷阱对象。</T>
//============================================================
void FThreadTrap::Pop(){
   MO_ASSERT(_pUsed);
   // 获得当前使用的实例
   FTrap* pTrap = _pUsed;
   _pUsed = pTrap->Parent();
   // 压入未使用的队列
   pTrap->SetParent(_pUnused);
   _pUnused = pTrap;
}
Beispiel #25
0
//============================================================
// <T>收集一个实例。</T>
//
// @param pName 名称
// @return 实例
//============================================================
FInstance* FClassFactory::Alloc(TCharC* pName){
   MO_ASSERT(pName);
   FInstance* pInstance = NULL;
   FClass* pClass = _pClasses->Find(pName);
   if(pClass != NULL){
      pInstance = pClass->InstanceAlloc();
   }
   return pInstance;
}
//============================================================
// <T>设置处理。</T>
//
// @param capacity 容量
// @param pAllocator 收集器
//============================================================
void FNetBufferedQueueConnection::Setup(TInt capacity, FBufferedQueueBlockAllocator* pAllocator){
   MO_ASSERT(capacity > 0);
   // 设置输入流
   _pInputQueue->SetLockCd(EStreamLock_Lock);
   _pInputQueue->Pool()->SetCapacity(capacity);
   _pInputQueue->SetAllocator(pAllocator);
   // 设置输出流
   _pOutputQueue->SetLockCd(EStreamLock_Lock);
   _pOutputQueue->Pool()->SetCapacity(capacity);
   _pOutputQueue->SetAllocator(pAllocator);
}
Beispiel #27
0
//============================================================
TString32 MProperties32::Remove(TChar32C* pName){
   TString32 value;
   TInt index = _pNames->IndexOf(pName);
   MO_ASSERT(ENotFound != index);
   value.Append(_pNames->Get(index));
   value.Append(_pValues->Get(index));
   _pNames->Delete(index);
   _pValues->Delete(index);
   --_count;
   return value;
}
Beispiel #28
0
//============================================================
// <T>压入一个消息。</T>
//
// @param pMessage 消息对象
// @return  处理结果
//============================================================
TBool FNetBufferedQueue::PushMessage(TNetMessage* pMessage){
   MO_ASSERT(pMessage);
   // 序列化路由数据
   TInt length;
   TByte buffer[MO_NETMESSAGE_MAXLENGTH];
   if(!pMessage->Serialize(buffer, MO_NETMESSAGE_MAXLENGTH, &length)){
      MO_FATAL("Message serialize failure.");
   }
   // 将数据放入管道
   return FBufferedQueue::Push(buffer, length);
}
Beispiel #29
0
//============================================================
// <T>压入一个路由。</T>
//
// @param pRouter 路由对象
// @return  处理结果
//============================================================
TBool FNetBufferedQueue::PushRouter(TNetRouter* pRouter){
   MO_ASSERT(pRouter);
   // 序列化路由数据
   TInt length;
   TByte buffer[MO_NETMESSAGE_MAXLENGTH];
   if(!pRouter->Serialize(buffer, MO_NETMESSAGE_MAXLENGTH, &length)){
      MO_FATAL("Router serialize failure.");
   }
   // 将数据放入管道
   return FBufferedQueue::Push(buffer, length);
}
Beispiel #30
0
//============================================================
// <T>解析16进制字符串。</T>
//
// @param pSource 来源
// @param length 长度
// @return 内容
//============================================================
TUint32 RUint32::ParseHex(TCharC* pSource, TInt length){
   MO_ASSERT(pSource);
   TUint32 v0 = ((TUint32)RByte::HEX_BYTES[(TInt)pSource[0]]) << 28;
   TUint32 v1 = ((TUint32)RByte::HEX_BYTES[(TInt)pSource[1]]) << 24;
   TUint32 v2 = ((TUint32)RByte::HEX_BYTES[(TInt)pSource[2]]) << 20;
   TUint32 v3 = ((TUint32)RByte::HEX_BYTES[(TInt)pSource[3]]) << 16;
   TUint32 v4 = ((TUint32)RByte::HEX_BYTES[(TInt)pSource[4]]) << 12;
   TUint32 v5 = ((TUint32)RByte::HEX_BYTES[(TInt)pSource[5]]) <<  8;
   TUint32 v6 = ((TUint32)RByte::HEX_BYTES[(TInt)pSource[6]]) <<  4;
   TUint32 v7 = ((TUint32)RByte::HEX_BYTES[(TInt)pSource[7]])      ;
   return v0 | v1 | v2 | v3 | v4 | v5 | v6 | v7;
}