Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index_builder.cpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a73439aac7407e04144d1f6c6e4efb2b8906596d (plain)
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
#include "index_builder.hpp"
#include "features_vector.hpp"

#include "../defines.hpp"

#include "../coding/file_container.hpp"


namespace indexer
{
  bool BuildIndexFromDatFile(string const & datFile, string const & tmpFile)
  {
    try
    {
      FilesContainerR readCont(datFile);
      FeaturesVector featuresVector(readCont);

      FilesContainerW writeCont(datFile, FileWriter::OP_APPEND);

      FileWriter writer = writeCont.GetWriter(INDEX_FILE_TAG);

      feature::DataHeader header;
      header.Load(readCont.GetReader(HEADER_FILE_TAG));

      BuildIndex(header.GetScale(header.GetScalesCount()-1) + 1, featuresVector, writer, tmpFile);
      writer.Flush();

      writeCont.Finish();
    }
    catch (Reader::OpenException const & e)
    {
      LOG(LERROR, (e.what(), " file is not found"));
      return false;
    }
    catch (Reader::Exception const & e)
    {
      LOG(LERROR, ("Unknown error while reading file ", e.what()));
      return false;
    }
    catch (Writer::Exception const & e)
    {
      LOG(LERROR, ("Error writing index file", e.what()));
    }

#ifdef DEBUG
    FilesContainerR readCont(datFile);
    FilesContainerR::ReaderT r = readCont.GetReader(HEADER_FILE_TAG);
    int64_t const base = ReadPrimitiveFromPos<int64_t>(r, 0);
    LOG(LINFO, ("OFFSET = ", base));
#endif

    return true;
  }
} // namespace indexer