⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: page.cpp,v $ * PRODUCTION Revision 1000.4  2004/06/01 19:15:52  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.44 * PRODUCTION * =========================================================================== *//*  $Id: page.cpp,v 1000.4 2004/06/01 19:15:52 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:  Lewis Geer * */#include <ncbi_pch.hpp>#include <html/components.hpp>#include <html/page.hpp>#include <html/jsmenu.hpp>#include <corelib/ncbiutil.hpp>#include <errno.h>BEGIN_NCBI_SCOPE// The buffer size for reading from stream.const SIZE_TYPE kBufferSize = 4096;extern const char* kTagStart;extern const char* kTagEnd;extern const char* kTagStartEnd; // CHTMLBasicPageCHTMLBasicPage::CHTMLBasicPage(void)    : CParent("basicpage"),      m_CgiApplication(0),      m_Style(0){    return;}CHTMLBasicPage::CHTMLBasicPage(CCgiApplication* application, int style)    : m_CgiApplication(application),      m_Style(style),      m_PrintMode(eHTML){    return;}CHTMLBasicPage::~CHTMLBasicPage(void){    // BW_02:  the following does not compile on MSVC++ 6.0 SP3:    // DeleteElements(m_TagMap);    for (TTagMap::iterator i = m_TagMap.begin();  i != m_TagMap.end();  ++i) {        delete i->second;    }}void CHTMLBasicPage::SetApplication(CCgiApplication* App){    m_CgiApplication = App;}void CHTMLBasicPage::SetStyle(int style){    m_Style = style;}CNCBINode* CHTMLBasicPage::MapTag(const string& name){    map<string, BaseTagMapper*>::iterator i = m_TagMap.find(name);    if ( i != m_TagMap.end() ) {        return (i->second)->MapTag(this, name);    }    return CParent::MapTag(name);}void CHTMLBasicPage::AddTagMap(const string& name, CNCBINode* node){    AddTagMap(name, CreateTagMapper(node));}void CHTMLBasicPage::AddTagMap(const string& name, BaseTagMapper* mapper){    delete m_TagMap[name];    m_TagMap[name] = mapper;}// CHTMLPageCHTMLPage::CHTMLPage(const string& title)    : m_Title(title){    Init();}CHTMLPage::CHTMLPage(const string& title, const string& template_file)    : m_Title(title){    Init();    SetTemplateFile(template_file);}CHTMLPage::CHTMLPage(const string& title, istream& template_stream)    : m_Title(title){    Init();    SetTemplateStream(template_stream);}CHTMLPage::CHTMLPage(const string& /*title*/,                     const void* template_buffer, SIZE_TYPE size){    Init();    SetTemplateBuffer(template_buffer, size);}CHTMLPage::CHTMLPage(CCgiApplication* application, int style,                     const string& title, const string& template_file)    : CParent(application, style),      m_Title(title){    Init();    SetTemplateFile(template_file);}void CHTMLPage::Init(void){    // Generate internal page name    GeneratePageInternalName();    // Template sources    m_TemplateFile   = kEmptyStr;    m_TemplateStream = 0;    m_TemplateBuffer = 0;    m_TemplateSize   = 0;        m_UsePopupMenus  = false;    AddTagMap("TITLE", CreateTagMapper(this, &CHTMLPage::CreateTitle));    AddTagMap("VIEW",  CreateTagMapper(this, &CHTMLPage::CreateView));}void CHTMLPage::CreateSubNodes(void){    if (m_UsePopupMenus) {        AppendChild(CreateTemplate());    }    // Otherwise, done while printing to avoid latency on large files}CNCBINode* CHTMLPage::CreateTitle(void) {    if ( GetStyle() & fNoTITLE )        return 0;    return new CHTMLText(m_Title);}CNCBINode* CHTMLPage::CreateView(void) {    return 0;}void CHTMLPage::EnablePopupMenu(CHTMLPopupMenu::EType type,                                 const string& menu_script_url,                                 bool use_dynamic_menu){    SPopupMenuInfo info(menu_script_url, use_dynamic_menu);    m_PopupMenus[type] = info;}static bool s_CheckUsePopupMenus(const CNCBINode* node,                                 CHTMLPopupMenu::EType type){    if ( !node  ||  !node->HaveChildren() ) {        return false;    }    ITERATE ( CNCBINode::TChildren, i, node->Children() ) {        const CNCBINode* cnode = node->Node(i);        if ( dynamic_cast<const CHTMLPopupMenu*>(cnode) ) {            const CHTMLPopupMenu* menu                = dynamic_cast<const CHTMLPopupMenu*>(cnode);            if ( menu->GetType() == type )                return true;        }        if ( cnode->HaveChildren()  &&  s_CheckUsePopupMenus(cnode, type)) {            return true;        }    }    return false;}void CHTMLPage::AddTagMap(const string& name, CNCBINode* node){    CParent::AddTagMap(name, node);    for (int t = CHTMLPopupMenu::ePMFirst; t <= CHTMLPopupMenu::ePMLast; t++ )    {        CHTMLPopupMenu::EType type = (CHTMLPopupMenu::EType)t;        if ( m_PopupMenus.find(type) == m_PopupMenus.end() ) {            if ( s_CheckUsePopupMenus(node, type) ) {                EnablePopupMenu(type);                m_UsePopupMenus = true;            }        } else {            m_UsePopupMenus = true;        }    }}void CHTMLPage::AddTagMap(const string& name, BaseTagMapper* mapper){    CParent::AddTagMap(name,mapper);}CNcbiOstream& CHTMLPage::PrintChildren(CNcbiOstream& out, TMode mode){    if (HaveChildren()) {        return CParent::PrintChildren(out, mode);    } else {        m_PrintMode = mode;        AppendChild(CreateTemplate(&out, mode));        return out;    }}CNCBINode* CHTMLPage::CreateTemplate(CNcbiOstream* out, CNCBINode::TMode mode){    // Get template stream    if ( !m_TemplateFile.empty() ) {        CNcbiIfstream is(m_TemplateFile.c_str());        return x_CreateTemplate(is, out, mode);    } else if ( m_TemplateStream ) {        return x_CreateTemplate(*m_TemplateStream, out, mode);    } else if ( m_TemplateBuffer ) {        CNcbiIstrstream is((char*)m_TemplateBuffer, m_TemplateSize);        return x_CreateTemplate(is, out, mode);    } else {        return new CHTMLText(kEmptyStr);    }}CNCBINode* CHTMLPage::x_CreateTemplate(CNcbiIstream& is, CNcbiOstream* out,                                       CNCBINode::TMode mode){    string str;    char   buf[kBufferSize];    if ( !is.good() ) {        NCBI_THROW(CHTMLException, eTemplateAccess,                   "CHTMLPage::CreateTemplate(): failed to open template");    }    // Special case: stream large templates on the first pass    // to reduce latency.    if (out  &&  !m_UsePopupMenus) {        auto_ptr<CNCBINode> node(new CNCBINode);        while (is) {            is.read(buf, sizeof(buf));            str.append(buf, is.gcount());            SIZE_TYPE pos = str.rfind('\n');            if (pos != NPOS) {                ++pos;                CHTMLText* child = new CHTMLText(str.substr(0, pos));                child->Print(*out, mode);                node->AppendChild(child);                str.erase(0, pos);            }        }        if ( !str.empty() ) {            CHTMLText* child = new CHTMLText(str);            child->Print(*out, mode);            node->AppendChild(child);        }        if ( !is.eof() ) {            NCBI_THROW(CHTMLException, eTemplateAccess,                       "CHTMLPage::CreateTemplate(): error reading template");        }                return node.release();    }    if ( m_TemplateSize ) {        str.reserve(m_TemplateSize);    }    while ( is ) {        is.read(buf, sizeof(buf));        if (m_TemplateSize == 0  &&  is.gcount() > 0            &&  str.size() == str.capacity()) {            // We don't know how big str will need to be, so we grow it            // exponentially.            str.reserve(str.size() +                        max((SIZE_TYPE)is.gcount(), str.size() / 2));        }        str.append(buf, is.gcount());    }    if ( !is.eof() ) {        NCBI_THROW(CHTMLException, eTemplateAccess,                   "CHTMLPage::CreateTemplate(): error reading template");    }

⌨️ 快捷键说明

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