📄 test_yc_chkarray.c
字号:
#ifdef _MSC_VER
#pragma warning(disable:4127)
#pragma warning(disable:4244)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../young/youngc.h"
#ifdef __cplusplus
using namespace youngc;
#endif
extern void GetStrings( dyrscarray* pstrarr, ncstring* pdstr );
extern void DestroyString( void* pdstr );
void print_chkarray( chkarray* self )
{
chkarr_iterator begin = chkarr_begin(self);
chkarr_iterator end = chkarr_end(self);
size_t i = 0;
while( begin.current != end.current )
{
printf( "string chkarray[%u]: %s\n", i++,
ncstr_to_string( (ncstring*)begin.current ) );
chkarr_itr_inc( &begin );
}
printf( "\n\n" );
}
void InputStrings( chkarray* pdeq, ncstring* pdstr, bool at_front )
{
bool result = true;
result = result;
while( 1 )
{
printf( "\nplease input strings, input '0' to exit!\n" );
ncstr_getline( pdstr, '\n' );
if( ncstr_size(pdstr) == 0 )
continue;
if( strcmp("0", ncstr_to_string(pdstr)) == 0 )
break;
/* at_front ? chkarr_push_front(pdeq, pdstr) : chkarr_push_back(pdeq, pdstr); */
if( at_front )
{
CHKARRAY_PUSH_FRONT_FUN( *pdeq, *pdstr, ncstring, result );
}
else
{
CHKARRAY_PUSH_BACK_FUN( *pdeq, *pdstr, ncstring, result );
}
}
printf( "\n\n" );
}
void test_chkarray( void )
{
char get[8] = {0};
ncstring dstr;
chkarray deq;
ncstr_init( &dstr );
printf( "please set move function(y/n)\n" );
scanf( "%s", get );
if( get[0] == 'y' )
chkarr_init( &deq, sizeof(ncstring), 0,(ylib_fp_oper_t)ncstr_init,
(ylib_fp_copy_t)ncstr_init_copy, (ylib_fp_copy_t)ncstr_assign_copy,
(ylib_fp_move_t)ncstr_init_move, (ylib_fp_move_t)ncstr_assign_move,
DestroyString, pool_alloc, pool_free );
else
chkarr_init( &deq, sizeof(ncstring), 0,(ylib_fp_oper_t)ncstr_init,
(ylib_fp_copy_t)ncstr_init_copy, (ylib_fp_copy_t)ncstr_assign_copy,
NULL, NULL,
DestroyString, pool_alloc, pool_free );
while( 1 )
{
int choice = 0;
printf( "\n\n" );
printf( " 1: test chkarr_init_copy\n" );
printf( " 2: test chkarr_assign_copy\n" );
printf( " 3: test chkarr_init_move\n" );
printf( " 4: test chkarr_assign_move\n" );
printf( " 5: test chkarr_erase_pos\n" );
printf( " 6: test chkarr_erase_range\n" );
printf( " 7: test chkarr_insert_value\n" );
printf( " 8: test chkarr_insert_array\n" );
printf( " 9: test chkarr_pop_back\n" );
printf( " 10: test chkarr_pop_front\n" );
printf( " 11: test chkarr_push_back\n" );
printf( " 12: test chkarr_push_front\n" );
printf( " 13: test chkarr_resize\n" );
printf( " 14: test chkarr_replace_fill\n" );
printf( " 15: test chkarr_replace_array\n" );
printf( " 16: test chkarr_empty\n" );
printf( " 17: test chkarr_size\n" );
printf( " 18: test chkarr_max_size\n" );
printf( " 19: test chkarr_begin\n" );
printf( " 20: test chkarr_end\n" );
printf( " 21: test chkarr_front\n" );
printf( " 22: test chkarr_back\n" );
printf( " 23: test chkarr_index\n" );
printf( " 24: test chkarr_at\n" );
printf( " 25: test chkarr_reverse\n" );
printf( " 26: test chkarr_chunk_elements\n" );
printf( " 27: print chkarray\n" );
printf( " 28: print sequence\n" );
printf( " 0: exit\n\n\n" );
scanf( "%d", &choice );
switch( choice )
{
case 0:
goto EXIT;
case 1:
{
chkarray deq1;
chkarr_init_copy( &deq1, &deq );
printf( "src:\n" );
print_chkarray( &deq );
printf( "dst:\n" );
print_chkarray( &deq1 );
chkarr_destroy( &deq );
chkarr_init_copy( &deq, &deq1 );
chkarr_destroy( &deq1 );
break;
}
case 2:
{
chkarray deq1;
chkarr_init( &deq1, sizeof(ncstring), 0, (ylib_fp_oper_t)ncstr_init,
(ylib_fp_copy_t)ncstr_init_copy, (ylib_fp_copy_t)ncstr_assign_copy,
(ylib_fp_move_t)ncstr_init_move, (ylib_fp_move_t)ncstr_assign_move,
DestroyString, pool_alloc, pool_free );
printf( "please input first string array:\n" );
InputStrings( &deq1, &dstr, false );
printf( "before dst:\n" );
print_chkarray( &deq1 );
chkarr_assign_copy( &deq1, &deq );
printf( "src:\n" );
print_chkarray( &deq );
printf( "after dst:\n" );
print_chkarray( &deq1 );
chkarr_destroy( &deq );
chkarr_assign_copy( &deq, &deq1 );
chkarr_destroy( &deq1 );
break;
}
case 3:
{
chkarray deq1;
chkarr_init_move( &deq1, &deq );
printf( "src:\n" );
print_chkarray( &deq );
printf( "dst:\n" );
print_chkarray( &deq1 );
chkarr_destroy( &deq1 );
break;
}
case 4:
{
chkarray deq1;
chkarr_init( &deq1, sizeof(ncstring), 0, (ylib_fp_oper_t)ncstr_init,
(ylib_fp_copy_t)ncstr_init_copy, (ylib_fp_copy_t)ncstr_assign_copy,
(ylib_fp_move_t)ncstr_init_move, (ylib_fp_move_t)ncstr_assign_move,
DestroyString, pool_alloc, pool_free );
printf( "please input first string array:\n" );
InputStrings( &deq1, &dstr, false );
printf( "before src:\n" );
print_chkarray( &deq );
printf( "before dst:\n" );
print_chkarray( &deq1 );
chkarr_assign_move( &deq1, &deq );
printf( "after src:\n" );
print_chkarray( &deq );
printf( "after dst:\n" );
print_chkarray( &deq1 );
chkarr_destroy( &deq1 );
break;
}
case 5:
{
size_t pos = 0;
printf( "please input index:\n" );
scanf( "%u", &pos );
chkarr_erase_pos( &deq, pos );
break;
}
case 6:
{
size_t first = 0, last = 0;
printf( "please input first index:\n" );
scanf( "%u", &first );
printf( "please input last index:\n" );
scanf( "%u", &last );
chkarr_erase_range( &deq, first, last );
break;
}
case 7:
{
size_t index = 0, count = 0;
printf( "please input insert index:\n" );
scanf( "%u", &index );
printf( "please input insert count:\n" );
scanf( "%u", &count );
printf( "please input insert string:\n" );
getchar();
ncstr_getline( &dstr, '\n' );
if( false == chkarr_insert_value(&deq, index, &dstr, count) )
printf( "return false!\n" );
else
print_chkarray( &deq );
break;
}
case 8:
{
size_t index = 0, count = 0;
dyrscarray strarr1;
dyrscarr_init( &strarr1, sizeof(ncstring), (ylib_fp_oper_t)ncstr_init,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -