PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/strigi-0.7.7/strigiutils/bin/xmlindexer/xmlindexwriter.cpp

#
C++ | 60 lines | 39 code | 1 blank | 20 comment | 10 complexity | c8bc3cfe974e9cbe2de097b643746cc4 MD5 | raw file
Possible License(s): LGPL-2.0
 1/* This file is part of Strigi Desktop Search
 2 *
 3 * Copyright (C) 2007 Jos van den Oever <jos@vandenoever.info>
 4 *
 5 * This library is free software; you can redistribute it and/or
 6 * modify it under the terms of the GNU Library General Public
 7 * License as published by the Free Software Foundation; either
 8 * version 2 of the License, or (at your option) any later version.
 9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB.  If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20#include "xmlindexwriter.h"
21using namespace std;
22using namespace Strigi;
23
24void
25XmlIndexWriter::initWriterData(const FieldRegister& f) {
26    map<string, RegisteredField*>::const_iterator i;
27    map<string, RegisteredField*>::const_iterator end(f.fields().end());
28    for (i = f.fields().begin(); i != end; ++i) {
29        Tag* tag = static_cast<Tag*>(i->second->writerData());
30        if (tag) {
31            tag->refcount++;
32            continue;
33        }
34        tag = new Tag();
35        tag->refcount = 1;
36        const string s(i->first);
37        const string& n = mapping.map(s);
38        if (s == n) {
39            tag->open = "  <value name='" + n + "'>";
40            tag->close = "</value>\n";
41        } else {
42            tag->open = "  <" + n + '>';
43            tag->close = "</" + n + ">\n";
44        }
45        i->second->setWriterData(tag);
46    }
47}
48void
49XmlIndexWriter::releaseWriterData(const FieldRegister& f) {
50    map<string, RegisteredField*>::const_iterator i;
51    map<string, RegisteredField*>::const_iterator end(f.fields().end());
52    for (i = f.fields().begin(); i != end; ++i) {
53        Tag* tag = static_cast<Tag*>(i->second->writerData());
54        if (tag->refcount-- == 1) {
55            //fprintf(stderr, "free for %s\n", i->second->key().c_str());
56            delete tag;
57            i->second->setWriterData(0);
58        }
59    }
60}