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";
142 LDEBUG << properties.size() <<
" properties read from xmlfile ";
144 for (
auto desc = properties.cbegin();
145 desc != properties.cend();
150 LDEBUG <<
"compute data for property " << desc->name;
152 std::vector<std::string>::size_type nbvalues=desc->values.size() + 1;
153 auto nbBits = m_d->computeNbBitsNeeded(nbvalues);
155 LDEBUG << nbvalues <<
" values so use " << nbBits <<
" bits";
163 std::map<std::string,LinguisticCode> symbol2code;
164 symbol2code[
"NONE"] =
L_NONE;
166 for (
auto valItr = desc->values.cbegin();
167 valItr != desc->values.cend();
171 symbol2code.insert(std::make_pair(*valItr, new_code));
180 std::runtime_error(
"Error: using more than the number of bits available.");
182 m_d->m_propertyManagers.insert(
183 std::make_pair(desc->name,
189 LDEBUG << subproperties.size() <<
" subproperties read from file";
191 for (
const auto& desc: subproperties)
194 LDEBUG <<
"compute data for subproperty " << desc.name <<
"of" << desc.parentName;
199 const auto& subvalues = desc.values;
203 uint64_t maxsubvalues=0;
204 for (
auto it=subvalues.cbegin();
205 it!=subvalues.cend();
208 if (it->second.size()+1>maxsubvalues)
210 maxsubvalues=it->second.size()+1;
213 auto nbBits = m_d->computeNbBitsNeeded(maxsubvalues);
215 LDEBUG <<
"maximum subvalues is " << maxsubvalues <<
" so use "
216 << nbBits <<
" bits";
226 std::map<std::string,LinguisticCode> symbol2code;
227 symbol2code[
"NONE"] =
L_NONE;
228 for (
const auto& subvalue: subvalues)
230 LinguisticCode parentValue=parentProp.getPropertyValue(subvalue.first);
232 LDEBUG <<
"value of" << subvalue.first <<
"is" << parentValue;
234 if (parentValue ==
L_NONE)
236 LERROR <<
"parent value " << subvalue.first <<
" of subproperty "
237 << desc.name <<
" is unknown !";
240 LDEBUG <<
"compute subvalues of " << subvalue.first <<
" ("
243 symbol2code.insert(std::make_pair(
string(subvalue.first)+
"-NONE",
246 for (
const auto& value: subvalue.second)
250 LDEBUG << value <<
" => " << symbol2code[value].toHexString();
255 m_d->m_propertyManagers.insert(std::make_pair(desc.name,
265 LDEBUG <<
"have used " << usedBits <<
" bits to code all properties";
269 LERROR <<
"needs" << usedBits
270 <<
"bits to code all properties !! Encoding may be Invalid !!";
271 throw std::runtime_error(
272 "Needs too much bits to code all properties !! Encoding would be Invalid !!");
278 const std::string& propertyName)
const
280 auto it =m_d->m_propertyManagers.find(propertyName);
281 if (it == m_d->m_propertyManagers.end())
284 LERROR <<
"Ask for unknown property accessor:" << propertyName;
291 const std::set<std::string>& propertyNames)
const
294 std::copy(propertyNames.begin(), propertyNames.end(),
295 std::ostream_iterator<string>(os,
":"));
298 LDEBUG <<
"create propertysetAccessor for " << os.str();
302 for (
auto propItr = propertyNames.cbegin();
303 propItr != propertyNames.cend();
307 propertySetMask |= man.getMask();
308 propertySetEmptyNessMask |= man.getEmptyNessMask();
312 LDEBUG <<
"propertysetEmptyNessMask is "
315 return std::shared_ptr<PropertyAccessor>(
318 propertySetEmptyNessMask));
324 for (uint64_t tmp=2; tmp < nbvalues; tmp*=2)
331 LERROR <<
"Error: nb bits needed ("<<nbBits<<
") is larger than sizeof LinguisticCode="
333 throw std::runtime_error(
334 "Error: nb bits needed is larger than sizeof LinguisticCode");
345 LERROR <<
"Error: cannot compute mask. Would use more bits ("
346 << (startBit + nbBits) <<
") than available ("
348 throw std::runtime_error(
"Error: cannot compute mask. Would use more bits than available");
351 for (
size_t currentBit = startBit;
352 currentBit < startBit + nbBits;
361 std::string>& propValues)
const
370 for (
auto it = propValues.cbegin(); it != propValues.cend(); it++)
373 man.getPropertyAccessor().writeValue(man.getPropertyValue(it->second),coded);
375 LDEBUG << it->first <<
" : " << it->second <<
" coded = " << coded.
toHexString();
382 const std::string& symbolicCodeFile,
383 std::map<std::string,LinguisticCode>& conversionTable)
const
387 LDEBUG <<
"convert Symbolic Code file " << symbolicCodeFile;
395 QFile file(symbolicCodeFile.c_str());
396 if (!file.open(QIODevice::ReadOnly))
399 LERROR <<
"An error occurred Error: Cannot open " << symbolicCodeFile ;
400 throw std::runtime_error(
401 std::string(
"PropertyCodeManager::convertSymbolicCodes Unable to open ")
404 if (!reader.
parse(&file))
407 LERROR <<
"PropertyCodeManager::convertSymbolicCodes An error occurred parsing"
412 std::string(
"Error while parsing " + symbolicCodeFile +
" : "
419 return m_d->m_propertyManagers;
423 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
LinguisticCode computeMask(size_t startBit, size_t nbBits) const
The mask of a property is an integer that show which bits are used.
friend class PropertyCodeManager
std::map< std::string, PropertyManager > m_propertyManagers
~PropertyCodeManagerPrivate()=default
size_t computeNbBitsNeeded(uint64_t nbvalues) const
Compute the number of bit needed to encode nbvalues.
PropertyCodeManagerPrivate(const PropertyCodeManagerPrivate &)=delete
PropertyCodeManagerPrivate & operator=(const PropertyCodeManagerPrivate &)=delete
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.
friend class PropertyCodeManagerPrivate
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)