PluginMRUList.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: PluginMRUList.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:26:05 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: PluginMRUList.cpp,v 1000.0 2004/06/01 21:26: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.
- *
- * ===========================================================================
- *
- * Author: .......
- *
- * File Description:
- * .......
- *
- * Remark:
- * This code was originally generated by application DATATOOL
- * using specifications from the data definition file
- * 'plugin.asn'.
- */
- // standard includes
- #include <ncbi_pch.hpp>
- #include <corelib/ncbistre.hpp>
- #include <serial/objostr.hpp>
- #include <serial/objistr.hpp>
- #include <serial/serial.hpp>
- #include <gui/utils/system_path.hpp>
- #include <gui/plugin/PluginMRUEntry.hpp>
- // generated includes
- #include <gui/plugin/PluginMRUList.hpp>
- // generated classes
- BEGIN_NCBI_SCOPE
- BEGIN_objects_SCOPE // namespace ncbi::objects::
- // constructor
- CPluginMRUList::CPluginMRUList(const string& filename, int max_list_size)
- : m_Filename(filename),
- m_MaxListSize(max_list_size)
- {
- x_ReadCacheFile();
- }
- // destructor
- CPluginMRUList::~CPluginMRUList(void)
- {
- }
- void CPluginMRUList::Add(CPluginMessage& msg, const string& label)
- {
- if (CRef<CPluginMRUEntry> entry = x_Exists(label)) {
- Set().remove(entry);
- }
- CRef<CPluginMessage> clone(new CPluginMessage());
- clone->Assign(msg);
- clone->SetReply().Reset();
- CRef<CPluginMRUEntry> entry(new CPluginMRUEntry);
- entry->SetMessage(*clone);
- entry->SetLabel(label);
-
- Set().push_front(entry);
- while (Get().size() > m_MaxListSize) {
- Set().pop_back();
- }
- x_WriteCacheFile();
- }
- void CPluginMRUList::Delete(CPluginMessage& msg)
- {
- if (CRef<CPluginMRUEntry> entry = x_Exists(msg)) {
- Set().remove(entry);
- }
- }
- CRef<CPluginMRUEntry> CPluginMRUList::x_Exists(const string& label)
- {
- NON_CONST_ITERATE(CPluginMRUList::Tdata, iter, Set()) {
- CRef<CPluginMRUEntry> entry = *iter;
-
- if (entry->GetLabel() == label) {
- return entry;
- }
- }
- return CRef<CPluginMRUEntry>(null);
- }
- CRef<CPluginMRUEntry> CPluginMRUList::x_Exists(CPluginMessage& msg)
- {
- CRef<CPluginMessage> msg_ref(&msg);
- NON_CONST_ITERATE(CPluginMRUList::Tdata, iter, Set()) {
- CRef<CPluginMRUEntry> entry = *iter;
-
- if (&(entry->GetMessage()) == &msg) {
- return entry;
- }
- }
- return CRef<CPluginMRUEntry>(null);
- }
- //const CPluginMRUList::TPluginMessageList&
- //CPluginMRUList::GetMessageList() const
- //{
- // return m_List;
- //}
- void CPluginMRUList::x_ReadCacheFile()
- {
- string filename = CSystemPath::ResolvePath("<home>/" + m_Filename);
- auto_ptr<CNcbiIfstream> in_file_str
- (new CNcbiIfstream(filename.c_str()));
- if (in_file_str->fail()) {
- // log
- return;
- }
- auto_ptr<CObjectIStream> in_obj_str
- (CObjectIStream::Open(eSerial_AsnText, *in_file_str));
- try {
- *in_obj_str >> *this;
- }
- catch (exception const except) {
- LOG_POST(Warning << "MRU Chache file read failed: " << except.what());
- }
- /**
- catch (...) {
- LOG_POST(Warning << "MRU Chache file read failed: ");
- }
- **/
- /*
- while (!in_file_str->eof()) {
- CRef<CPluginMessage> msg(new CPluginMessage());
-
- try {
- *in_obj_str >> *msg;
- }
- catch (...) {
- // log
- return;
- }
- m_List.push_back(msg);
- }
- */
- }
- void CPluginMRUList::x_WriteCacheFile()
- {
- string filename = CSystemPath::ResolvePath("<home>/" + m_Filename);
- auto_ptr<CNcbiOfstream> out_file_str
- (new CNcbiOfstream(filename.c_str(), IOS_BASE::trunc));
- if (out_file_str->fail()) {
- // log
- return;
- }
- auto_ptr<CObjectOStream> out_obj_str
- (CObjectOStream::Open(eSerial_AsnText, *out_file_str));
- *out_obj_str << *this;
- // ITERATE(TPluginMessageList, iter, m_List) {
- // *out_obj_str << **iter;
- // }
- }
- END_objects_SCOPE // namespace ncbi::objects::
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- *
- * $Log: PluginMRUList.cpp,v $
- * Revision 1000.0 2004/06/01 21:26:05 gouriano
- * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/06/01 18:09:45 dicuccio
- * Always prune the MRU list to the maximum size if it is larger
- *
- * Revision 1.2 2004/05/21 22:27:46 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.1 2004/05/18 11:18:35 friedman
- * Initial Revision
- *
- *
- * ===========================================================================
- */
- /* Original file checksum: lines: 64, chars: 1889, CRC32: 5415d4ae */