93 m_d->m_propertyManagers = pcm.m_d->m_propertyManagers;
98 m_d->m_propertyManagers = pcm.m_d->m_propertyManagers;
106 LDEBUG <<
typeid(*this).name() <<
"PropertyCodeManager::readFromXmlFile" << filename;
110 LDEBUG <<
typeid(*this).name() <<
"PropertyCodeManager::readFromXmlFile before creating parser";
118 LDEBUG <<
"PropertyCodeManager::readFromXmlFile before parsing";
120 QFile file(filename.c_str());
121 if (!file.open(QIODevice::ReadOnly))
123 LIMA_EXCEPTION(
"PropertyCodeManager::readFromXmlFile Unable to open "
124 << filename.c_str());
126 if (!reader.
parse(&file))
133 LDEBUG <<
"PropertyCodeManager::readFromXmlFile parsed. before deleting parser";
141 LDEBUG << properties.size() <<
" properties read from xmlfile ";
143 for (
auto desc = properties.cbegin();
144 desc != properties.cend();
149 LDEBUG <<
"compute data for property " << desc->name;
151 std::vector<std::string>::size_type nbvalues=desc->values.size() + 1;
152 uint8_t nbBits = m_d->computeNbBitsNeeded(nbvalues);
154 LDEBUG << nbvalues <<
" values so use " << nbBits <<
" bits";
162 std::map<std::string,LinguisticCode> symbol2code;
163 symbol2code[
"NONE"] =
L_NONE;
165 for (
auto valItr = desc->values.cbegin();
166 valItr != desc->values.cend();
170 symbol2code.insert(std::make_pair(*valItr, new_code));
179 std::runtime_error(
"Error: using more than the number of bits available.");
181 m_d->m_propertyManagers.insert(
182 std::make_pair(desc->name,
188 LDEBUG << subproperties.size() <<
" subproperties read from file";
190 for (
const auto& desc: subproperties)
193 LDEBUG <<
"compute data for subproperty " << desc.name <<
"of" << desc.parentName;
198 const auto& subvalues = desc.values;
202 uint64_t maxsubvalues=0;
203 for (
auto it=subvalues.cbegin();
204 it!=subvalues.cend();
207 if (it->second.size()+1>maxsubvalues)
209 maxsubvalues=it->second.
size()+1;
212 auto nbBits = m_d->computeNbBitsNeeded(maxsubvalues);
214 LDEBUG <<
"maximum subvalues is " << maxsubvalues <<
" so use "
215 << nbBits <<
" bits";
225 std::map<std::string,LinguisticCode> symbol2code;
226 symbol2code[
"NONE"] =
L_NONE;
227 for (
const auto& subvalue: subvalues)
229 LinguisticCode parentValue=parentProp.getPropertyValue(subvalue.first);
231 LDEBUG <<
"value of" << subvalue.first <<
"is" << parentValue;
233 if (parentValue ==
L_NONE)
235 LERROR <<
"parent value " << subvalue.first <<
" of subproperty "
236 << desc.name <<
" is unknown !";
239 LDEBUG <<
"compute subvalues of " << subvalue.first <<
" ("
242 symbol2code.insert(std::make_pair(
string(subvalue.first)+
"-NONE",
245 for (
const auto& value: subvalue.second)
249 LDEBUG << value <<
" => " << symbol2code[value].toHexString();
254 m_d->m_propertyManagers.insert(std::make_pair(desc.name,
264 LDEBUG <<
"have used " << usedBits <<
" bits to code all properties";
268 LERROR <<
"needs" << usedBits
269 <<
"bits to code all properties !! Encoding may be Invalid !!";
270 throw std::runtime_error(
271 "Needs too much bits to code all properties !! Encoding would be Invalid !!");
277 const std::string& propertyName)
const
279 auto it =m_d->m_propertyManagers.find(propertyName);
280 if (it == m_d->m_propertyManagers.end())
283 LERROR <<
"Ask for unknown property accessor:" << propertyName;
290 const std::set<std::string>& propertyNames)
const
293 std::copy(propertyNames.begin(), propertyNames.end(),
294 std::ostream_iterator<string>(os,
":"));
297 LDEBUG <<
"create propertysetAccessor for " << os.str();
301 for (
auto propItr = propertyNames.cbegin();
302 propItr != propertyNames.cend();
306 propertySetMask |= man.getMask();
307 propertySetEmptyNessMask |= man.getEmptyNessMask();
311 LDEBUG <<
"propertysetEmptyNessMask is "
314 return std::shared_ptr<PropertyAccessor>(
317 propertySetEmptyNessMask));
323 for (uint64_t tmp=2; tmp < nbvalues; tmp*=2)
330 LERROR <<
"Error: nb bits needed ("<<nbBits<<
") is larger than sizeof LinguisticCode="
332 throw std::runtime_error(
333 "Error: nb bits needed is larger than sizeof LinguisticCode");
339 uint8_t nbBits)
const
344 LERROR <<
"Error: cannot compute mask. Would use more bits ("
345 << (startBit + nbBits) <<
") than available ("
347 throw std::runtime_error(
"Error: cannot compute mask. Would use more bits than available");
350 for (uint8_t currentBit = startBit;
351 currentBit < startBit + nbBits;
360 std::string>& propValues)
const
369 for (
auto it = propValues.cbegin(); it != propValues.cend(); it++)
372 man.getPropertyAccessor().writeValue(man.getPropertyValue(it->second),coded);
374 LDEBUG << it->first <<
" : " << it->second <<
" coded = " << coded.
toHexString();
381 const std::string& symbolicCodeFile,
382 std::map<std::string,LinguisticCode>& conversionTable)
const
386 LDEBUG <<
"convert Symbolic Code file " << symbolicCodeFile;
394 QFile file(symbolicCodeFile.c_str());
395 if (!file.open(QIODevice::ReadOnly))
398 LERROR <<
"An error occurred Error: Cannot open " << symbolicCodeFile ;
399 throw std::runtime_error(
400 std::string(
"PropertyCodeManager::convertSymbolicCodes Unable to open ")
403 if (!reader.
parse(&file))
406 LERROR <<
"PropertyCodeManager::convertSymbolicCodes An error occurred parsing"
411 std::string(
"Error while parsing " + symbolicCodeFile +
" : "
418 return m_d->m_propertyManagers;
422 const std::string& propertyName)
const
#define LIMA_EXCEPTION(X)
This macro writes the message X to a previously configured error stream before throwing a LimaExcepti...
#define PROPERTYCODELOGINIT
#define LIMA_EXCEPTION_SELECT(X, Y)
This macro writes the message X to a previously configured error stream before throwing a Y exception...
Provide function to read write and check a property.
PropertyCodeManagerPrivate()=default
std::map< std::string, PropertyManager > m_propertyManagers
~PropertyCodeManagerPrivate()=default
uint8_t computeNbBitsNeeded(uint64_t nbvalues) const
Compute the number of bit needed to encode nbvalues.
LinguisticCode computeMask(uint8_t startBit, uint8_t nbBits) const
The mask of a property is an integer that show which bits are used.
PropertyCodeManagerPrivate(const PropertyCodeManagerPrivate &)=delete
PropertyCodeManagerPrivate & operator=(const PropertyCodeManagerPrivate &)=delete
Provide tools to parse a property file, and deal with the property coding system.
const std::shared_ptr< PropertyAccessor > getPropertySetAccessor(const std::set< std::string > &propertyNames) const
Get a PropertyAccessor associated to several properties.
void convertSymbolicCodes(const std::string &symbolicCodeFile, std::map< std::string, LinguisticCode > &conversionTable) const
Compute conversion of symbolic codes into linguisticCode and append them into the given map.
const std::map< std::string, PropertyManager > & getPropertyManagers() const
Get the map of all PropertyManagers.
const PropertyManager & getPropertyManager(const std::string &propertyName) const
Get the PropertyManager associated to a property.
void readFromXmlFile(const std::string &filename)
This functions should be called once, just after creation.
PropertyCodeManager()
Default Constructor.
PropertyCodeManager & operator=(const PropertyCodeManager &)
const PropertyAccessor & getPropertyAccessor(const std::string &propertyName) const
Get the PropertyAccessor associated to a property.
LinguisticCode encode(const std::map< std::string, std::string > &propValues) const
Compute the code corresponding to given the properties/values.
Provide tools to manage a specific property.
const PropertyAccessor & getPropertyAccessor() const
give the corresponding PropertyAccessor
const std::vector< PropertyDescription > & getProperties()
bool parse(QIODevice *device)
QString errorString() const
const std::vector< SubPropertyDescription > & getSubProperties()
Use this exception to signal an error in one of the configuration files.
std::string toHexString() const
static std::size_t size() noexcept
static LinguisticCode fromUInt(uint64_t v)
Throw this exception when encountering problems with XML files opening or parsing.
bool parse(QIODevice *device)
QString errorString() const
string hexString(const uint64_t x)