本文整理汇总了C++中CoreDict类的典型用法代码示例。如果您正苦于以下问题:C++ CoreDict类的具体用法?C++ CoreDict怎么用?C++ CoreDict使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CoreDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: blessed
/*#
@function set Dictionary
@brief Stores a value in a dictionary
@param key The key to be found.
@param value The key to be set.
@return True if the value was overwritten, false if it has been inserted anew.
@note This method bypassess setIndex__ override in blessed (POOP) dictionaries.
@see oob
*/
FALCON_FUNC mth_dictSet( ::Falcon::VMachine *vm )
{
Item *i_dict, *i_key, *i_value;
if( vm->self().isMethodic() )
{
i_dict = &vm->self();
i_key = vm->param(0);
i_value = vm->param(1);
}
else {
i_dict = vm->param(0);
i_key = vm->param(1);
i_value = vm->param(2);
}
if( i_dict == 0 || ! i_dict->isDict() || i_key == 0 || i_value == 0 )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.origin( e_orig_runtime )
.extra( vm->self().isMethodic() ? "X,X" : "D,X,X" ) );
}
CoreDict *dict = i_dict->asDict();
Item *value = dict->find( *i_key );
if ( value == 0 )
{
vm->regA().setBoolean( false );
dict->put( *i_key, *i_value );
}
else {
vm->regA().setBoolean( true );
*value = *i_value;
}
}
示例2: URI_setFields
/*# @method setFields URI
@brief Sets query fields for this uri.
@param fields A dictionary of fields or nil to clear the query.
@raise ParamError if the input dictionary contains non-string values.
*/
FALCON_FUNC URI_setFields ( ::Falcon::VMachine *vm )
{
UriObject *self = dyncast<UriObject*>( vm->self().asObject() );
URI &uri = self->uri();
Item *p0 = vm->param(0);
if ( ( p0 == 0 ) || ( ! p0->isDict() ) )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).
origin( e_orig_runtime ).extra( "S" ) );
return;
}
CoreDict *dict = p0->asDict();
Iterator iter( &dict->items() );
while( iter.hasCurrent() )
{
if ( ( !iter.getCurrentKey().isString()) || (! iter.getCurrent().isString() ) )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).
origin( e_orig_runtime ).extra( "S" ) );
return;
}
uri.setField( *iter.getCurrentKey().asString(), *iter.getCurrent().asString() );
iter.next();
}
uri.makeQuery();
}
示例3: Dictionary_do
FALCON_FUNC Dictionary_do ( ::Falcon::VMachine *vm )
{
Item* i_func = vm->param(0);
if ( i_func == 0 || ! i_func->isCallable() )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.extra( "C, ..." ) );
}
// Save the parameters as the stack may change greatly.
CoreDict* dict = vm->self().asDict();
if ( dict->empty() )
{
vm->retnil();
return;
}
Iterator* iter = new Iterator(&dict->items());
vm->addLocals(1);
*vm->local(0) = new GarbagePointer(iter);
vm->returnHandler( Dictionary_do_next );
// do the first call.
vm->pushParam( iter->getCurrentKey() );
vm->pushParam( iter->getCurrent() );
vm->callFrame( *vm->param(0), 2 );
}
示例4: Dictionary_comp
FALCON_FUNC Dictionary_comp ( ::Falcon::VMachine *vm )
{
if ( vm->param(0) == 0 )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.extra( "R|A|C|Sequence, [C]" ) );
}
// Save the parameters as the stack may change greatly.
CoreDict* dict = vm->self().asDict();
Item i_gen = *vm->param(0);
Item i_check = vm->param(1) == 0 ? Item(): *vm->param(1);
// if this is a blessed dictionary, we must use the append method.
if ( dict->isBlessed() )
{
// this will throw if dict has not "append"
PoopSeq *seq = new PoopSeq( vm, dict );
vm->pushParam( new GarbagePointer( seq ) );
seq->comprehension_start( vm, dict, i_check );
}
else {
dict->items().comprehension_start( vm, dict, i_check );
}
vm->pushParam( i_gen );
}
示例5: Dictionary_mfcomp
FALCON_FUNC Dictionary_mfcomp ( ::Falcon::VMachine *vm )
{
Item* i_func = vm->param(0);
if ( i_func == 0 )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.extra( "C, ..." ) );
}
// Save the parameters as the stack may change greatly.
CoreDict* dict = vm->self().asDict();
StackFrame* current = vm->currentFrame();
Item i_check = *i_func;
// if this is a blessed dictionary, we must use the append method.
if ( dict->isBlessed() )
{
// this will throw if dict has not "append"
PoopSeq *seq = new PoopSeq( vm, dict );
vm->pushParam( new GarbagePointer( seq ) );
seq->comprehension_start( vm, dict, i_check );
}
else {
dict->items().comprehension_start( vm, dict, i_check );
}
for( uint32 i = 1; i < current->m_param_count; ++i )
{
vm->pushParam( current->m_params[i] );
}
}
示例6: mth_dictValues
FALCON_FUNC mth_dictValues( ::Falcon::VMachine *vm )
{
Item *i_dict;
if( vm->self().isMethodic() )
{
i_dict = &vm->self();
}
else {
i_dict = vm->param(0);
if( i_dict == 0 || ! i_dict->isDict() )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.origin( e_orig_runtime )
.extra( "D" ) );
}
}
CoreDict *dict = i_dict->asDict();
CoreArray *array = new CoreArray;
array->reserve( dict->length() );
Iterator iter( &dict->items() );
while( iter.hasCurrent() )
{
array->append( iter.getCurrent() );
iter.next();
}
vm->retval( array );
}
示例7: URI_getFields
/*# @method getFields URI
@brief Returns fields contained in the query element into a dictionary.
@return The fields as a dictionary of nil if the query part contains no element.
@raise ParamError if the string is not a valid URI/URL encoded string.
*/
FALCON_FUNC URI_getFields ( ::Falcon::VMachine *vm )
{
UriObject *self = dyncast<UriObject*>( vm->self().asObject() );
URI &uri = self->uri();
if ( uri.query().size() == 0 )
{
vm->retnil();
return;
}
if( uri.fieldCount() == 0 )
{
// we have a query but no fields; this means we still have to parse it.
if ( ! uri.parseQuery( true ) )
{
// todo: better signalation
throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).
origin( e_orig_runtime ).extra( vm->moduleString( rtl_invalid_uri ) ) );
return;
}
// really nothing to parse?
if ( uri.fieldCount() == 0 )
{
vm->retnil();
return;
}
}
// ok, build our dictionary
uint32 count = uri.fieldCount();
CoreDict *dict = new CoreDict( new LinearDict( count ) );
CoreString *key = new CoreString;
CoreString *value = new CoreString;
uri.firstField( *key, *value );
count--;
dict->put( key, value );
while( count > 0 )
{
key = new CoreString;
value = new CoreString;
uri.nextField( *key, *value );
count --;
dict->put( key, value );
}
vm->retval( dict );
}
示例8: value
/*#
@function dictFront
@brief Returns the first item in the dictionary.
@param dict The dictionary on which to operate.
@optparam remove If true, remove the dictionary entry too.
@optparam key If true, return the key instead of the value.
@return The first value (or key) in the dictionary.
@raise AccessError if the dictionary is empty
*/
FALCON_FUNC mth_dictFront( ::Falcon::VMachine *vm )
{
CoreDict* dict;
bool bKey;
bool bRemove;
process_dictFrontBackParams( vm, dict, bKey, bRemove );
Iterator iter( &dict->items() );
if ( bKey )
vm->retval( iter.getCurrentKey() );
else
vm->retval( iter.getCurrent() );
if ( bRemove )
iter.erase();
}
示例9: mth_dictClear
/*#
@method clear Dictionary
@brief Removes all the items from this dictionary.
*/
FALCON_FUNC mth_dictClear ( ::Falcon::VMachine *vm )
{
Item *dict;
if( vm->self().isMethodic() )
{
dict = &vm->self();
}
else {
dict = vm->param(0);
if( dict == 0 || ! dict->isDict() )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.origin( e_orig_runtime )
.extra( "D" ) );
}
}
CoreDict *d = dict->asDict();
d->clear();
}
示例10: mth_dictFill
/*#
@method fill Dictionary
@brief Fills the array with the given element.
@param item The item to be replicated.
@return This dictionary.
This method allows to clear all the values in this dictionary,
resetting all the elements to a default value.
*/
FALCON_FUNC mth_dictFill ( ::Falcon::VMachine *vm )
{
Item *i_dict;
Item *i_item;
if ( vm->self().isMethodic() )
{
i_dict = &vm->self();
i_item = vm->param(0);
}
else
{
i_dict = vm->param(0);
i_item = vm->param(1);
}
if ( i_dict == 0 || ! i_dict->isDict()
|| i_item == 0 )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.origin( e_orig_runtime )
.extra( vm->self().isMethodic() ? "X" : "D,X" ) );
}
CoreDict *dict = i_dict->asDict();
Iterator iter( &dict->items() );
while( iter.hasCurrent() )
{
if ( i_item->isString() )
iter.getCurrent() = new CoreString( *i_item->asString() );
else
iter.getCurrent() = *i_item;
iter.next();
}
vm->retval( dict );
}
示例11: Dictionary_mcomp
FALCON_FUNC Dictionary_mcomp ( ::Falcon::VMachine *vm )
{
// Save the parameters as the stack may change greatly.
CoreDict* dict = vm->self().asDict();
StackFrame* current = vm->currentFrame();
// if this is a blessed dictionary, we must use the append method.
if ( dict->isBlessed() )
{
// this will throw if dict has not "append"
PoopSeq *seq = new PoopSeq( vm, dict );
vm->pushParam( new GarbagePointer( seq ) );
seq->comprehension_start( vm, dict, Item() );
}
else {
dict->items().comprehension_start( vm, dict, Item() );
}
for( uint32 i = 0; i < current->m_param_count; ++i )
{
vm->pushParam( current->m_params[i] );
}
}
示例12: mth_dictFind
FALCON_FUNC mth_dictFind( ::Falcon::VMachine *vm )
{
Item *i_dict, *i_key;
if( vm->self().isMethodic() )
{
i_dict = &vm->self();
i_key = vm->param(0);
}
else {
i_dict = vm->param(0);
i_key = vm->param(1);
}
if( i_dict == 0 || ! i_dict->isDict() || i_key == 0 )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.origin( e_orig_runtime )
.extra( vm->self().isMethodic() ? "X" : "D,X" ) );
}
CoreDict *dict = i_dict->asDict();
Iterator iter( &dict->items() );
if ( ! dict->findIterator( *i_key, iter ) )
vm->retnil();
else
{
// find the iterator class, we'll need it
Item *i_iclass = vm->findWKI( "Iterator" );
fassert( i_iclass != 0 );
CoreObject *ival = i_iclass->asClass()->createInstance( new Iterator( iter ) );
ival->setProperty( "_origin", *i_dict );
vm->retval( ival );
}
}
示例13: mth_dictRemove
/*#
@method remove Dictionary
@brief Removes a given key from the dictionary.
@param key The key to be removed
@return True if the key is found and removed, false otherwise.
If the given key is found, it is removed from the dictionary,
and the function returns true. If it's not found, it returns false.
*/
FALCON_FUNC mth_dictRemove ( ::Falcon::VMachine *vm )
{
Item *dict, *key;
if( vm->self().isMethodic() )
{
dict = &vm->self();
key = vm->param(0);
}
else {
dict = vm->param(0);
key = vm->param(1);
}
if( dict == 0 || ! dict->isDict() || key == 0 )
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
.origin( e_orig_runtime )
.extra( vm->self().isMethodic() ? "X" : "D,X" ) );
}
CoreDict *d = dict->asDict();
vm->regA().setBoolean( d->remove( *key ) );
}
示例14: describe_internal
//.........这里部分代码省略.........
}
if ( count == (uint32) maxSize )
tgt += " ...";
tgt += "]";
}
break;
case FLC_ITEM_ARRAY:
{
CoreArray *arr = elem->asArray();
tgt += "[";
if ( level == maxLevel )
{
tgt += "...]";
break;
}
for( count = 0; count < arr->length(); count++ ) {
if ( count == 0 ) tgt += " ";
describe_internal( vm, tgt, & ((*arr)[count]), level + 1, maxLevel, maxSize );
if ( count + 1 < arr->length() )
tgt += ", ";
}
tgt +="]";
}
break;
case FLC_ITEM_DICT:
{
CoreDict *dict = elem->asDict();
if( dict->isBlessed() )
tgt += "*";
tgt += "[";
if ( level == maxLevel )
{
tgt += "...=>...]";
break;
}
if ( dict->length() == 0 )
{
tgt += "=>]";
break;
}
Item key, value;
Iterator iter( &dict->items() );
// separate the first loop to be able to add ", "
describe_internal( vm, tgt, &iter.getCurrentKey(), level + 1, maxLevel, maxSize );
tgt += " => ";
describe_internal( vm, tgt, &iter.getCurrent(), level + 1, maxLevel, maxSize );
iter.next();
while( iter.hasCurrent() )
{
tgt += ", ";
describe_internal( vm, tgt, &iter.getCurrentKey(), level + 1, maxLevel, maxSize );
tgt += " => ";
describe_internal( vm, tgt, &iter.getCurrent(), level + 1, maxLevel, maxSize );
iter.next();
示例15: inspect_internal
//.........这里部分代码省略.........
}
break;
case FLC_ITEM_ARRAY:
{
CoreArray *arr = elem->asArray();
temp = "Array[";
temp.writeNumber( (int64) arr->length() );
temp += "]";
stream->writeString( temp );
if ( level == maxLevel )
{
stream->writeString( "{...}" );
break;
}
stream->writeString( "{\n" );
for( count = 0; count < arr->length(); count++ ) {
inspect_internal( vm, & ((*arr)[count]), level + 1, maxLevel, maxSize, i_stream, true, true );
}
for ( i = 0; i < level; i ++ )
{
stream->writeString( " " );
}
stream->writeString( "}" );
}
break;
case FLC_ITEM_DICT:
{
CoreDict *dict = elem->asDict();
temp = "Dict[";
temp.writeNumber( (int64) dict->length() );
temp += "]";
stream->writeString( temp );
if ( level == maxLevel )
{
stream->writeString( "{...}" );
break;
}
stream->writeString( "{\n" );
Iterator iter( &dict->items() );
while( iter.hasCurrent() )
{
inspect_internal( vm, &iter.getCurrentKey(), level + 1, maxLevel, maxSize, i_stream, true, false );
stream->writeString( " => " );
inspect_internal( vm, &iter.getCurrent(), level + 1, maxLevel, maxSize, i_stream, false, true );
iter.next();
}
for ( i = 0; i < level; i ++ )
{
stream->writeString(" ");
}
stream->writeString( "}" );
}
break;
case FLC_ITEM_OBJECT:
{
CoreObject *arr = elem->asObjectSafe();