test_obj_convert.cpp
来自「ncbi源码」· C++ 代码 · 共 348 行
CPP
348 行
/* * =========================================================================== * PRODUCTION $Log: test_obj_convert.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 20:45:05 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== *//* $Id: test_obj_convert.cpp,v 1000.1 2004/06/01 20:45:05 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Mike DiCuccio * * File Description: * Test application for plugins */#include <ncbi_pch.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbiargs.hpp>#include <corelib/ncbienv.hpp>#include <corelib/ncbireg.hpp>#include <gui/core/idocument.hpp>#include <gui/core/obj_convert.hpp>#include <gui/core/plugin_arg_dialog.hpp>#include <gui/core/plugin_exception.hpp>#include <gui/core/selection_buffer.hpp>#include <gui/plugin/PluginArgSet.hpp>#include <gui/objutils/utils.hpp>#include <objects/seq/Bioseq.hpp>#include <objmgr/feat_ci.hpp>#include <objmgr/object_manager.hpp>#include <objmgr/scope.hpp>#include <objtools/data_loaders/genbank/gbloader.hpp>#include <serial/objostr.hpp>#include <serial/serial.hpp>USING_NCBI_SCOPE;USING_SCOPE(objects);//// a test exception class//class CObjConvertTestException : EXCEPTION_VIRTUAL_BASE public CException{public: // Enumerated list of document management errors enum EErrCode { eTestFailed }; // Translate the specific error code into a string representations of // that error code. virtual const char* GetErrCodeString(void) const { switch (GetErrCode()) { case eTestFailed: return "eTestFailed"; default: return CException::GetErrCodeString(); } } NCBI_EXCEPTION_DEFAULT(CObjConvertTestException, CException);};class CObjConvertTestApp : public CNcbiApplication{public: CObjConvertTestApp();private: virtual void Init(void); virtual int Run(void); virtual void Exit(void); // // internal testing routines // void x_TestObjConvert(); void x_TestTime();};CObjConvertTestApp::CObjConvertTestApp(){}/////////////////////////////////////////////////////////////////////////////// Init test for all different types of argumentsvoid CObjConvertTestApp::Init(void){ // Create command-line argument descriptions class auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); // Specify USAGE context arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), "Object conversion test application"); arg_desc->AddKey("acc", "Accession", "Accession to test", CArgDescriptions::eString); arg_desc->AddDefaultKey("iters", "Iterations", "Iterations to test", CArgDescriptions::eInteger,#ifdef _DEBUG "1"#else "10"#endif ); // Setup arg.descriptions for this application SetupArgDescriptions(arg_desc.release());}int CObjConvertTestApp::Run(void){ CArgs args = GetArgs(); const size_t MAX_ITERS = args["iters"].AsInteger(); string acc = args["acc"].AsString(); CRef<CSeq_id> id(new CSeq_id(acc)); if (id->Which() == CSeq_id::e_not_set) { LOG_POST(Fatal << "don't understand accession " << acc); } CRef<CObjectManager> obj_mgr(new CObjectManager()); obj_mgr->RegisterDataLoader(*new CGBDataLoader(), CObjectManager::eDefault); CRef<CScope> scope(new CScope(*obj_mgr)); scope->AddDefaults(); CRef<CSeq_loc> loc(new CSeq_loc()); loc->SetWhole(*id); // pass 1: load all features into memory and index cout << "priming..."; cout.flush(); SAnnotSelector sel = CSeqUtils::GetAnnotSelector(); {{ CFeat_CI feat_iter(*scope, *loc, sel); cout << "done." << endl; cout << "found " << feat_iter.GetSize() << " features" << endl; }} // // time raw use of CFeat_CI // cout << "timing CFeat_CI..."; cout.flush(); CStopWatch sw; sw.Start(); {{ size_t count = 0; for (size_t iters = 0; iters < MAX_ITERS; ++iters) { CFeat_CI feat_iter(*scope, *loc, sel); for ( ; feat_iter; ++feat_iter) { ++count; } } }} double e = sw.Elapsed(); cout << "done" << endl; cout << MAX_ITERS << " iterations in " << e << " seconds = " << e / MAX_ITERS << " secs/iter" << endl; // // time direct use of CObjectConverter // cout << "timing CObjectConverter..."; cout.flush(); sw.Start(); {{ size_t size = 0; for (size_t iters = 0; iters < MAX_ITERS; ++iters) { CObjConverter::TObjList objs; CObjectConverter::Convert(*scope, *loc, CSeq_feat::GetTypeInfo(), objs); size += objs.size(); } }} e = sw.Elapsed(); cout << "done" << endl; cout << MAX_ITERS << " iterations in " << e << " seconds = " << e / MAX_ITERS << " secs/iter" << endl; // // time use of CObjectCache // cout << "timing CObjectConverter..."; cout.flush(); sw.Start(); {{ size_t sum = 0; CConvertCache cache; for (size_t iters = 0; iters < MAX_ITERS; ++iters) { const CObjectConverter::TObjList& objs = cache.Convert(*scope, *loc, CSeq_feat::GetTypeInfo()); sum += objs.size(); } }} e = sw.Elapsed(); cout << "done" << endl; cout << MAX_ITERS << " iterations in " << e << " seconds = " << e / MAX_ITERS << " secs/iter" << endl; return 0;}/////////////////////////////////////////////////////////////////////////////// Cleanupvoid CObjConvertTestApp::Exit(void){ SetDiagStream(0);}/////////////////////////////////////////////////////////////////////////////// MAINint main(int argc, const char* argv[]){ // Execute main application function return CObjConvertTestApp().AppMain(argc, argv, 0, eDS_Default, 0);}/* * =========================================================================== * $Log: test_obj_convert.cpp,v $ * Revision 1000.1 2004/06/01 20:45:05 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * * Revision 1.6 2004/06/01 18:04:02 dicuccio * Tweak to avoid warning message * * Revision 1.5 2004/05/21 22:27:41 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.4 2004/05/03 17:53:53 dicuccio * Tweaked makefiles to support new gui_objutils library * * Revision 1.3 2004/01/21 12:38:19 dicuccio * redesigned CObjectCOnverter API to eliminate temporary object creation * * Revision 1.2 2004/01/15 16:28:02 dicuccio * FIxed compilation errors - test_obj_convert now works * * Revision 1.1 2004/01/08 11:35:03 dicuccio * Initial revision * * Revision 1.14 2003/10/24 02:13:15 ucko * Fix for new CPluginArgDialog interface * * Revision 1.13 2003/10/07 17:26:15 dicuccio * FIxed for URL -> Value conversion * * Revision 1.12 2003/09/29 15:42:05 dicuccio * Deprecated gui/scope.hpp. Merged gui/core/types.hpp into gui/types.hpp * * Revision 1.11 2003/09/04 14:01:52 dicuccio * Introduce IDocument and IView as abstract base classes for CDocument and CView * * Revision 1.10 2003/07/17 11:59:50 friedman * Include CSelectionBuffer::TSelList for SertArgs. Test Boolesn/Flag dialog widgets. * * Revision 1.9 2003/07/16 15:22:36 dicuccio * Implemented tool tips for arguments * * Revision 1.8 2003/06/20 14:47:41 dicuccio * Revised handling of plugin registration (moved GetInfo() out of plugin factory * and into each handler as a static function) * * Revision 1.7 2003/05/19 13:36:00 dicuccio * Moved gui/core/plugin/ -> gui/plugin/. Merged gui/core/algo, gui/core/doc/, * and gui/core/view/ into one library (gui/core/) * * Revision 1.6 2003/05/09 16:49:01 dicuccio * Added explicit check so that default set-constraint arguments will have their * values shown * * Revision 1.5 2003/04/25 14:15:24 dicuccio * Fix compilation errors resulting from changes to plugin API * * Revision 1.4 2003/04/21 15:13:15 dicuccio * Added real-life test arguments * * Revision 1.3 2003/04/16 11:39:50 dicuccio * Added torture-test menu with many entries * * Revision 1.2 2003/03/28 19:20:19 dicuccio * Added default argument for testing * * Revision 1.1 2003/03/20 19:57:28 dicuccio * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?