This repository has been archived by the owner on Oct 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathXTBImageComplexDictionary.cpp
101 lines (81 loc) · 2.75 KB
/
XTBImageComplexDictionary.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// XTBImageComplexDictionary.cpp
// XTBook
//
// Created by Kawada Tomoaki on 8/1/11.
// Copyright 2011 Nexhawks. All rights reserved.
//
#include "XTBImageComplexDictionary.h"
#include "XTBDicDBReader.h"
#include "platform.h"
#include "TPList/TPLString.h"
#include "TPList/TPLDictionary.h"
#include <tcw/twStrConv.h>
#include "XTBIndexDBReader.h"
#include "TWiki/TWUtils.h"
#include "XTBImageComplexArticle.h"
#include "XTBImageComplexIterator.h"
XTBImageComplexDictionary::XTBImageComplexDictionary(const XTBSysString& path, const TPLDictionary *options):
XTBDictionary(options),
m_images(NULL){
std::wstring imagesFile=L"Images";
std::wstring searchFile;
if(TPLString *value=dynamic_cast<TPLString *>(options->objectForKey(XTBImageComplexImagesFileKey))){
imagesFile=twM2W(value->UTF8String());
}
if(TPLString *value=dynamic_cast<TPLString *>(options->objectForKey(XTBImageComplexSearchFileKey))){
searchFile=twM2W(value->UTF8String());
}
XTBSysString imagesPath;
XTBSysString searchPath;
imagesPath=path+XTBPathSeparator+XTBSysStringFromWString(imagesFile);
if(!searchFile.empty())
searchPath=path+XTBPathSeparator+XTBSysStringFromWString(searchFile);
m_searchIndex=NULL;
try{
// load articles. (required)
m_images=new XTBDicDBReader(imagesPath);
// load search index.
if(XTBDoesPathExist(searchPath+XTBSysText(".indexdb"))){
m_searchIndex=new XTBIndexDBReader(searchPath);
}
}catch(...){
if(m_images)
delete m_images;
if(m_searchIndex)
delete m_searchIndex;
throw;
}
}
XTBImageComplexDictionary::~XTBImageComplexDictionary(){
if(m_images)
delete m_images;
if(m_searchIndex)
delete m_searchIndex;
}
std::string XTBImageComplexDictionary::dbKeyForDocumentName(const std::wstring& name) const{
return twW2M(TWUtils::dbKeyFor(name));
}
bool XTBImageComplexDictionary::hasDocumentForName(const std::wstring& name) const{
std::string dbKey=dbKeyForDocumentName(name);
return m_images->pointerForKey(dbKey)!=XTBDicDBInvalidPointer;
}
XTBImageComplexArticle *XTBImageComplexDictionary::articleForDbKey(const std::string& dbKey) const{
return new XTBImageComplexArticle(this, dbKey);
}
XTBDocument *XTBImageComplexDictionary::documentForName(const std::wstring&name) const{
std::string dbKey=dbKeyForDocumentName(name);
if(m_images->pointerForKey(dbKey)!=XTBDicDBInvalidPointer){
return articleForDbKey(dbKey);
}
return NULL;
}
XTBDictionaryIterator *XTBImageComplexDictionary::searchWithKey(const std::wstring&name) const{
if(!m_searchIndex)
return NULL;
std::string key=twW2M(name);
unsigned int lowerBound=m_searchIndex->lowerBoundForKey(key);
unsigned int upperBound=m_searchIndex->upperBoundForKey(key);
return new XTBImageComplexIterator(this, m_searchIndex,
lowerBound, upperBound);
}