void Tokenizer::_addToken(std::vector<Token>& tokens, const std::string& text) { // Find the type of token if (opcodes.find(text) != opcodes.end()) { // The token is an opcode Token t(OPCODE, text); tokens.push_back(t); } else if (registers.find(text) != registers.end()) { // The token is a register Token t(REGISTER, text); tokens.push_back(t); } else if (_isValidData(text)) { // The token is data std::string data; _getData(text, data); Token t(DATA, data); tokens.push_back(t); } else if (':' == text[text.size() - 1] && _isValidLabel(text.substr(0, text.size() - 1))) { // The token ends in :, it is a label declaration std::string label = text.substr(0, text.size() - 1); Token t(LABELDECL, label); tokens.push_back(t); } else if (_isValidLabel(text)) { // The token is a label reference Token t(LABELREF, text); tokens.push_back(t); } else { // The token is of an unknown type Token t(UNKNOWN, text); tokens.push_back(t); } }
RecordData WiredTigerRecordStore::dataFor(OperationContext* txn, const RecordId& loc) const { // ownership passes to the shared_array created below WiredTigerCursor curwrap(_uri, _tableId, true, txn); WT_CURSOR* c = curwrap.get(); invariant(c); c->set_key(c, _makeKey(loc)); int ret = WT_OP_CHECK(c->search(c)); massert(28556, "Didn't find RecordId in WiredTigerRecordStore", ret != WT_NOTFOUND); invariantWTOK(ret); return _getData(curwrap); }
bool GAFFile::open(const std::string& filePath, const char* openMode) { close(); m_data = _getData(filePath, openMode, m_dataLen); if (m_data) { return _processOpen(); } return false; }
bool WiredTigerRecordStore::findRecord(OperationContext* txn, const RecordId& loc, RecordData* out) const { WiredTigerCursor curwrap(_uri, _tableId, true, txn); WT_CURSOR* c = curwrap.get(); invariant(c); c->set_key(c, _makeKey(loc)); int ret = WT_OP_CHECK(c->search(c)); if (ret == WT_NOTFOUND) { return false; } invariantWTOK(ret); *out = _getData(curwrap); return true; }
/* * call-seq: * marshal_dump -> Array * * Provides marshalling support for use by the Marshal library. * ===Return value * Array */ DLL_LOCAL VALUE _marshal_dump(VALUE self) { VALUE result = rb_ary_new(); rb_ary_push(result,_GetWidth(self)); rb_ary_push(result,_GetHeight(self)); rb_ary_push(result,_getData(self)); rb_ary_push(result,_getAlpha(self)); rb_ary_push(result,_getMask(self)); #if wxUSE_PALETTE rb_ary_push(result,_getPalette(self)); #else rb_ary_push(result,Qnil); #endif return result; }
int CmdController::Execute() { int return_code = CMD_SUCCESS; try { switch (_cmd) { case CMD_PUT: { WorkProc::getInstance().getQueue()->push(_getQueueName(), _getPriority(), _getData()); _result = std::string("ok\n"); break; } case CMD_GET: { std::string *data = WorkProc::getInstance().getQueue()->pop(_getQueueName()); if (data != NULL) { _result = std::string(*data); delete data; } else { _result = std::string("::no tasks::\n"); } break; } case CMD_POSTPONED: { WorkProc::getInstance().getQueue()->push_postponed(_getQueueName(), _getTime(), _getData()); _result = std::string("ok\n"); break; } case CMD_LENGTH: { _result = std::to_string(WorkProc::getInstance().getQueue()->length(_getQueueName())); break; } case CMD_LIST: _result = WorkProc::getInstance().getQueue()->getQueueList(); break; case CMD_CLEAR: WorkProc::getInstance().getQueue()->clear(_getQueueName()); _result = std::string("ok\n"); break; case CMD_COUNTERS_GET: _result = std::to_string(WorkProc::getInstance().getCounters()->get(_getQueueName())); break; case CMD_COUNTERS_INC: WorkProc::getInstance().getCounters()->inc(_getQueueName()); _result = std::string("ok\n"); break; case CMD_COUNTERS_DEC: WorkProc::getInstance().getCounters()->dec(_getQueueName()); _result = std::string("ok\n"); break; case CMD_COUNTERS_CLEAR: WorkProc::getInstance().getCounters()->clear(_getQueueName()); _result = std::string("ok\n"); break; case CMD_COUNTERS_LIST: _result = WorkProc::getInstance().getCounters()->getList(); break; default: { _result = std::string("Unknown command\n"); return_code = CMD_ERROR; break; } } } catch (const std::exception &ex) { _result = std::string(ex.what()); return_code = CMD_ERROR; } return return_code; }
// Main Function // int main(int argc, char ** argv) { static int flag_help; static int flag_metric; if ( argc > 1 ) { int c; while (1) { static struct option long_options[] = { // Long Option Flags // {"help", no_argument, 0, 'h' }, {"imperial", no_argument, 0, 'i' }, {"metric", no_argument, 0, 'm' }, // Long Option Switches // {"format", required_argument, 0, 'f' }, {"location", required_argument, 0, 'l' }, {0, 0, 0, 0 }, }; int option_index = 0; // Stores the option index c = getopt_long(argc, argv, "hif:l:m", long_options, &option_index); if ( c == -1 ) break; switch (c) { case 'h': flag_help = 1; break; case 'i': flag_metric = 0; break; case 'f': snprintf(formatString, sizeof(formatString), "%s", optarg); break; case 'l': snprintf(passLoc, sizeof(passLoc), "%s", optarg); break; case 'm': flag_metric = 1; break; } } } if ( flag_help == 1 ) _usage(); if ( *passLoc ) // Inspiration: http://www.geekhideout.com/urlcode.shtml { char * end; const long sl = strtol(passLoc, &end, 10); if ( end == passLoc ) { char * pass = passLoc; char * buffer = _malloc(strlen(passLoc) * 3 + 1); char * buff = buffer; while ( *pass ) { if ( isalnum(*pass) ||\ *pass == '-' ||\ *pass == '.' ||\ *pass == ',' ) *buff++ = *pass; else if ( *pass == ' ' ) *buff++ = '+'; pass++; } *buff = '\0'; _getData(buffer, flag_metric); free(buffer); } else if ( sl > 99999 || sl < 00000 ) { fprintf(stderr, "Invalid zip code: %ld\n", sl); exit(1); } else _getData((char * )passLoc, flag_metric); } else { fprintf(stderr, "No specified location\n"); exit(1); } // Call other functions for parsing return 0; }