HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxMatchInfo.cpp
Go to the documentation of this file.
1 #include "SphinxMatchInfo.hpp"
2 #include "SphinxResultData.hpp"
3 
4 namespace HCE
5 {
6 namespace sphinx
7 {
8 //-------------------------------------------------------------------
10 : name(""), value("")
11 {
12  (*this) = rhs;
13 }
14 //-------------------------------------------------------------------
16 : name(""), value("")
17 {
18  (*this) = std::forward<AttrInfo>(rhs);
19 }
20 //-------------------------------------------------------------------
22 {
23  if (this != &rhs)
24  {
25  name = rhs.name;
26  value = rhs.value;
27  }
28  return *this;
29 }
30 //-------------------------------------------------------------------
32 {
33  if (this != &rhs)
34  {
35  name = std::move(rhs.name);
36  value = std::move(rhs.value);
37  }
38  return *this;
39 }
40 //-------------------------------------------------------------------
41 //-------------------------------------------------------------------
43 :docId(0), weight(""), attributes()
44 {
45 }
46 //-------------------------------------------------------------------
48 :docId(0), weight(""), attributes(attributesCount)
49 {
50 }
51 //-------------------------------------------------------------------
53 :docId(0), weight(""), attributes(rhs.getAttributes().size())
54 {
55  (*this) = rhs;
56 }
57 //-------------------------------------------------------------------
59 :docId(0), weight(""), attributes(rhs.getAttributes().size())
60 {
61  (*this) = std::forward<SphinxMatchInfo>(rhs);
62 }
63 //-------------------------------------------------------------------
64 void SphinxMatchInfo::setWeightFromNumeric(unsigned long long weight, unsigned long long length)
65 {
66  setWeightFromHexString(toHexString(weight, length));
67 }
68 //-------------------------------------------------------------------
70 {
71  setWeight(weight);
72 }
73 //-------------------------------------------------------------------
74 void SphinxMatchInfo::setWeightFromDecString(const std::string& weight, unsigned long long length)
75 {
76  unsigned long long value = 0;
77  try
78  {
79  value = std::stoull(weight);
80  }
81  catch(std::exception&)
82  {
83 
84  }
85  setWeightFromNumeric(value, length);
86 }
87 //-------------------------------------------------------------------
89 {
90  if (this != &rhs)
91  {
92  docId = rhs.getDocId();
93  weight = rhs.getWeight();
94  attributes = rhs.getAttributes();
95  }
96  return *this;
97 }
98 //-------------------------------------------------------------------
100 {
101  if (this != &rhs)
102  {
103  docId = std::move(rhs.getDocId());
104  weight = std::move(rhs.getWeight());
105  attributes = std::move(rhs.getAttributes());
106  }
107  return *this;
108 }
109 //-------------------------------------------------------------------
111 {
112  attributes.push_back(SphinxResultDataItem<AttrInfo>(attrInfo));
113 }
114 //-------------------------------------------------------------------
116 {
117  attributes.push_back(SphinxResultDataItem<AttrInfo>(std::forward<AttrInfo>(attrInfo)));
118 }
119 //-------------------------------------------------------------------
120 void SphinxMatchInfo::addAttrInfo(const std::string& name, const std::string& value)
121 {
122  addAttrInfo(std::forward<AttrInfo>(AttrInfo(name, value)));
123 }
124 //-------------------------------------------------------------------
125 const AttrInfo SphinxMatchInfo::getFieldByName(const std::string& attrName) const
126 {
127  AttrInfo attrInfo;
128  for (size_t i=0;i<attributes.size();++i)
129  {
130  if (attributes[i].getItem().name == attrName)
131  {
132  attrInfo = attributes[i].getItem();
133  break;
134  }
135  }
136  return attrInfo;
137 }
138 //-------------------------------------------------------------------
140 {
141  size_t count = attributes.size();
142  for (size_t i=0;i<count;++i)
143  {
144  if (attributes[i].isEmpty())
145  {
146  count = i;
147  break;
148  }
149  }
150  return count;
151 }
152 //-------------------------------------------------------------------
154 {
155  return attributes[index].getItem();
156 }
157 //-------------------------------------------------------------------
158 void SphinxMatchInfo::setAttrItem(size_t index, const AttrInfo& attr)
159 {
160  attributes[index].setItem(attr);
161 }
162 //-------------------------------------------------------------------
164 {
165  attributes[index].setItem(std::forward<AttrInfo>(attr));
166 }
167 //-------------------------------------------------------------------
169 {
170  docId = 0;
171  weight.clear();
172  attributes.clear();
173 }
174 //-------------------------------------------------------------------
176 {
177  docId = 0;
178  weight.clear();
179  const size_t count = attributes.size();
180  for (size_t i=0;i<count;++i)
181  attributes[i].isEmpty(true);
182 }
183 //-------------------------------------------------------------------
184 void SphinxMatchInfo::resize(size_t sz)
185 {
186  attributes.resize(sz);
187  reset();
188 }
189 //-------------------------------------------------------------------
190 //-------------------------------------------------------------------
191 } // namespace sphinx
192 } // namespace HCE