filter.cpp

来自「ncbi源码」· C++ 代码 · 共 214 行

CPP
214
字号
/* * =========================================================================== * PRODUCTION $Log: filter.cpp,v $ * PRODUCTION Revision 1000.0  2004/06/01 21:20:31  gouriano * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2 * PRODUCTION * =========================================================================== *//*  $Id: filter.cpp,v 1000.0 2004/06/01 21:20:31 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: *    CFilterSet -- container for a number of column filtering rules *    CFilter -- encapsulates a single filter rule */#include <ncbi_pch.hpp>#include <gui/objutils/filter.hpp>BEGIN_NCBI_SCOPECFilter::CFilter(const string& name, int col, EMode mode,                 const string& data)    : m_Name(name),      m_Col(col),      m_Mode(mode),      m_Data(data){}bool CFilter::Filter(const vector<string>& row, ECompare compare) const{    if (m_Col < 0  ||  m_Col >= (int)row.size()) {        return false;    }    switch (m_Mode) {    case ePass:        return true;    case eContains:        // we force comparison as a string        return (row[m_Col].find(m_Data) != string::npos);    case eDoesntContain:        // we force comparison as a string        return (row[m_Col].find(m_Data) == string::npos);    case eEquals:        if (compare == eString) {            return (row[m_Col] == m_Data);        }        return (NStr::StringToInt(row[m_Col], 10, NStr::eCheck_Skip) ==                NStr::StringToInt(m_Data,     10, NStr::eCheck_Skip));    case eDoesntEqual:        if (compare == eString) {            return (row[m_Col] != m_Data);        }        return (NStr::StringToInt(row[m_Col], 10, NStr::eCheck_Skip) !=                NStr::StringToInt(m_Data,     10, NStr::eCheck_Skip));    case eLess:        if (compare == eString) {            return (row[m_Col] < m_Data);        }        return (NStr::StringToInt(row[m_Col], 10, NStr::eCheck_Skip) <                NStr::StringToInt(m_Data,     10, NStr::eCheck_Skip));    case eLessEquals:        if (compare == eString) {            return (row[m_Col] <= m_Data);        }        return (NStr::StringToInt(row[m_Col], 10, NStr::eCheck_Skip) <=                NStr::StringToInt(m_Data,     10, NStr::eCheck_Skip));    case eGreater:        if (compare == eString) {            return (row[m_Col] > m_Data);        }        return (NStr::StringToInt(row[m_Col], 10, NStr::eCheck_Skip) >                NStr::StringToInt(m_Data,     10, NStr::eCheck_Skip));    case eGreaterEquals:        if (compare == eString) {            return (row[m_Col] >= m_Data);        }        return (NStr::StringToInt(row[m_Col], 10, NStr::eCheck_Skip) >=                NStr::StringToInt(m_Data,     10, NStr::eCheck_Skip));    }    return false;}// filter a given row, returning true if a match existsbool CFilterSet::Filter(const vector<string>& row) const{    ITERATE (TFilters, iter, m_Filters) {        const CFilter& filter = **iter;        int col = filter.GetColumn();        if ( !filter.Filter(row, m_ColTypes[col]) ) {            return false;        }    }    return true;}// add a filter to the listvoid CFilterSet::Add(CFilter* filter){    m_Filters.push_back(CRef<CFilter>(filter));}// remove a named filtervoid CFilterSet::Remove(const string& name){    NON_CONST_ITERATE (TFilters, iter, m_Filters) {        if ((*iter)->GetName() == name) {            iter = m_Filters.erase(iter);            --iter;        }    }}// remove a filter by pointervoid CFilterSet::Remove(CFilter* filter){    NON_CONST_ITERATE (TFilters, iter, m_Filters) {        if ((*iter).GetPointer() == filter) {            m_Filters.erase(iter);            break;        }    }}void CFilterSet::SetColType(size_t col, CFilter::ECompare comp){    if (m_ColTypes.size() <= col) {        m_ColTypes.resize(col + 1, CFilter::eString);    }    m_ColTypes[col] = comp;}END_NCBI_SCOPE/* * =========================================================================== * $Log: filter.cpp,v $ * Revision 1000.0  2004/06/01 21:20:31  gouriano * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2 * * Revision 1.2  2004/05/21 22:27:43  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.1  2004/04/30 11:48:15  dicuccio * Initial commit - split out from src/gui/utils * * Revision 1.5  2003/06/23 13:20:50  dicuccio * Use size_t instead of int for indexing * * Revision 1.4  2003/03/11 15:25:12  kuznets * iterate -> ITERATE * * Revision 1.3  2003/01/15 21:15:17  dicuccio * Removed useless _TRACE() messages * * Revision 1.2  2003/01/13 13:10:11  dicuccio * Namespace clean-up.  Retired namespace gui -> converted all to namespace * ncbi.  Moved all FLUID-generated code into namespace ncbi. * * Revision 1.1  2003/01/08 15:03:34  dicuccio * Added filter classes for filtering rows of string-based data * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?