src/stdlib/table.c
/*=================================================
 * copy_table -- Copy all elements from src to dest
 *===============================================*/
- Copy all elements from src to dest
- Copy all elements from src to dest
void
copy_table (const TABLE src, TABLE dest)
{
	if (!src || !dest) return;
	ASSERT(src->vtable == &vtable_for_table);
	ASSERT(dest->vtable == &vtable_for_table);
	if (src->valtype == TB_INT) {
		TABLE_ITER tabit = begin_table_iter(src);
		CNSTRING key=0;
		INT ival=0;
		ASSERT(dest->valtype == TB_INT);
		while (next_table_int(tabit, &key, &ival)) {
			insert_table_int(dest, key, ival);
		}
		end_table_iter(&tabit);
		return;
	}
	if (src->valtype == TB_STR) {
		TABLE_ITER tabit = begin_table_iter(src);
		CNSTRING key=0;
		VPTR val=0;
		ASSERT(dest->valtype == src->valtype);
		while (next_table_ptr(tabit, &key, &val)) {
			insert_table_str(dest, key, val);
		}
		end_table_iter(&tabit);
		return;
	}
	if (src->valtype == TB_HPTR) {
		ASSERT(0);
	}
	if (src->valtype == TB_VPTR) {
		TABLE_ITER tabit = begin_table_iter(src);
		CNSTRING key=0;
		VPTR val=0;
		ASSERT(dest->valtype == src->valtype);
		while (next_table_ptr(tabit, &key, &val)) {
			insert_table_ptr(dest, key, val);
		}
		end_table_iter(&tabit);
		return;
	}
	if (src->valtype == TB_OBJ) {
		TABLE_ITER tabit = begin_table_iter(src);
		CNSTRING key=0;
		VPTR val=0;
		ASSERT(dest->valtype == src->valtype);
		while (next_table_ptr(tabit, &key, &val)) {
			addref_object(val);
			insert_table_obj(dest, key, val);
		}
		end_table_iter(&tabit);
		return;
	}
	ASSERT(0);
}
void copy_table ( const TABLE src , TABLE dest ) { if ( ! src || ! dest ) return ; ASSERT ( src -> vtable == & vtable_for_table ) ; ASSERT ( dest -> vtable == & vtable_for_table ) ; if ( src -> valtype == TB_INT ) { TABLE_ITER tabit = begin_table_iter ( src ) ; CNSTRING key = 0 ; INT ival = 0 ; ASSERT ( dest -> valtype == TB_INT ) ; while ( next_table_int ( tabit , & key , & ival ) ) { insert_table_int ( dest , key , ival ) ; } end_table_iter ( & tabit ) ; return ; } if ( src -> valtype == TB_STR ) { TABLE_ITER tabit = begin_table_iter ( src ) ; CNSTRING key = 0 ; VPTR val = 0 ; ASSERT ( dest -> valtype == src -> valtype ) ; while ( next_table_ptr ( tabit , & key , & val ) ) { insert_table_str ( dest , key , val ) ; } end_table_iter ( & tabit ) ; return ; } if ( src -> valtype == TB_HPTR ) { ASSERT ( 0 ) ; } if ( src -> valtype == TB_VPTR ) { TABLE_ITER tabit = begin_table_iter ( src ) ; CNSTRING key = 0 ; VPTR val = 0 ; ASSERT ( dest -> valtype == src -> valtype ) ; while ( next_table_ptr ( tabit , & key , & val ) ) { insert_table_ptr ( dest , key , val ) ; } end_table_iter ( & tabit ) ; return ; } if ( src -> valtype == TB_OBJ ) { TABLE_ITER tabit = begin_table_iter ( src ) ; CNSTRING key = 0 ; VPTR val = 0 ; ASSERT ( dest -> valtype == src -> valtype ) ; while ( next_table_ptr ( tabit , & key , & val ) ) { addref_object ( val ) ; insert_table_obj ( dest , key , val ) ; } end_table_iter ( & tabit ) ; return ; } ASSERT ( 0 ) ; }
copy_table -- Copy all elements from src to dest
copy_table -- Copy all elements from src to dest