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

📄 metadata.cpp

📁 Last change: 2008-02-03 This is the source code of KCeasy。
💻 CPP
字号:
/*
This file is part of KCeasy (http://www.kceasy.com)
Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/
//---------------------------------------------------------------------------
#pragma hdrstop
#include "MetaData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)

namespace KCeasyEngine {

// mime type handling

struct
{
    char* MimeType;
    TFileType FileType;
} const MimeMapping[] =
{
    "application/msword",               FTDocument,
    "application/rtf",                  FTDocument,
    "application/pdf",                  FTDocument,
    "application/postscript",           FTDocument,
    "application/msaccess",             FTDocument,
    "application/vnd.ms-excel",         FTDocument,
    "application/vnd.ms-powerpoint",    FTDocument,
    "application/wordperfect5.1",       FTDocument,
    "application/x-javascript",         FTDocument,
    "application/x-latex",              FTDocument,
    "application/x-perl",               FTDocument,
    "application/x-star-office",        FTDocument,
    "application/x-bittorrent",         FTTorrent,
    NULL, FTUnknown
};

TFileType FileTypeFromMime(const string& MimeType)
{
    // special mappings
    for(int i=0;MimeMapping[i].MimeType;++i) {
        if(MimeType == MimeMapping[i].MimeType)
            return MimeMapping[i].FileType;
    }

    int slash = MimeType.find('/');
    if(MimeType.compare(0,slash,"application") == 0)
        return FTUnknown;
    else if(MimeType.compare(0,slash,"audio") == 0)
        return FTAudio;
    else if(MimeType.compare(0,slash,"video") == 0)
        return FTVideo;
    else if(MimeType.compare(0,slash,"image") == 0)
        return FTImage;
    else if(MimeType.compare(0,slash,"text") == 0)
        return FTDocument;
    else
        return FTUnknown;
}

// meta data handling

TMetaData::TMetaData()
{
}

TMetaData::TMetaData(const TMetaData& Org)
{
    pair_map = Org.pair_map;
}

TMetaData& TMetaData::operator =(const TMetaData& Org)
{
    pair_map = Org.pair_map;
    return *this;
}

const string& TMetaData::Get(const char* Name) const
{
    static string empty("");
    map<string,TMetaDataPair>::const_iterator itr = pair_map.find(Name);
    return (itr != pair_map.end()) ? (*itr).second.Value : empty;
}

int TMetaData::GetInt(const char* Name) const
{
    map<string,TMetaDataPair>::const_iterator itr = pair_map.find(Name);
    return (itr != pair_map.end()) ? string_to_int((*itr).second.Value) : 0;
}

void TMetaData::Set(string& Name, string& Value)
{
    pair_map.insert(map<string,TMetaDataPair>::value_type(Name,TMetaDataPair(Name,Value)));
}

void TMetaData::SetInt(string& Name, int Value)
{
    string ValueStr = int_to_string(Value);
    pair_map.insert(map<string,TMetaDataPair>::value_type(Name,TMetaDataPair(Name,ValueStr)));
}

} // namespace KCeasyEngine

⌨️ 快捷键说明

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