void test_example_wikipedia_bcon(size_t iterations) { bcon_error_t ret; size_t i; bson b[1]; bcon wikipedia[] = { "firstName", "John", "lastName" , "Smith", "age" , BI(25), "address" , "{", "streetAddress", "21 2nd Street", "city" , "New York", "state" , "NY", "postalCode" , "10021", "}", "phoneNumber", "[", "{", "type" , "home", "number", "212 555-1234", "}", "{", "type" , "fax", "number", "646 555-4567", "}", "]", BEND }; for (i = 0; i < iterations; i++) { ret = bson_from_bcon( b, wikipedia ); bson_destroy( b ); } assert(ret == BCON_OK); }
vector compgene(cmatrix& A,cmatrix& B) { int i; int N=A.Rows; int IFAIL=0; int MATV=0; int* ITER=new int[N]; vector ALFR(N); vector ALFI(N); vector BETA(N); double EPS1=0.; matrix AR(N,N); matrix AI(N,N); matrix BR(N,N); matrix BI(N,N); for (i=0;i<N;i++) for (int j=0;j<N;j++) { AR(i,j)=real(A(i,j)); AI(i,j)=imag(A(i,j)); BR(i,j)=real(B(i,j)); BI(i,j)=imag(B(i,j)); } matrix VR(N,N); matrix VI(N,N); /* f02gjf_(&N,AR.TheMatrix,&N,AI.TheMatrix,&N,BR.TheMatrix,&N, BI.TheMatrix,&N,&EPS1,ALFR.TheVector,ALFI.TheVector, BETA.TheVector,&MATV,VR.TheMatrix,&N, VI.TheMatrix,&N,ITER,&IFAIL); */ cerr<<"compgene to be implemented"<<endl; exit(1); if (IFAIL != 0) cerr <<"error in compgene "<<endl; if (!ALFR.TheVector) exit(1); for (i=0;i<N;i++) ALFR(i)=ALFR(i)/BETA(i); // sort ! char ORDER='A'; int M1=1; int M2=N; /* m01caf_(ALFR.TheVector,&M1,&M2,&ORDER,&IFAIL);*/ cerr<<"sort to be implemented"<<endl; exit(1); if (IFAIL != 0) cerr <<"error in m01caf_ "<<endl; return ALFR; }
static VOID bitmap_to_buf(APTR src_info , LONG x_src, LONG y_src , LONG x_dest, LONG y_dest , LONG width, LONG height , ULONG *bufptr , Object *dest_bm , HIDDT_Pixel *coltab ) /* destination HIDD bitmap */ { LONG y; /* Fill buffer with pixels from bitmap */ for (y = 0; y < height; y ++) { LONG x; for (x = 0; x < width; x ++) { UBYTE pen; pen = getbitmappixel(BI(src_info)->bitmap , x + x_src , y + y_src , BI(src_info)->bmdepth , BI(src_info)->planemask); *bufptr ++ = (coltab != NULL) ? coltab[pen] : pen; // kprintf("(%d, %d) pen=%d buf=%d\n", x, y, pen, coltab[pen]); } } }
void test_valid_structure() { bcon bc_key_value[] = { "k0", "v0", BEND }; test_bson_from_bcon( bc_key_value, BCON_OK, BSON_VALID ); bcon bc_key_spec_value[] = { "k0", ":_s:", "v0", BEND }; test_bson_from_bcon( bc_key_spec_value, BCON_OK, BSON_VALID ); bcon bc_key_value_2[] = { "k0", "v0", "k1", "v1", BEND }; test_bson_from_bcon( bc_key_value_2, BCON_OK, BSON_VALID ); bcon bc_embedded[] = { "k0", "v0", "k1", "{", "k10", "v10", "k11", "v11", "}", "k2", "v2", BEND }; test_bson_from_bcon( bc_embedded, BCON_OK, BSON_VALID ); bcon bc_embedded_2[] = { "k0", "v0", "k1", "{", "k10", "v10", "k11", "{", "k110", "v110", "}", "k12", "v12", "}", "k2", "v2", BEND }; test_bson_from_bcon( bc_embedded_2, BCON_OK, BSON_VALID ); bcon bc_array[] = { "k0", "v0", "k1", "[", "v10", "v11", "v12", "]", "k2", "v2", BEND }; test_bson_from_bcon( bc_array, BCON_OK, BSON_VALID ); bcon bc_array_with_type[] = { "k0", "v0", "k1", "[", "v10", BI(123), BL(456789), "v12", "]", "k2", "v2", BEND }; test_bson_from_bcon( bc_array_with_type, BCON_OK, BSON_VALID ); bcon bc_array_2[] = { "k0", "v0", "k1", "[", "v10", "v11", "[", "v120", "v121", "]", "v13", "]", "k2", "v2", BEND }; test_bson_from_bcon( bc_array_2, BCON_OK, BSON_VALID ); bcon bc_doc_array[] = { "k0", "v0", "k1", "{", "k10", "v10", "k11", "[", "v110", "v111", "]", "k12", "v12", "}", "k2", "v2", BEND }; test_bson_from_bcon( bc_doc_array, BCON_OK, BSON_VALID ); bcon bc_array_doc[] = { "k0", "v0", "k1", "[", "v10", "v11", "{", "k120", "v120", "k121", "v121", "}", "v13", "]", "k2", "v2", BEND }; test_bson_from_bcon( bc_array_doc, BCON_OK, BSON_VALID ); }
void test_example_awesome() { bcon_error_t ret; bson b[1]; /* JSON {"BSON": ["awesome", 5.05, 1986]} */ bcon awesome[] = { "BSON", "[", "awesome", BF(5.05), BI(1986), "]", BEND }; test_bson_from_bcon( awesome, BCON_OK, BSON_VALID ); if (verbose ) printf("\t--------\n"); bson_init( b ); bson_append_start_array( b, "BSON" ); bson_append_string( b, "0", "awesome" ); bson_append_double( b, "1", 5.05 ); bson_append_int( b, "2", 1986 ); bson_append_finish_array( b ); ret = bson_finish( b ); if ( verbose ) bson_print( b ); bson_destroy( b ); }
/********************************************************************* * The Tree *********************************************************************/ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) : QTreeWidget( _parent ), p_intf( _p_intf ) { /* General Qt options */ setAlternatingRowColors( true ); setHeaderHidden( true ); setIconSize( QSize( ITEM_HEIGHT,ITEM_HEIGHT ) ); setTextElideMode( Qt::ElideNone ); setUniformRowHeights( true ); CONNECT( this, itemExpanded(QTreeWidgetItem*), this, resizeColumns() ); /* Nice icons */ #define BI( a,b) QIcon a##_icon = QIcon( b ) BI( audio, ":/prefsmenu/advanced/audio" ); BI( video, ":/prefsmenu/advanced/video" ); BI( input, ":/prefsmenu/advanced/codec" ); BI( sout, ":/prefsmenu/advanced/sout" ); BI( advanced, ":/prefsmenu/advanced/extended" ); BI( playlist, ":/prefsmenu/advanced/playlist" ); BI( interface, ":/prefsmenu/advanced/intf" ); #undef BI /* Build the tree for the main module */ module_t *p_module = module_get_main(); /* Initialisation and get the confsize */ PrefsItemData *data = NULL; PrefsItemData *data_sub = NULL; QTreeWidgetItem *current_item = NULL; unsigned confsize; module_config_t *const p_config = module_config_get (p_module, &confsize); /* Go through the list of conf */ for( size_t i = 0; i < confsize; i++ ) { const char *psz_help; QIcon icon; /* Work on a new item */ module_config_t *p_item = p_config + i; switch( p_item->i_type ) { /* This is a category */ case CONFIG_CATEGORY: if( p_item->value.i == -1 ) break; /* PrefsItemData Init */ data = new PrefsItemData(); data->name = qtr( config_CategoryNameGet( p_item->value.i ) ); psz_help = config_CategoryHelpGet( p_item->value.i ); if( psz_help ) data->help = qtr( psz_help ); else data->help.clear(); data->i_type = TYPE_CATEGORY; data->i_object_id = p_item->value.i; /* This is a category, put a nice icon */ switch( p_item->value.i ) { #define CI(a,b) case a: icon = b##_icon;break CI( CAT_AUDIO, audio ); CI( CAT_VIDEO, video ); CI( CAT_INPUT, input ); CI( CAT_SOUT, sout ); CI( CAT_ADVANCED, advanced ); CI( CAT_PLAYLIST, playlist ); CI( CAT_INTERFACE, interface ); } #undef CI /* Create a new QTreeItem to display it in the tree at top level */ current_item = new QTreeWidgetItem(); current_item->setText( 0, data->name ); current_item->setIcon( 0 , icon ); //current_item->setSizeHint( 0, QSize( -1, ITEM_HEIGHT ) ); current_item->setData( 0, Qt::UserRole, qVariantFromValue( data ) ); addTopLevelItem( current_item ); break; /* This is a subcategory */ case CONFIG_SUBCATEGORY: if( p_item->value.i == -1 ) break; /* Special cases: move the main subcategories to the parent cat*/ if( data && ( p_item->value.i == SUBCAT_VIDEO_GENERAL || p_item->value.i == SUBCAT_ADVANCED_MISC || p_item->value.i == SUBCAT_INPUT_GENERAL || p_item->value.i == SUBCAT_INTERFACE_GENERAL || p_item->value.i == SUBCAT_SOUT_GENERAL|| p_item->value.i == SUBCAT_PLAYLIST_GENERAL|| p_item->value.i == SUBCAT_AUDIO_GENERAL ) ) { /* Data still contains the correct thing */ data->i_type = TYPE_CATSUBCAT; data->i_subcat_id = p_item->value.i; data->name = qtr( config_CategoryNameGet( p_item->value.i ) ); psz_help = config_CategoryHelpGet( p_item->value.i ); if( psz_help ) data->help = qtr( psz_help ); else data->help.clear(); current_item->setData( 0, Qt::UserRole, QVariant::fromValue( data ) ); continue; } /* Normal Subcategories */ /* Process the Data */ data_sub = new PrefsItemData(); data_sub->name = qtr( config_CategoryNameGet( p_item->value.i) ); psz_help = config_CategoryHelpGet( p_item->value.i ); if( psz_help ) data_sub->help = qtr( psz_help ); else data_sub->help.clear(); data_sub->i_type = TYPE_SUBCATEGORY; data_sub->i_object_id = p_item->value.i; /* Create a new TreeWidget */ QTreeWidgetItem *subcat_item = new QTreeWidgetItem(); subcat_item->setText( 0, data_sub->name ); subcat_item->setData( 0, Qt::UserRole, qVariantFromValue( data_sub ) ); //subcat_item->setSizeHint( 0, QSize( -1, ITEM_HEIGHT ) ); /* Add it to the parent */ assert( current_item ); current_item->addChild( subcat_item ); break; /* Other items don't need yet a place on the tree */ } } module_config_free( p_config ); module_t **p_list = module_list_get( NULL ); /* Build the tree of plugins */ for( size_t i = 0; (p_module = p_list[i]) != NULL; i++ ) { // Main module excluded if( module_is_main( p_module) ) continue; unsigned confsize; int i_subcategory = 0, i_category = 0; bool b_options = false; module_config_t *const p_config = module_config_get (p_module, &confsize); /* Loop through the configurations items */ for (size_t i = 0; i < confsize; i++) { const module_config_t *p_item = p_config + i; if( p_item->i_type == CONFIG_CATEGORY ) i_category = p_item->value.i; else if( p_item->i_type == CONFIG_SUBCATEGORY ) i_subcategory = p_item->value.i; if( CONFIG_ITEM(p_item->i_type) ) b_options = true; if( b_options && i_category && i_subcategory ) break; } module_config_free (p_config); /* Dummy item, please proceed */ if( !b_options || i_category == 0 || i_subcategory == 0 ) continue; // Locate the category item; QTreeWidgetItem *subcat_item = NULL; bool b_found = false; for( int i_cat_index = 0 ; i_cat_index < topLevelItemCount(); i_cat_index++ ) { /* Get the treeWidgetItem that correspond to the category */ QTreeWidgetItem *cat_item = topLevelItem( i_cat_index ); PrefsItemData *data = cat_item->data( 0, Qt::UserRole ). value<PrefsItemData *>(); /* If we match the good category */ if( data->i_object_id == i_category ) { for( int i_sc_index = 0; i_sc_index < cat_item->childCount(); i_sc_index++ ) { subcat_item = cat_item->child( i_sc_index ); PrefsItemData *sc_data = subcat_item->data(0, Qt::UserRole). value<PrefsItemData *>(); if( sc_data && sc_data->i_object_id == i_subcategory ) { b_found = true; break; } } if( !b_found ) { subcat_item = cat_item; b_found = true; } break; } } if( !b_found ) continue; PrefsItemData *module_data = new PrefsItemData(); module_data->i_type = TYPE_MODULE; module_data->psz_name = strdup( module_get_object( p_module ) ); module_data->name = qtr( module_get_name( p_module, false ) ); module_data->help.clear(); const char *psz_help = module_get_help( p_module ); if ( psz_help ) module_data->help = qtr( psz_help ); QTreeWidgetItem *module_item = new QTreeWidgetItem(); module_item->setText( 0, module_data->name ); module_item->setData( 0, Qt::UserRole, QVariant::fromValue( module_data) ); //module_item->setSizeHint( 0, QSize( -1, ITEM_HEIGHT ) ); subcat_item->addChild( module_item ); } /* We got everything, just sort a bit */ sortItems( 0, Qt::AscendingOrder ); module_list_free( p_list ); resizeColumnToContents( 0 ); }
int main(int argc, char *argv[]) { { libmaus2::lz::LineSplittingGzipOutputStream LSG("gzsplit",4,17); for ( uint64_t i = 0; i < 17; ++i ) LSG << "line_" << i << "\n"; } { libmaus2::lz::LineSplittingGzipOutputStream LSG("nogzsplit",4,17); } testGzip(); testlz4(); #if 0 maskBamDuplicateFlag(std::cin,std::cout); return 0; #endif #if 0 { libmaus2::lz::BgzfInflateDeflateParallel BIDP(std::cin,std::cout,Z_DEFAULT_COMPRESSION,32,128); libmaus2::autoarray::AutoArray<char> B(64*1024,false); int r; uint64_t t = 0; uint64_t last = std::numeric_limits<uint64_t>::max(); uint64_t lcnt = 0; uint64_t const mod = 64*1024*1024; libmaus2::timing::RealTimeClock rtc; rtc.start(); libmaus2::timing::RealTimeClock lrtc; lrtc.start(); while ( (r = BIDP.read(B.begin(),B.size())) ) { BIDP.write(B.begin(),r); lcnt += r; t += r; if ( t/mod != last/mod ) { if ( isatty(STDERR_FILENO) ) std::cerr << "\r" << std::string(60,' ') << "\r"; std::cerr << rtc.formatTime(rtc.getElapsedSeconds()) << " " << t/(1024*1024) << "MB, " << (lcnt/lrtc.getElapsedSeconds())/(1024.0*1024.0) << "MB/s"; if ( isatty(STDERR_FILENO) ) std::cerr << std::flush; else std::cerr << std::endl; lrtc.start(); last = t; lcnt = 0; } } if ( isatty(STDERR_FILENO) ) std::cerr << "\r" << std::string(60,' ') << "\r"; std::cerr << rtc.formatTime(rtc.getElapsedSeconds()) << " " << t/(1024*1024) << "MB, " << (t/rtc.getElapsedSeconds())/(1024.0*1024.0) << "MB/s"; std::cerr << std::endl; return 0; } #endif #if 0 { ::libmaus2::lz::BgzfDeflateParallel BDP(std::cout,32,128,Z_DEFAULT_COMPRESSION); while ( std::cin ) { libmaus2::autoarray::AutoArray<char> B(16384); std::cin.read(B.begin(),B.size()); int64_t const r = std::cin.gcount(); BDP.write(B.begin(),r); } BDP.flush(); std::cout.flush(); } return 0; #endif #if 0 { try { libmaus2::lz::BgzfInflateParallel BIP(std::cin /* ,4,16 */); uint64_t c = 0; uint64_t b = 0; uint64_t d = 0; libmaus2::timing::RealTimeClock rtc; rtc.start(); libmaus2::autoarray::AutoArray<uint8_t> adata(64*1024,false); while ( (d=BIP.read(reinterpret_cast<char *>(adata.begin()),adata.size())) != 0 ) { b += d; if ( ++c % (16*1024) == 0 ) { std::cerr << c << "\t" << b/(1024.0*1024.0*1024.0) << "\t" << static_cast<double>(b)/(1024.0*1024.0*rtc.getElapsedSeconds()) << " MB/s" << std::endl; } } std::cerr << c << "\t" << b/(1024.0*1024.0*1024.0) << "\t" << static_cast<double>(b)/(1024.0*1024.0*rtc.getElapsedSeconds()) << " MB/s" << std::endl; std::cerr << "decoded " << b << " bytes in " << rtc.getElapsedSeconds() << " seconds." << std::endl; } catch(std::exception const & ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } } return 0; #endif std::cerr << "Testing random data on bgzf..."; testBgzfRandom(); std::cerr << "done." << std::endl; std::cerr << "Testing mono..."; testBgzfMono(); std::cerr << "done." << std::endl; ::libmaus2::lz::BgzfDeflate<std::ostream> bdefl(std::cout); char const * str = "Hello, world.\n"; bdefl.write(reinterpret_cast<char const *>(str),strlen(str)); bdefl.flush(); bdefl.write(reinterpret_cast<char const *>(str),strlen(str)); bdefl.flush(); bdefl.addEOFBlock(); return 0; ::libmaus2::lz::BgzfInflateStream SW(std::cin); ::libmaus2::autoarray::AutoArray<char> BB(200,false); while ( SW.read(BB.begin(),BB.size()) ) { } if ( argc < 2 ) return EXIT_FAILURE; return 0; #if 0 ::libmaus2::lz::GzipHeader GZH(argv[1]); return 0; #endif std::ostringstream ostr; ::libmaus2::autoarray::AutoArray<uint8_t> message = ::libmaus2::util::GetFileSize::readFile(argv[1]); std::cerr << "Deflating message of length " << message.size() << "..."; ::libmaus2::lz::Deflate DEFL(ostr); DEFL.write ( reinterpret_cast<char const *>(message.begin()), message.size() ); DEFL.flush(); std::cerr << "done." << std::endl; std::cerr << "Checking output..."; std::istringstream istr(ostr.str()); ::libmaus2::lz::Inflate INFL(istr); int c; uint64_t i = 0; while ( (c=INFL.get()) >= 0 ) { assert ( c == message[i] ); i++; } std::cerr << "done." << std::endl; // std::cerr << "Message size " << message.size() << std::endl; std::string testfilename = "test"; ::libmaus2::lz::BlockDeflate BD(testfilename); BD.write ( message.begin(), message.size() ); BD.flush(); uint64_t const decpos = message.size() / 3; ::libmaus2::lz::BlockInflate BI(testfilename,decpos); ::libmaus2::autoarray::AutoArray<uint8_t> dmessage (message.size(),false); uint64_t const red = BI.read(dmessage.begin()+decpos,dmessage.size()); assert ( red == dmessage.size()-decpos ); std::cerr << "("; for ( uint64_t i = decpos; i < message.size(); ++i ) assert ( message[i] == dmessage[i] ); std::cerr << ")\n"; std::string shortmes1("123456789"); std::string shortmes2("AA"); std::string shortmes3("BB"); std::string shortmes4("CC"); std::string textfile1("test1"); std::string textfile2("test2"); std::string textfile3("test3"); std::string textfile4("test4"); ::libmaus2::lz::BlockDeflate BD1(textfile1); BD1.write ( reinterpret_cast<uint8_t const *>(shortmes1.c_str()), shortmes1.size() ); BD1.flush(); ::libmaus2::lz::BlockDeflate BD2(textfile2); BD2.write ( reinterpret_cast<uint8_t const *>(shortmes2.c_str()), shortmes2.size() ); BD2.flush(); ::libmaus2::lz::BlockDeflate BD3(textfile3); BD3.write ( reinterpret_cast<uint8_t const *>(shortmes3.c_str()), shortmes3.size() ); BD3.flush(); ::libmaus2::lz::BlockDeflate BD4(textfile4); BD4.write ( reinterpret_cast<uint8_t const *>(shortmes4.c_str()), shortmes4.size() ); BD4.flush(); std::vector < std::string > filenames; filenames.push_back(textfile1); filenames.push_back(textfile2); filenames.push_back(textfile3); filenames.push_back(textfile4); for ( uint64_t j = 0; j <= 15; ++j ) { ::libmaus2::lz::ConcatBlockInflate CBI(filenames,j); for ( uint64_t i = 0; i < j; ++i ) std::cerr << ' '; for ( uint64_t i = 0; i < CBI.n-j; ++i ) std::cerr << (char)CBI.get(); std::cerr << std::endl; } return 0; }
static VOID buf_to_bitmap(APTR dest_info , LONG x_src, LONG y_src , LONG x_dest, LONG y_dest , ULONG width, ULONG height , UBYTE *bufptr , Object *src_bm , HIDDT_Pixel *coltab ) { if (BI(dest_info)->minterm == 0x00C0) { LONG y; for (y = 0; y < height; y ++) { LONG x; for (x = 0; x < width; x ++) { setbitmappixel(BI(dest_info)->bitmap , x + x_dest , y + y_dest , *bufptr ++, BI(dest_info)->bmdepth, BI(dest_info)->planemask ); } } } else { LONG y; for (y = 0; y < height; y ++) { LONG x; for (x = 0; x < width; x ++) { ULONG src = *bufptr ++ , dest = 0; ULONG minterm = BI(dest_info)->minterm; /* Set the pixel using correct minterm */ dest = getbitmappixel(BI(dest_info)->bitmap , x + x_dest , y + y_dest , BI(dest_info)->bmdepth , BI(dest_info)->planemask ); #warning Do reverse coltab lookup if (minterm & 0x0010) dest = ~src & ~dest; if (minterm & 0x0020) dest |= ~src & dest; if (minterm & 0x0040) dest |= src & ~dest; if (minterm & 0x0080) dest |= src & dest; setbitmappixel(BI(dest_info)->bitmap , x + x_dest , y + y_dest , dest, BI(dest_info)->bmdepth , BI(dest_info)->planemask ); } } } return; }
void CServerMonitorView::Message(IRCServer *pServer, char *Buffer) { BufferItem BI(BIC_UNKNOWN,strdup(Buffer)); Put(pServer,&BI); }
void test_basic_types() { bcon basic_types[] = {"string", BS("a string"), "f(double)", BF(3.14159), "boolean", BB(1), "time", BT(time(0)), "null", BNULL, "symbol", BX("a symbol"), "int", BI(123), "long", BL(456789L), BEND}; test_bson_from_bcon( basic_types, BCON_OK, BSON_VALID ); }