当前位置: 首页>>代码示例>>C++>>正文


C++ AtomArray::splice方法代码示例

本文整理汇总了C++中AtomArray::splice方法的典型用法代码示例。如果您正苦于以下问题:C++ AtomArray::splice方法的具体用法?C++ AtomArray::splice怎么用?C++ AtomArray::splice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AtomArray的用法示例。


在下文中一共展示了AtomArray::splice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ClassClosure

	ArrayClass::ArrayClass(VTable* cvtable)
	: ClassClosure(cvtable), 
	  kComma(core()->internConstantStringLatin1(","))
	{
		AvmCore* core = this->core();
		Toplevel* toplevel = this->toplevel();

		toplevel->arrayClass = this;
		AvmAssert(traits()->getSizeOfInstance() == sizeof(ArrayClass));

		VTable* ivtable = this->ivtable();
		ScriptObject* objectPrototype = toplevel->objectClass->prototype;
		prototype = new (core->GetGC(), ivtable->getExtraSize()) ArrayObject(ivtable, objectPrototype, 0);

		// According to ECMAscript spec (ECMA-262.pdf)
		// generic support: concat, join, pop, push, reverse, shift, slice, sort, splice, unshift
		// NOT generic: toString, toLocaleString
		// unknown: sortOn (our own extension)

#if defined(_DEBUG)

		// AtomArray DRC unit tests, put here b/c this always runs once, has a GC * and
		// this class has to do with arrays.  this is more convienent that trying to test
		// through actionscript

		// create an atom
		Stringp s = core->newConstantStringLatin1("foo");
		Atom a = s->atom();
		AvmAssert(s->RefCount()==0);
		AtomArray *ar = new (gc()) AtomArray();
		
		// test push/pop
		ar->push(a); AvmAssert(s->RefCount()==1);
		ar->push(a); AvmAssert(s->RefCount()==2);
		ar->pop(); AvmAssert(s->RefCount()==1);

		// reverse
		ar->push(a); AvmAssert(s->RefCount()==2);
		ar->reverse(); AvmAssert(s->RefCount()==2);
		
		// shift
		ar->shift(); AvmAssert(s->RefCount()==1);

		// splice
		AtomArray *ar2 = new (gc()) AtomArray();
		ar->push(a);
		ar2->push(ar); AvmAssert(s->RefCount()==4);
		ar->splice(1, 2, 1, ar2, 0);  // [a,a,a]
		AvmAssert(s->RefCount()==5);

		// unshift
		Atom as[4] = {a,a,a,a};
		ar->unshift(as, 4);
		AvmAssert(s->RefCount()==9);

		// removeAt
		ar->removeAt(1); AvmAssert(s->RefCount()==8);

		// setAt
		ar->setAt(2, a); AvmAssert(s->RefCount()==8);

		// insert
		ar->insert(2, a); AvmAssert(s->RefCount()==9);

		// clear
		ar->clear(); AvmAssert(s->RefCount() == 2);
		ar2->clear(); AvmAssert(s->RefCount() == 0);

		gc()->Free(ar);
		gc()->Free(ar2);
#endif
	}
开发者ID:weimingtom,项目名称:mod-actionscript,代码行数:72,代码来源:ArrayClass.cpp


注:本文中的AtomArray::splice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。