static DUMP_INFO* dumpTitle( // DUMP A TITLE LINE DUMP_INFO *di, // - dump information const char *title, // - title line const char *class_name ) // - name of class { di = bufferRewind( di ); di = bufferChr( di, '\n' ); di = bufferStr( di, title ); di = bufferChr( di, ' ' ); di = bufferStr( di, class_name ); di = bufferWrite( di ); return di; }
static DUMP_INFO* bufferNmb( // CONCATENATE NUMBER TO BUFFER DUMP_INFO* di, // - dump information unsigned numb ) // - to be concatenated { char buf[16]; // - buffer VbufConcDecimal( &di->buffer, numb ); if( numb >= 10 ) { itoa( numb, buf, 16 ); di = bufferStr( di, "/0x" ); di = bufferStr( di, buf ); } return di; }
static DUMP_INFO* dumpStruct( // DUMP A STRUCTURE TYPE type, // - structure type DUMP_INFO* di, // - dump information char* title, // - title for dump ds_control control ) // - control word { CLASSINFO* info; // - class information NAME *parent; // - where parent ptr is stored control = control; type = StructType( type ); info = type->u.c.info; parent = VstkPush( &di->stack ); *parent = info->name; di = dumpTitle( di, title, NameStr( info->name ) ); if( type != di->original ) { di = bufferInit( di ); di = bufferStr( di, "embedded size: " ); di = bufferNmb( di, info->vsize ); di = bufferWrite( di ); di = dumpOffset( di ); di = dumpParentage( di ); } else { di = bufferInit( di ); di = bufferStr( di, "size: " ); di = bufferNmb( di, info->size ); di = bufferWrite( di ); } if( info->has_vbptr ) { di = dumpDataMemb( di , "[virtual" , "base pointer]" , info->vb_offset + di->offset , CgMemorySize( TypePtrToVoid() ) ); } if( info->has_vfptr ) { di = dumpDataMemb( di , "[virtual" , "functions pointer]" , info->vf_offset + di->offset , CgMemorySize( TypePtrToVoid() ) ); } ScopeWalkDataMembers( type->u.c.scope, dumpMember, di ); if( type == di->original ) { ScopeWalkVirtualBases( type->u.c.scope, dumpVirtual, di ); } ScopeWalkDirectBases( type->u.c.scope, dumpDirect, di ); VstkPop( &di->stack ); return di; }
static DUMP_INFO* dumpParentage( // DUMP PARENTAGE DUMP_INFO* di ) // - dump information { char**daughter; // - daughter class for( daughter = VstkTop( &di->stack ); ; ) { daughter = VstkNext( &di->stack, daughter ); if( daughter == NULL ) break; di = bufferInit( di ); di = bufferStr( di, "base of: " ); di = bufferStr( di, *daughter ); di = bufferWrite( di ); } return di; }
// Load JSON from URL Value loadUrl(const string & url, bool isEscaped) { // Load URL DataSourceRef dataSource = ci::loadUrl(Url(url, isEscaped)); // Read buffer Buffer buffer; try { buffer = dataSource->getBuffer(); } catch (...) { Value value; return value; } size_t dataSize = buffer.getDataSize(); shared_ptr<int_fast8_t> bufferStr(new int_fast8_t[dataSize + 1], checked_array_deleter<int_fast8_t>()); memcpy(bufferStr.get(), buffer.getData(), buffer.getDataSize()); bufferStr.get()[dataSize] = 0; // Convert buffer to string, deserialize and return return deserialize(string(reinterpret_cast<char *>(bufferStr.get()))); }
extern "C" NS_GFX_(PRBool) NS_HexToRGB(const nsString& aColorSpec, nscolor* aResult) { // XXXldb nsStackString<10> NS_LossyConvertUCS2toASCII bufferStr(aColorSpec); return NS_ASCIIHexToRGB(bufferStr, aResult); }
static DUMP_INFO* bufferInit( // INITIALIZE BUFFER (NON-TITLE LINE) DUMP_INFO* di ) // - dump information { di = bufferRewind( di ); di = bufferStr( di, " " ); return di; }
const std::string TCPSocket::socketReceive(size_t dataLength) { printf("Data to receive length: %lu\n", dataLength); size_t receivedData = 0; std::string dataReceived; bool socketOpen = true; while (receivedData < dataLength && socketOpen == true) { int result; std::vector<char> buffer; buffer.resize(dataLength - receivedData, 0); result = recv(this->socketFd, &(buffer[0]), dataLength, 0); if (result == SOCKET_ERROR) { perror("Socket receive error"); printf("Socket receive error: %sn\n", strerror(errno)); exit(1); } else if (result == SOCKET_CLOSE) { perror("Socket receive close"); printf("Socket receive close: %sn\n", strerror(errno)); socketOpen = false; } receivedData += result; std::string bufferStr(buffer.begin(), buffer.end()); std::string acumStr(dataReceived.c_str()); dataReceived = acumStr + bufferStr; printf("Datos parciales recibidos: %lu/%lu Texto: %s\n", receivedData, dataLength, bufferStr.c_str()); printf("Acumulado: %s\n", dataReceived.c_str()); } printf("Datos recibidos: %s\n", dataReceived.c_str()); return dataReceived; }
static DUMP_INFO* dumpDataMemb( // DUMP A DATA MEMBER DUMP_INFO *di, // - dump information const char *kind, // - kind of field const char *name, // - field name target_offset_t offset, // - field offset target_size_t size ) // - field size { di = bufferInit( di ); di = bufferStr( di, kind ); di = bufferChr( di, ' ' ); di = bufferStr( di, name ); di = bufferStr( di, ", offset = " ); di = bufferNmb( di, offset ); di = bufferStr( di, ", size = " ); di = bufferNmb( di, size ); di = bufferWrite( di ); return di; }
static DUMP_INFO* dumpOffset( // DUMP OFFSET LINE DUMP_INFO* di ) // - dump information { di = bufferInit( di ); di = bufferStr( di, "offset of class: " ); di = bufferNmb( di, di->offset ); di = bufferWrite( di ); return di; }
Aws::String GetExecutableDirectory() { static const unsigned long long bufferSize = 256; WCHAR buffer[bufferSize]; memset(buffer, 0, sizeof(buffer)); if (GetModuleFileNameW(nullptr, buffer, static_cast<DWORD>(sizeof(buffer)))) { Aws::String bufferStr(Aws::Utils::StringUtils::FromWString(buffer)); auto fileNameStart = bufferStr.find_last_of(PATH_DELIM); if (fileNameStart != std::string::npos) { bufferStr = bufferStr.substr(0, fileNameStart); } return bufferStr; } return ""; }
bool SVGImage::Load (uint8* iBuffer, size_t iSize) { AllocatorCS allocator; CS::Utility::ScopedDelete<vgvm::cairo::CairoContext> context ( vgvm::cairo::createCairoContext (&allocator)); CS::Utility::ScopedDelete<vgvm::Program> prog (context->createProgram ()); { csString bufferStr ((char*)iBuffer, iSize); if (!vgvm::svg::compileSVG (bufferStr, prog)) return false; } uint width = 256; uint height = 256; uint8* buf_bgra = (uint8*)cs_malloc (width * height * 4); context->setOutput (buf_bgra, width, height, true); context->executeProgram (prog); csRGBpixel* buf = new csRGBpixel[width * height]; size_t numPix = width * height; const uint8* sp = buf_bgra; csRGBpixel* dp = buf; while (numPix-- > 0) { dp->blue = *sp++; dp->green = *sp++; dp->red = *sp++; dp->alpha = *sp++; dp++; } cs_free (buf_bgra); Format |= ~CS_IMGFMT_ALPHA; SetDimensions (width, height); ConvertFromRGBA (buf); return true; }
void TartarLayer::onHttpRequestCompleted(CCHttpClient *sender, CCHttpResponse *response) { if (!response) { return; } int statusCode = response->getResponseCode(); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); CCLog("response code: %d", statusCode); if (!response->isSucceed()) { CCLog("response failed"); CCLog("error buffer: %s", response->getErrorBuffer()); return; } // dump data std::vector<char> *buffer = response->getResponseData(); std::string bufferStr(buffer->begin(),buffer->end()); if (std::string(response->getHttpRequest()->getTag()) == std::string("GET INFO")) { // Display the memberId and name. cJSON* json; json = cJSON_Parse(bufferStr.c_str()); if (json) { cJSON* messageJSON = cJSON_GetObjectItem(json, "message"); if (messageJSON) { // Set NeedCheck label UILabel* pUILabelWarning = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_NeedCheck")); pUILabelWarning->setVisible(true); pUILabelWarning->setText(messageJSON->valuestring); } cJSON* imageJSON = cJSON_GetObjectItem(json, "image"); if (imageJSON) { std::string imagePath = imageJSON->valuestring; CCHttpRequest* request = new CCHttpRequest(); std::string url = "http://localhost:8000/media/" + imagePath; request->setUrl(url.c_str()); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(TartarLayer::onHttpRequestCompleted)); request->setTag("GET IMAGE"); CCHttpClient::getInstance()->send(request); request->release(); int index = imagePath.find_last_of("."); if (index != -1) { m_textureFormat = imagePath.substr(index); } } } } else { std::string path = CCFileUtils::sharedFileUtils()->getWritablePath(); // Save it locally path += "currentTeeth"; path += m_textureFormat; CCLOG("path: %s",path.c_str()); FILE *fp = fopen(path.c_str(), "wb+"); fwrite(bufferStr.c_str(), 1,buffer->size(), fp); fclose(fp); // Display UIImageView* pImage = DynamicCast<UIImageView*>(UiManager::Singleton().GetChildByName("ImageView")); pImage->setTexture(path.c_str()); CCRect rect = pImage->getRect(); float normalWidth = cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width - 10.0f; float normalHeight = normalWidth * 0.6f; pImage->setScaleX(normalWidth / rect.size.width * pImage->getScaleX()); pImage->setScaleY(normalHeight / rect.size.height * pImage->getScaleY()); } }
void LoginLayer::onHttpRequestCompleted(CCHttpClient *sender, CCHttpResponse *response) { if (!response) { UILabel* pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_Fail")); pUILabel->setVisible(true); return; } int statusCode = response->getResponseCode(); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); CCLog("response code: %d", statusCode); if (!response->isSucceed()) { UILabel* pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_Fail")); pUILabel->setVisible(true); return; } // Success! // Enter next UI page UIWidget* pUIWidget = UiManager::Singleton().GetChildByName("Panel_Login"); pUIWidget->setVisible(false); EnableTextField(false); pUIWidget = UiManager::Singleton().GetChildByName("Panel_LoginConfirm"); pUIWidget->setVisible(true); UILabel* pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_Fail")); pUILabel->setVisible(false); // Dump data std::vector<char> *buffer = response->getResponseData(); std::string bufferStr(buffer->begin(),buffer->end()); // Display the memberId and name. cJSON* json; json = cJSON_Parse(bufferStr.c_str()); if (json) { cJSON* memberIdJSON = cJSON_GetObjectItem(json, "member_id"); if (memberIdJSON) { UILabel* pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_NumberValue")); pUILabel->setText(memberIdJSON->valuestring); } cJSON* nameJSON = cJSON_GetObjectItem(json, "name"); if (nameJSON) { UILabel* pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_NameValue")); pUILabel->setText(nameJSON->valuestring); // Save clinic name GameData::Singleton().SetClinicName(std::string(nameJSON->valuestring)); } cJSON* homePageJSON = cJSON_GetObjectItem(json, "homepage"); if (homePageJSON) { // Save homepage Url GameData::Singleton().SetHomePageUrl(std::string(homePageJSON->valuestring)); } cJSON* mapPathJSON = cJSON_GetObjectItem(json, "map"); if (mapPathJSON) { // Save mapPath GameData::Singleton().SetMapPath(std::string(mapPathJSON->valuestring)); } } }