本文整理汇总了C++中Toplevel::arrayClass方法的典型用法代码示例。如果您正苦于以下问题:C++ Toplevel::arrayClass方法的具体用法?C++ Toplevel::arrayClass怎么用?C++ Toplevel::arrayClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Toplevel
的用法示例。
在下文中一共展示了Toplevel::arrayClass方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memcpy
/*static*/ ChostentObject* CNetdbClass::gethostbyname(ScriptObject* self, Stringp name)
{
AvmCore *core = self->core();
Toplevel* toplevel = self->toplevel();
if( !name )
{
toplevel->throwArgumentError(kNullArgumentError, "name");
}
struct hostent *he;
StUTF8String nameUTF8(name);
he = VMPI_gethostbyname( nameUTF8.c_str() );
if( he )
{
ShellToplevel* shelltop = (ShellToplevel*)self->toplevel();
ChostentClass *hc = shelltop->getShellClasses()->get_hostentClass();
ChostentObject *ho = hc->constructObject();
ho->set_h_name( core->newStringUTF8( he->h_name ) );
ArrayObject *aliases = toplevel->arrayClass()->newArray();
int count = 0;
int i;
for( i=0; he->h_aliases[i] != NULL; ++i )
{
aliases->setUintProperty( count++, core->newStringUTF8( he->h_aliases[i] )->atom() );
}
ho->set_h_aliases( aliases );
ho->set_h_addrtype( he->h_addrtype );
ho->set_h_length( he->h_length );
ArrayObject *addrlist = toplevel->arrayClass()->newArray();
count = 0;
for( i=0; he->h_addr_list[i] != NULL; ++i )
{
struct in_addr in;
memcpy(&in.s_addr, he->h_addr_list[i], sizeof (in.s_addr));
CIn_AddrClass *ac = shelltop->getShellClasses()->get_in_addrClass();
CIn_AddrObject *ao = ac->constructObject();
ao->set_s_addr( in.s_addr );
addrlist->setUintProperty( count++, ao->toAtom() );
//addrlist->setUintProperty( count++, core->newStringUTF8( inet_ntoa(in) )->atom() );
}
ho->set_h_addr_list( addrlist );
return ho;
}
return NULL;
}
示例2: while
ArrayObject * ProgramClass::_getEnviron()
{
Toplevel *toplevel = this->toplevel();
AvmCore *core = this->core();
ArrayObject *array = toplevel->arrayClass()->newArray();
#if AVMSYSTEM_WIN32
wchar **cur = VMPI_GetEnviron16();
int i = 0;
while( cur[i] )
{
Stringp value = core->newStringUTF16(cur[i]);
StUTF8String valueUTF8(value);
array->setUintProperty( i, core->newStringUTF8( valueUTF8.c_str() )->atom() );
i++;
}
#else
char **cur = VMPI_GetEnviron();
int i = 0;
while( cur[i] )
{
array->setUintProperty( i, core->newStringUTF8( cur[i] )->atom() );
i++;
}
#endif
return array;
}
示例3: set_stack
bool SamplerScript::set_stack(ScriptObject* self, ClassFactoryClass* cf, const Sample& sample, SampleObject* sam)
{
if (sample.stack.depth > 0)
{
Toplevel* toplevel = self->toplevel();
AvmCore* core = toplevel->core();
Sampler* s = core->get_sampler();
StackFrameClass* sfcc = (StackFrameClass*)cf->get_StackFrameClass();
ArrayObject* stack = toplevel->arrayClass()->newArray(sample.stack.depth);
StackTrace::Element* e = (StackTrace::Element*)sample.stack.trace;
for(uint32_t i=0; i < sample.stack.depth; i++, e++)
{
StackFrameObject* sf = sfcc->constructObject();
// at every allocation the sample buffer could overflow and the samples could be deleted
// the StackTrace::Element pointer is a raw pointer into that buffer so we need to check
// that its still around before dereferencing e
uint32_t num;
if (s->getSamples(num) == NULL)
return false;
sf->setconst_name(e->name()); // NOT e->info()->name() because e->name() can be a fake name
sf->setconst_file(e->filename());
sf->setconst_line(e->linenum());
sf->setconst_scriptID(static_cast<double>(e->functionId()));
stack->setUintProperty(i, sf->atom());
}
sam->setconst_stack(stack);
}
return true;
}
示例4:
/*static*/ CprotoentObject* CNetdbClass::getprotoent(ScriptObject* self)
{
struct protoent *pp;
pp = VMPI_getprotoent();
if( pp )
{
ShellToplevel* shelltop = (ShellToplevel*)self->toplevel();
CprotoentClass *pc = shelltop->getShellClasses()->get_protoentClass();
CprotoentObject *po = pc->constructObject();
po->set_p_name( self->core()->newStringUTF8( pp->p_name ) );
po->set_p_proto( pp->p_proto );
Toplevel* toplevel = self->toplevel();
ArrayObject *aliases = toplevel->arrayClass()->newArray();
int count = 0;
int i;
for( i=0; pp->p_aliases[i] != NULL; ++i )
{
aliases->setUintProperty( count++, self->core()->newStringUTF8( pp->p_aliases[i] )->atom());
}
po->set_p_aliases( aliases );
return po;
}
return NULL;
}
示例5:
ArrayObject * ProgramClass::_getArgv()
{
Toplevel *toplevel = this->toplevel();
AvmCore *core = this->core();
ArrayObject *array = toplevel->arrayClass()->newArray();
for( int i=0; i<user_argc; i++ )
{
array->setUintProperty(i, core->newStringUTF8(user_argv[i])->atom());
}
return array;
}
示例6: if
/*static*/ ArrayObject* CNetdbClass::getaddrinfo(ScriptObject* self, Stringp nodename, Stringp servname, CaddrinfoObject* hints, CEAIrrorObject* eaierr)
{
AvmCore *core = self->core();
Toplevel* toplevel = self->toplevel();
ShellToplevel* shelltop = (ShellToplevel*)self->toplevel();
if( !hints )
{
CaddrinfoClass *ai_c = shelltop->getShellClasses()->get_addrinfoClass();
CaddrinfoObject *hints = ai_c->constructObject();
//default properties
hints->set_ai_family( AF_UNSPEC );
hints->set_ai_socktype( SOCK_STREAM );
}
StUTF8String nodenameUTF8(nodename);
StUTF8String servnameUTF8(servname);
//(void)hints;
struct addrinfo h;
VMPI_memset(&h, 0, sizeof h);
h.ai_flags = hints->get_ai_flags();
h.ai_family = hints->get_ai_family();
h.ai_socktype = hints->get_ai_socktype();
h.ai_protocol = hints->get_ai_protocol();
//ignore other propertiess
struct addrinfo *res, *p;
int result = VMPI_getaddrinfo( nodenameUTF8.c_str(), servnameUTF8.c_str(), &h, &res );
if( result != 0 )
{
//printf( "getaddrinfo: %s\n", gai_strerror(result));
if( eaierr )
{
eaierr->call_apply( result );
}
return NULL;
}
ArrayObject *infolist = toplevel->arrayClass()->newArray();
int count = 0;
for( p = res; p != NULL; p = p->ai_next )
{
CaddrinfoClass *infoc = shelltop->getShellClasses()->get_addrinfoClass();
CaddrinfoObject *info = infoc->constructObject();
info->set_ai_flags( p->ai_flags );
info->set_ai_family( p->ai_family );
info->set_ai_socktype( p->ai_socktype );
info->set_ai_protocol( p->ai_protocol );
info->set_ai_addrlen( (int) p->ai_addrlen );
info->set_ai_canonname( core->newStringUTF8( p->ai_canonname ) );
if( p->ai_family == AF_INET )
{
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
CSockaddr_inClass *addr4c = shelltop->getShellClasses()->get_sockaddr_inClass();
CSockaddr_inObject *addr4o = addr4c->constructObject();
addr4o->set_sin_family( ipv4->sin_family );
addr4o->set_sin_port( ipv4->sin_port );
CIn_AddrClass *ac = shelltop->getShellClasses()->get_in_addrClass();
CIn_AddrObject *ao = ac->constructObject();
ao->set_s_addr( ipv4->sin_addr.s_addr );
addr4o->set_sin_addr( ao );
info->set_ai_addr( addr4o->toAtom() );
}
else if( p->ai_family == AF_INET6 )
{
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
CSockaddr_in6Class *addr6c = shelltop->getShellClasses()->get_sockaddr_in6Class();
CSockaddr_in6Object *addr6o = addr6c->constructObject();
addr6o->set_sin6_family( ipv6->sin6_family );
addr6o->set_sin6_port( ipv6->sin6_port );
addr6o->set_sin6_flowinfo( ipv6->sin6_flowinfo );
addr6o->set_sin6_scope_id( ipv6->sin6_scope_id );
CIn6_AddrClass *ac6 = shelltop->getShellClasses()->get_in6_addrClass();
CIn6_AddrObject *ao6 = ac6->constructObject();
ao6->fromStruct( ipv6->sin6_addr );
addr6o->set_sin6_addr( ao6 );
info->set_ai_addr( addr6o->toAtom() );
}
infolist->setUintProperty( count++, info->toAtom() );
}
VMPI_freeaddrinfo( res );
//.........这里部分代码省略.........