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

nl-stringindex.h « include « rvtl « hhmm « synlm « contrib - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 22931f081cdd681f235257fb5cc7f588e48a6d99 (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
55
56
57
58
59
60
61
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// This file is part of ModelBlocks. Copyright 2009, ModelBlocks developers. //
//                                                                           //
//    ModelBlocks 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 3 of the License, or      //
//    (at your option) any later version.                                    //
//                                                                           //
//    ModelBlocks 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.                           //
//                                                                           //
//    You should have received a copy of the GNU General Public License      //
//    along with ModelBlocks.  If not, see <http://www.gnu.org/licenses/>.   //
//                                                                           //
//    ModelBlocks developers designate this particular file as subject to    //
//    the "Moses" exception as provided by ModelBlocks developers in         //
//    the LICENSE file that accompanies this code.                           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#ifndef _STRING_INDEX__
#define _STRING_INDEX__

#include <cassert>
#include <string>
using std::string;
#include <map>
using std::map;

class StringIndex{

 private:

  // Data members...
  map <string, int> msi;
  map <int, string> mis;
  int maxIndex;
    
 public:

  // Constructor / destructor methods...
  StringIndex() { maxIndex=0; }

  // Specification methods...
  int addIndex (const char* ps)  { assert(ps!=NULL); return addIndex(string(ps)); }
  int addIndex (const string& s) { if(msi.end()==msi.find(s)){msi[s]=maxIndex;mis[maxIndex]=s;maxIndex++;} return msi[s]; }
  void clear   ( )               { msi.clear(); mis.clear(); maxIndex=0; }
  // Extraction methods...
  int           getSize   ( )               const { return maxIndex; }
  int           getIndex  (const char* ps)  const { assert(ps!=NULL); return getIndex(string(ps)); }
  int           getIndex  (const string& s) const { assert(msi.end()!=msi.find(s));
                                                    return msi.find(s)->second; }
  const string& getString (int i)           const { assert(mis.end()!=mis.find(i));
                                                    return mis.find(i)->second; }
};


#endif // _STRING_INDEX__