📄 pathmapper.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 "PathMapper.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
namespace KCeasyEngine {
// meta data handling
TPathMapper::TPathMapper()
{
SetNeedToMap(true);
}
TPathMapper::TPathMapper(const TPathMapper& Org)
{
MapList = Org.MapList;
NeedToMap = Org.NeedToMap;
}
TPathMapper& TPathMapper::operator =(const TPathMapper& Org)
{
MapList = Org.MapList;
NeedToMap = Org.NeedToMap;
return *this;
}
string TPathMapper::Serialize()
{
if(MapList.empty())
return "";
Iterator itr = MapList.begin();
string Serial = (*itr).Key + "*" + (*itr).Path;
for(++itr; itr != MapList.end(); ++itr)
Serial += string("|") + (*itr).Key + "*" + (*itr).Path;
return Serial;
}
bool TPathMapper::Unserialize(const string& Serial)
{
list<string> strlst = string_split(Serial,"|");
int pos;
MapList.clear();
for(list<string>::iterator itr = strlst.begin(); itr != strlst.end(); ++itr) {
if((pos = (*itr).find('*')) == -1) {
MapList.clear();
return false;
}
string Key = (*itr).substr(0,pos);
string Path = (*itr).substr(pos+1);
Insert(Key,Path,0);
}
return true;
}
bool TPathMapper::Insert(const string& Key, const string& Path, int Pos)
{
// remove map if it is somewhere else in the list
for(Iterator itr = MapList.begin(); itr != MapList.end(); ++itr) {
if((*itr).Key == Key)
MapList.erase(itr);
}
// add at Pos
Iterator itr = MapList.begin();
for(int i=0; i<Pos && itr != MapList.end(); i++)
++itr;
MapList.insert(itr,TPathMap(Key,Path));
return true;
}
void TPathMapper::Remove(const string& Key)
{
// remove map if it is somewhere else in the list
for(Iterator itr = MapList.begin(); itr != MapList.end(); ++itr) {
if((*itr).Key == Key)
MapList.erase(itr);
}
}
string TPathMapper::Map(const string& Path)
{
if(!NeedToMap)
return UnixToWindowsPath(Path);
for(Iterator itr = MapList.begin();itr != MapList.end(); ++itr) {
string PathBegin = Path.substr(0,(*itr).Key.length());
if(PathBegin == (*itr).Key) {
string NewPath = (*itr).Path;
NewPath += Path.substr((*itr).Key.length());
return UnixToWindowsPath(NewPath);
}
}
return "";
}
bool TPathMapper::MappingExists(const string& Path)
{
for(Iterator itr = MapList.begin();itr != MapList.end(); ++itr) {
string PathBegin = Path.substr(0,(*itr).Key.length());
if(PathBegin == (*itr).Key)
return true;
}
return false;
}
bool TPathMapper::PathUsable(const string &Path)
{
if(Path == "")
return false;
if(!NeedToMap)
return true;
if(MappingExists(Path))
return true;
return false;
}
} // namespace KCeasyEngine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -