labels.cpp 766 Bytes
Newer Older
Mikaël Salson's avatar
Mikaël Salson committed
1
2

#include "labels.h"
Mikaël Salson's avatar
Mikaël Salson committed
3
4
5
#include <cmath>
#include <cstdlib>
#include "tools.h"
Mikaël Salson's avatar
Mikaël Salson committed
6

Mathieu Giraud's avatar
Mathieu Giraud committed
7

8
void load_into_map(map <string, string> &the_map, string map_file)
Mikaël Salson's avatar
Mikaël Salson committed
9
10
11
12
{
  // Loads a simple file with key, values into a map
  
  if (!map_file.size())
13
    return ;
Mikaël Salson's avatar
Mikaël Salson committed
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

  cout << "  <== " << map_file ;

  ifstream f(map_file.c_str());
      
  if (!f.is_open())
    {
      cout << "  [failed] " << endl ;
    }

  int nb_keys = 0 ;

  while (f.good())
    {
      string line ;
      getline (f, line);

      int i = line.find(" ");
      if (i != (int) string::npos)
	{
	  string key = line.substr(0, i);
	  string value = line.substr(i+1, string::npos);
	  
	  nb_keys++ ;      
	  the_map[key] = value + " " + the_map[key];
	}
    }

  cout << ": " << nb_keys << " elements" << endl ;
}
Mikaël Salson's avatar
Mikaël Salson committed
44
45