本文整理汇总了C++中TArray::initialize方法的典型用法代码示例。如果您正苦于以下问题:C++ TArray::initialize方法的具体用法?C++ TArray::initialize怎么用?C++ TArray::initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TArray
的用法示例。
在下文中一共展示了TArray::initialize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JumpControlTbl
JumpControlTbl(const hyu8** pCode)
: tbl(0)
{
const hyu8* code = *pCode;
hyu16 endOffs = Endian::unpack<hyu16>(code);
const hyu8* endAddr = code + endOffs;
code += 2;
hyu8 numTbl = *code;
code += 2;
hyu16* tblOffs = (hyu16*) code;
code += sizeof(hyu16) * numTbl;
alignPtr<4>(&code);
tbl.initialize(numTbl);
for (hyu8 i = 0; i < numTbl; ++i) {
HMD_ASSERTMSG(tblOffs[i] == code - *pCode, "offs=%x, code=%x, start=%x",tblOffs[i],code,*pCode);
hyu8 numLabel = *code;
code += 4;
BMap<hys32, SymbolID_t>* addrLabel = new BMap<hys32, SymbolID_t>(numLabel);
SymbolID_t* labels = (SymbolID_t*) code;
hys32* addrs = (hys32*)(code + sizeof(SymbolID_t) * numLabel);
alignPtr<4>(&addrs);
for (hyu8 j = 0; j < numLabel; ++j) {
addrLabel->forceAdd(addrs[j], labels[j]);
}
tbl.add(addrLabel);
code = (const hyu8*) (addrs + numLabel);
}
HMD_ASSERT(code == endAddr);
*pCode = code;
}
示例2: test_insert_remove
void test_insert_remove(void)
{
TArray<int> arr;
arr.initialize(2);
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
HMD_ASSERT_HALT(arr.insert(1));
arr.insert(0) = 10;
CPPUNIT_ASSERT_EQUAL((hyu32)1, arr.size());
CPPUNIT_ASSERT_EQUAL(10, arr[0]);
arr.insert(0) = 20;
CPPUNIT_ASSERT_EQUAL((hyu32)2, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(10, arr[1]);
arr.insert(1) = 30;
CPPUNIT_ASSERT_EQUAL((hyu32)3, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(30, arr[1]);
CPPUNIT_ASSERT_EQUAL(10, arr[2]);
arr.insert(3) = 40;
CPPUNIT_ASSERT_EQUAL((hyu32)4, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(30, arr[1]);
CPPUNIT_ASSERT_EQUAL(10, arr[2]);
CPPUNIT_ASSERT_EQUAL(40, arr[3]);
arr.insert(-1) = 50;
CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(30, arr[1]);
CPPUNIT_ASSERT_EQUAL(10, arr[2]);
CPPUNIT_ASSERT_EQUAL(50, arr[3]);
CPPUNIT_ASSERT_EQUAL(40, arr[4]);
arr.remove(2);
CPPUNIT_ASSERT_EQUAL((hyu32)4, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(30, arr[1]);
CPPUNIT_ASSERT_EQUAL(50, arr[2]);
CPPUNIT_ASSERT_EQUAL(40, arr[3]);
arr.remove(-3);
CPPUNIT_ASSERT_EQUAL((hyu32)3, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(50, arr[1]);
CPPUNIT_ASSERT_EQUAL(40, arr[2]);
HMD_ASSERT_HALT(arr.remove(3));
HMD_ASSERT_HALT(arr.remove(-4));
int* p = arr.nthAddr(3);
int* q = arr.addSpaces(2);
CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
CPPUNIT_ASSERT_EQUAL(p, q);
}
示例3: test_replace
void test_replace(void)
{
TArray<int> arr;
arr.initialize(10);
for (int i = 0; i < 10; ++i)
arr.add(i * 10);
CPPUNIT_ASSERT_EQUAL(30, arr.replace(3, -10));
CPPUNIT_ASSERT_EQUAL(50, arr.replace(5, -10));
CPPUNIT_ASSERT_EQUAL(80, arr.replace(8, 800));
CPPUNIT_ASSERT_EQUAL(-10, arr.replace(5, 10));
CPPUNIT_ASSERT_EQUAL(-10, arr.replace(3, 10));
CPPUNIT_ASSERT_EQUAL(800, arr.replace(8, 10));
CPPUNIT_ASSERT_EQUAL((hyu32)10, arr.size());
arr.deleteVal(10);
CPPUNIT_ASSERT_EQUAL((hyu32)6, arr.size());
}
示例4: test_deleteVal
void test_deleteVal(void)
{
TArray<int> arr;
arr.initialize(10);
for (int i = 0; i < 10; ++i)
arr.add(i * 10);
arr[3] = 80;
arr[6] = 80;
CPPUNIT_ASSERT_EQUAL((hyu32)10, arr.size());
arr.deleteVal(20);
CPPUNIT_ASSERT_EQUAL((hyu32)9, arr.size());
arr.deleteVal(80);
CPPUNIT_ASSERT_EQUAL((hyu32)6, arr.size());
CPPUNIT_ASSERT_EQUAL(0, arr[0]);
CPPUNIT_ASSERT_EQUAL(10, arr[1]);
CPPUNIT_ASSERT_EQUAL(40, arr[2]);
CPPUNIT_ASSERT_EQUAL(50, arr[3]);
CPPUNIT_ASSERT_EQUAL(70, arr[4]);
CPPUNIT_ASSERT_EQUAL(90, arr[5]);
}
示例5: test_array
void test_array(void)
{
int dat[10] = { 100, 110, 120, -130, 140, -15000, 16000, 1700, 18, 19000 };
TArray<int> arr;
arr.initialize(0);
CPPUNIT_ASSERT_EQUAL((int*)NULL, arr.m_contents);
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.m_capacity);
arr.initialize(2);
CPPUNIT_ASSERT(arr.m_contents != NULL);
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
CPPUNIT_ASSERT_EQUAL((hyu32)2, arr.m_capacity);
arr.add(dat, 5);
CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
CPPUNIT_ASSERT_EQUAL(100, arr[0]);
CPPUNIT_ASSERT_EQUAL(140, arr[4]);
arr.fill(7);
CPPUNIT_ASSERT_EQUAL(7, arr[0]);
CPPUNIT_ASSERT_EQUAL(7, arr[4]);
CPPUNIT_ASSERT(arr.checkIndex(100));
CPPUNIT_ASSERT(arr.checkIndex(-5));
CPPUNIT_ASSERT(! arr.checkIndex(-6));
arr[2] = 222;
CPPUNIT_ASSERT_EQUAL(222, *(arr.nthAddr(2)));
arr.subst(20, 202020, -1);
CPPUNIT_ASSERT_EQUAL((hyu32)21, arr.size());
CPPUNIT_ASSERT_EQUAL(-1, arr[5]);
CPPUNIT_ASSERT_EQUAL(-1, arr[19]);
CPPUNIT_ASSERT_EQUAL(202020, arr[20]);
arr.add(&dat[5], 5);
arr.add(123);
arr.add(456);
CPPUNIT_ASSERT_EQUAL((hyu32)28, arr.size());
CPPUNIT_ASSERT_EQUAL(-15000, arr[21]);
CPPUNIT_ASSERT_EQUAL(19000, arr[25]);
CPPUNIT_ASSERT_EQUAL(123, arr[26]);
CPPUNIT_ASSERT_EQUAL(456, arr[27]);
int x = 222;
CPPUNIT_ASSERT_EQUAL(2, arr.issue(x));
x = 202020;
CPPUNIT_ASSERT_EQUAL(20, arr.issue(x));
x = 123;
CPPUNIT_ASSERT_EQUAL(26, arr.issue(x));
CPPUNIT_ASSERT_EQUAL((hyu32)28, arr.size());
x = 98765;
CPPUNIT_ASSERT_EQUAL(28, arr.issue(x));
CPPUNIT_ASSERT_EQUAL(98765, arr[28]);
arr.clear();
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
hyu32 capa = arr.m_capacity;
arr.reserve(capa);
CPPUNIT_ASSERT(capa != arr.m_capacity);
}