本文整理汇总了C++中ObString::ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ ObString::ptr方法的具体用法?C++ ObString::ptr怎么用?C++ ObString::ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObString
的用法示例。
在下文中一共展示了ObString::ptr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
int ObMergerTabletLocationCache::update(const uint64_t table_id, const ObString & rowkey,
const ObMergerTabletLocationList & location)
{
int ret = OB_SUCCESS;
if (!init_)
{
TBSYS_LOG(ERROR, "%s", "check init failed");
ret = OB_INNER_STAT_ERROR;
}
else if ((0 == rowkey.length()) || (NULL == rowkey.ptr()))
{
TBSYS_LOG(ERROR, "%s", "check rowkey length failed");
ret = OB_INPUT_PARAM_ERROR;
}
else
{
char * temp = (char *)ob_malloc(sizeof(table_id) + rowkey.length(),ObModIds::OB_MS_LOCATION_CACHE);
if (NULL == temp)
{
TBSYS_LOG(ERROR, "check ob malloc failed:size[%lu], pointer[%p]",
sizeof(table_id) + rowkey.length(), temp);
ret = OB_ALLOCATE_MEMORY_FAILED;
}
else
{
ObRange range;
ObString CacheKey;
// encode table_id + rowkey as CacheKey
*((uint64_t *) temp) = table_id;
memcpy(temp + sizeof(uint64_t), rowkey.ptr(), rowkey.length());
CacheKey.assign(temp, static_cast<int32_t>(sizeof(table_id) + rowkey.length()));
// get the pair according to the key
ObCachePair pair;
ret = tablet_cache_.get(CacheKey, pair);
if (OB_SUCCESS != ret)
{
TBSYS_LOG(DEBUG, "find tablet from cache failed:table_id[%lu], length[%d]",
table_id, rowkey.length());
}
else
{
int64_t pos = 0;
// TODO double check pair.key whether as equal with CacheKey
ret = range.deserialize(pair.get_key().ptr(), pair.get_key().length(), pos);
if (OB_SUCCESS != ret)
{
TBSYS_LOG(ERROR, "deserialize tablet range failed:table_id[%lu], ret[%d]",
table_id, ret);
}
else
{
ret = set(range, location);
}
}
// destory the temp buffer
ob_free(temp);
}
}
return ret;
}
示例2: fast_search
int64_t ObStringSearch::fast_search(const ObString & pattern, const ObString & text)
{
const char* pat = pattern.ptr();
const int64_t pat_len = pattern.length();
const char* txt = text.ptr();
const int64_t txt_len = text.length();
return fast_search(pat, pat_len, txt, txt_len);
}
示例3: convert
int ObUpsRowUtil::convert(const ObUpsRow &row, ObString &compact_row)
{
int ret = OB_SUCCESS;
ObCompactCellWriter cell_writer;
cell_writer.init(compact_row.ptr(), compact_row.size());
const ObObj *cell = NULL;
uint64_t table_id = OB_INVALID_ID;
uint64_t column_id = OB_INVALID_ID;
ObObj cell_clone;
if(row.get_is_delete_row())
{
if(OB_SUCCESS != (ret = cell_writer.row_delete()))
{
TBSYS_LOG(WARN, "append delete row fail:ret[%d]", ret);
}
}
for (int64_t i = 0; (OB_SUCCESS == ret) && i < row.get_column_num(); ++i)
{
if (OB_SUCCESS != (ret = row.raw_get_cell(i, cell, table_id, column_id)))
{
TBSYS_LOG(WARN, "failed to get cell, err=%d", ret);
break;
}
else
{
if(ObExtendType == cell->get_type() && ObActionFlag::OP_NOP == cell->get_ext())
{
//不用处理,OP_NOP不序列化
}
else if (OB_SUCCESS != (ret = cell_writer.append(column_id, *cell)))
{
if (OB_SIZE_OVERFLOW != ret)
{
TBSYS_LOG(WARN, "failed to append cell, err=%d", ret);
}
break;
}
}
} // end for i
if (OB_SUCCESS == ret)
{
if (OB_SUCCESS != (ret = cell_writer.row_finish()))
{
if (OB_SIZE_OVERFLOW != ret)
{
TBSYS_LOG(WARN, "failed to append cell, err=%d", ret);
}
}
else
{
compact_row.assign_ptr(compact_row.ptr(), (int32_t)(cell_writer.size()));
}
}
return ret;
}
示例4: check_dir
int ObFileService::check_dir(const ObString& local_dir, const int64_t file_size)
{
int ret = OB_SUCCESS;
char path_buf[OB_MAX_FILE_NAME_LENGTH];
if (OB_SUCCESS == ret)
{
// check if the dir is allowed to write
struct stat dir_stat;
int n = snprintf(path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s",
local_dir.length(), local_dir.ptr());
if (n<0 || n>=OB_MAX_FILE_NAME_LENGTH)
{
ret = OB_SIZE_OVERFLOW;
TBSYS_LOG(ERROR, "local_dir length is overflow, length[%d] str[%.*s]",
local_dir.length(), local_dir.length(), local_dir.ptr());
}
else if (stat(path_buf, &dir_stat) != 0)
{
TBSYS_LOG(WARN, "get local directory[%s] stat fail: %s",
path_buf, strerror(errno));
ret = OB_IO_ERROR;
}
else if (!(S_IWUSR & dir_stat.st_mode))
{
TBSYS_LOG(WARN, "local dir[%s] cannot be written", path_buf);
ret = OB_IO_ERROR;
}
}
if (OB_SUCCESS == ret)
{
// check the free space
struct statvfs dir_statvfs;
if (statvfs(path_buf, &dir_statvfs) != 0)
{
TBSYS_LOG(WARN, "get disk free space of %s info fail: %s",
path_buf, strerror(errno));
ret = OB_IO_ERROR;
}
else
{
int64_t free_space = dir_statvfs.f_bavail * dir_statvfs.f_bsize;
if(file_size > free_space)
{
TBSYS_LOG(WARN, "free disk space of %s is not enough: file_size[%ld]"
" free_space[%ld]", path_buf, file_size, free_space);
ret = OB_CS_OUTOF_DISK_SPACE;
}
}
}
return ret;
}
示例5: memcpy
int ObStringBuf :: write_string(const ObString& str, ObString* stored_str)
{
int err = OB_SUCCESS;
if (0 == str.length() || NULL == str.ptr())
{
if (NULL != stored_str)
{
stored_str->assign(NULL, 0);
}
}
else
{
int64_t str_length = str.length();
if (NULL == block_tail_ ||
(NULL != block_tail_ &&
block_tail_->block_size - block_tail_->cur_pos <= str_length))
{
err = alloc_a_block_();
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "failed to alloc_a_block_, err=%d", err);
}
}
if (OB_SUCCESS == err)
{
if (NULL == block_tail_ ||
(NULL != block_tail_ &&
block_tail_->block_size - block_tail_->cur_pos <= str_length))
{
// buffer still not enough
err = OB_ERROR;
}
else
{
memcpy(block_tail_->data + block_tail_->cur_pos, str.ptr(), str.length());
if (NULL != stored_str)
{
stored_str->assign(block_tail_->data + block_tail_->cur_pos, str.length());
}
block_tail_->cur_pos += str_length;
total_res_ += str_length;
}
}
}
return err;
}
示例6: set_user_name
int ObUserInfoKey::set_user_name(ObString name)
{
int ret = OB_SUCCESS;
if (NULL == name.ptr())
{
TBSYS_LOG(WARN, "illegal argument name[%p]", name.ptr());
ret = OB_ERROR;
}
else
{
user_name_ = name.ptr();
length_ = name.length();
}
return ret;
}
示例7: set_passwd
int ObUserInfoValue::set_passwd(ObString pass)
{
int ret = OB_SUCCESS;
if (NULL == pass.ptr())
{
TBSYS_LOG(WARN, "illegal argument passwd[%p]", pass.ptr());
ret = OB_ERROR;
}
else
{
passwd_ = pass.ptr();
length_ = pass.length();
}
return ret;
}
示例8: set_skey
int ObSKeyInfoValue::set_skey(ObString key)
{
int ret = OB_SUCCESS;
if (NULL == key.ptr())
{
TBSYS_LOG(WARN, "illegal argument skey[%p]", key.ptr());
ret = OB_ERROR;
}
else
{
skey_ = key.ptr();
length_ = key.length();
}
return ret;
}
示例9: get_block_position_info
int ObBlockIndexCache::get_block_position_info(
const ObBlockIndexPositionInfo& block_index_info,
const uint64_t table_id,
const uint64_t column_group_id,
const ObString& key,
const SearchMode search_mode,
ObBlockPositionInfos& pos_info)
{
int ret = OB_SUCCESS;
bool revert_handle = false;
ObSSTableBlockIndexV2 block_index;
Handle handle;
if (OB_SUCCESS != (ret =
check_param(block_index_info, table_id, column_group_id)))
{
TBSYS_LOG(ERROR, "check_param error, table_id=%ld, column_group_id=%ld",
table_id, column_group_id);
}
else if ( is_regular_mode(search_mode)
&& (NULL == key.ptr() || key.length() <= 0) )
{
TBSYS_LOG(WARN, "invalid param, key_ptr=%p, key_len=%d",
key.ptr(), key.length());
ret = OB_INVALID_ARGUMENT;
}
else if ( OB_SUCCESS != (ret =
load_block_index(block_index_info, block_index, table_id, handle)) )
{
TBSYS_LOG(ERROR, "load block index error, ret=%d, table_id=%ld"
"column_group_id=%ld, mode=%d, pos=%ld",
ret, table_id, column_group_id, search_mode, pos_info.block_count_);
}
else
{
revert_handle = true;
ret = block_index.search_batch_blocks_by_key(
table_id, column_group_id, key, search_mode, pos_info);
}
if (revert_handle && OB_SUCCESS != kv_cache_.revert(handle))
{
//must revert the handle
TBSYS_LOG(WARN, "failed to revert block index cache handle");
}
return ret;
}
示例10: get_rowkey_info_from_sm
int get_rowkey_info_from_sm(const ObSchemaManagerV2* schema_mgr,
const uint64_t table_id, const ObString& table_name, ObRowkeyInfo& rowkey_info)
{
int ret = OB_SUCCESS;
const ObTableSchema* tbl = NULL;
if (NULL == schema_mgr)
{
ret = OB_INVALID_ARGUMENT;
}
else if (table_id > 0 && table_id != OB_INVALID_ID)
{
tbl = schema_mgr->get_table_schema(table_id);
}
else if (NULL != table_name.ptr())
{
tbl = schema_mgr->get_table_schema(table_name);
}
if (NULL == tbl)
{
ret = OB_INVALID_ARGUMENT;
}
else
{
rowkey_info = tbl->get_rowkey_info();
}
return ret;
}
示例11: memset
TEST_F(ObSqlExpressionTest, copy_operator_test)
{
ObString stdstring;
stdstring.assign((char*)"hello world", 11);
ObSqlExpression p;
ExprItem item_b;
item_b.type_ = T_STRING;
item_b.string_.assign((char*)"hello world", 11);
p.add_expr_item(item_b);
ObRow row;
const ObObj *result = NULL;
p.add_expr_item_end();
p.calc(row, result);
//int64_t re;
ObString mystring;
EXPECT_EQ(OB_SUCCESS, result->get_varchar(mystring));
EXPECT_EQ(mystring, stdstring);
// test deep copy
ObSqlExpression q;
q = p;
p.~ObSqlExpression();
memset(&p, 0, sizeof(p));
EXPECT_EQ(OB_SUCCESS, q.calc(row, result));
EXPECT_EQ(OB_SUCCESS, result->get_varchar(mystring));
EXPECT_EQ(mystring, stdstring);
TBSYS_LOG(INFO, "%.*s", mystring.length(), mystring.ptr());
//ASSERT_EQ();
}
示例12: set_varchar
int ObSystemConfigKey::set_varchar(const ObString &key, const char * strvalue)
{
int ret = OB_SUCCESS;
if (NULL == strvalue)
{
TBSYS_LOG(WARN, "check varchar value failed");
ret = OB_INVALID_ARGUMENT;
}
else if (key == ObString::make_string("svr_type"))
{
strncpy(server_type_, strvalue, sizeof (server_type_));
server_type_[OB_SERVER_TYPE_LENGTH - 1] = '\0';
}
else if (key == ObString::make_string("svr_ip"))
{
strncpy(server_ip_, strvalue, sizeof (server_ip_));
server_ip_[OB_MAX_SERVER_ADDR_SIZE - 1] = '\0';
}
else
{
ret = OB_INVALID_ARGUMENT;
TBSYS_LOG(ERROR, "unknow sys config column name: %.*s",
key.length(), key.ptr());
}
return ret;
}
示例13: get_cid_by_idx
uint64_t ObMetaTableColumnSchema::get_cid_by_idx(const int64_t i) const
{
uint64_t ret = OB_INVALID_ID;
if (i >= get_columns_num() || 0 > i)
{
TBSYS_LOG(ERROR, "invalid column index, i=%ld tid=%lu", i, table_schema_.table_id_);
}
else
{
ObString cname;
const int buf_len = meta_table_cname::STARTKEY_OBJ_PREFIX.length() + 8;
char cname_buf[buf_len];
cname_buf[0] = '\0';
if (i < static_cast<int64_t>(ARRAYSIZEOF(COLUMNS_NAME)))
{
cname = COLUMNS_NAME[i];
}
else
{
// start_rowkey_obj1, start_rowkey_obj2, ...
int len = snprintf(cname_buf, buf_len, "%.*s%ld", meta_table_cname::STARTKEY_OBJ_PREFIX.length(),
meta_table_cname::STARTKEY_OBJ_PREFIX.ptr(), i - ARRAYSIZEOF(COLUMNS_NAME) + 1);
cname.assign_ptr(cname_buf, len);
}
if (OB_SUCCESS != get_cid_by_name(cname, ret))
{
TBSYS_LOG(ERROR, "meta table column not found, cname=%.*s tid=%lu",
cname.length(), cname.ptr(), table_schema_.table_id_);
}
}
return ret;
}
示例14: get_mutator
int CellinfoBuilder::get_mutator(const ObString &row_key, const ObSchema &schema, int64_t &cur_seed,
ObMutator &mutator, PageArena<char> &allocer)
{
int ret = OB_SUCCESS;
int64_t sign = ob_crc64(row_key.ptr(), row_key.length());
uint64_t table_id = schema.get_table_id();
sign = ob_crc64(sign, &table_id, sizeof(uint64_t));
struct drand48_data rand_data;
cur_seed += 1;
srand48_r(sign + cur_seed, &rand_data);
int64_t rand = 0;
lrand48_r(&rand_data, &rand);
int64_t op_num = range_rand(1, max_op_num_, rand);
for (int64_t i = 0; i < op_num; i++)
{
ret = build_operator_(rand_data, row_key, schema, mutator, allocer);
if (OB_SUCCESS != ret)
{
break;
}
}
ObString table_name;
table_name.assign_ptr(const_cast<char*>(schema.get_table_name()), strlen(schema.get_table_name()));
ObString column_name;
column_name.assign_ptr(SEED_COLUMN_NAME, strlen(SEED_COLUMN_NAME));
ObObj obj;
obj.set_int(cur_seed);
mutator.update(table_name, row_key, column_name, obj);
return ret;
}
示例15: set_new_table_name
int ObAlterTableStmt::set_new_table_name(ResultPlan& result_plan, const ObString& table_name)
{
int& ret = result_plan.err_stat_.err_code_ = OB_SUCCESS;
ObSchemaChecker* schema_checker = NULL;
if (name_pool_ == NULL)
{
ret = OB_NOT_INIT;
snprintf(result_plan.err_stat_.err_msg_, MAX_ERROR_MSG,
"Name pool need to be set, ret=%d", ret);
}
else if ((schema_checker = static_cast<ObSchemaChecker*>(result_plan.schema_checker_)) == NULL)
{
ret = OB_ERR_SCHEMA_UNSET;
snprintf(result_plan.err_stat_.err_msg_, MAX_ERROR_MSG,
"Schema(s) are not set");
}
else if(schema_checker->get_table_id(table_name) != OB_INVALID_ID)
{
ret = OB_ERR_TABLE_UNKNOWN;
snprintf(result_plan.err_stat_.err_msg_, MAX_ERROR_MSG,
"Table '%.*s' already exist", table_name.length(), table_name.ptr());
}
else if ((ret = ob_write_string(*name_pool_, table_name, new_table_name_)) != OB_SUCCESS)
{
snprintf(result_plan.err_stat_.err_msg_, MAX_ERROR_MSG,
"Allocate memory for table name failed");
}
return ret;
}