Repository navigation
Expand file tree
/
Copy pathAttributeTranslator.cpp
More file actions
88 lines (80 loc) · 2.26 KB
/
Copy pathAttributeTranslator.cpp
File metadata and controls
88 lines (80 loc) · 2.26 KB
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
//
// AttributeTranslator.cpp
// proj4
//
// Created by Andy on 3/3/22.
//
#include "AttributeTranslator.h"
#include <fstream>
#include <iostream>
AttributeTranslator::AttributeTranslator()
{
}
bool AttributeTranslator::Load(std::string filename)
{
std::ifstream file(filename);
if (file.fail() || !file)
{
return false;
}
std::string line;
while(getline(file, line))
{
int i = 0;
int track = 0;
int comma = 0;
std::string source;
std::string compatible_attribute;
while(line[i] != '\n' && i<line.size())
{
if(line[i] == ',' && track == 1)//separator between source and compatible
{
source = line.substr(0, i);
comma = i;
}
if(line[i] == ',' && track == 2)//separator between compatible value and compatible attribute
{
compatible_attribute = line.substr(comma+1, i-(comma+1));
comma = i;
}
if(line[i]==',')
{
track++;
}
i++;
}
std::string compatible_value = line.substr(comma+1, i);
std::vector<AttValPair>* temp = SourceMatch.search(source);
std::string sourceCompatible = source+compatible_attribute+compatible_value;
AttValPair newPair = AttValPair(compatible_attribute, compatible_value);
if(temp!=nullptr)//if already in the radix tree
{
if(unique.insert(sourceCompatible).second == true)
{
temp->push_back(newPair);
}
}
else
{
std::vector<AttValPair> newVector;
newVector.push_back(newPair);
unique.insert(sourceCompatible);
SourceMatch.insert(source, newVector);
}
}
return true;
}
std::vector<AttValPair> AttributeTranslator::FindCompatibleAttValPairs(const AttValPair& source) const//Needs to check for duplicates
{
std::string sourceString = source.attribute+","+source.value;
std::vector<AttValPair>* temp = SourceMatch.search(sourceString);
if(temp!=nullptr)
{
return *temp;
}
else
{
std::vector<AttValPair> newVector;
return newVector;
}
}