LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
genericDocumentProperties.cpp
Go to the documentation of this file.
1// Copyright 2002-2022 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 *
8 * @file documentProperties.cpp
9 * @author Besancon Romaric (besanconr@zoe.cea.fr)
10 * @date Fri Oct 10 2003
11 * @version $Id$
12 * copyright Copyright (C) 2003-2012 by CEA LIST
13 *
14 ***********************************************************************/
15
17#include "strwstrtools.h"
18
19#include <QtCore/QDate>
20
21#include <iostream>
22#include <fstream>
23#include <algorithm>
24
25using namespace std;
26
27namespace Lima {
28namespace Common {
29namespace Misc {
30
32{
34
38
39 std::map<std::string,uint64_t> m_intValues;
40 std::map<std::string,std::string> m_stringValues;
41 std::map<std::string,QDate> m_dateValues;
42 std::map<std::string,std::pair<QDate,QDate> > m_dateIntervalValues;
43 // properties with several values
44 std::map<std::string,std::vector<std::string> > m_multipleStringValues;
45 std::map<std::string,std::vector<std::pair<std::string,float> > > m_multipleWeightedPropValues;
46
47 QDate readDate(std::istream& file);
48 void writeDate(std::ostream& file,const QDate& d) const;
49 std::vector<std::string> m_noStringVal;
50 std::vector<std::pair<std::string,float> > m_noWeightedPropVal;
51};
52
53GenericDocumentPropertiesPrivate::GenericDocumentPropertiesPrivate(){
54}
55
56GenericDocumentPropertiesPrivate::GenericDocumentPropertiesPrivate(const GenericDocumentPropertiesPrivate& p):
57m_intValues(p.m_intValues),
58m_stringValues(p.m_stringValues),
59m_dateValues(p.m_dateValues),
60m_dateIntervalValues(p.m_dateIntervalValues),
61m_multipleStringValues(p.m_multipleStringValues),
62m_multipleWeightedPropValues(p.m_multipleWeightedPropValues)
63{
64}
65
66//***********************************************************************
67// destructor
68//***********************************************************************
69GenericDocumentPropertiesPrivate::~GenericDocumentPropertiesPrivate() {
70}
71
72
73//***********************************************************************
74// constructors
75//***********************************************************************
80
85
86//***********************************************************************
87// destructor
88//***********************************************************************
93
94//***********************************************************************
95// assignment operator
96//***********************************************************************
98 if (&p != this) {
99 m_d->m_intValues=p.m_d->m_intValues;
100 m_d->m_stringValues=p.m_d->m_stringValues;
101 m_d->m_dateValues=p.m_d->m_dateValues;
102 m_d->m_dateIntervalValues=p.m_d->m_dateIntervalValues;
103 m_d->m_multipleStringValues=p.m_d->m_multipleStringValues;
104 m_d->m_multipleWeightedPropValues=p.m_d->m_multipleWeightedPropValues;
105 }
106 return *this;
107}
108
109void GenericDocumentProperties::setStringValue(const std::string& propName,
110 const std::string& str)
111{
112 m_d->m_stringValues[propName]=str;
113}
114
115void GenericDocumentProperties::setIntValue(const std::string& propName,
116 const uint64_t& val)
117{
118 m_d->m_intValues[propName]=val;
119}
120
121void GenericDocumentProperties::setDateValue(const std::string& propName,
122 const QDate& val)
123{
124 m_d->m_dateValues[propName]=val;
125}
126
127void GenericDocumentProperties::setDateIntervalValue(const std::string& propName,
128 const std::pair<QDate,QDate>& val)
129{
130 m_d->m_dateIntervalValues[propName]=val;
131}
132
133
135 const std::vector<std::string>& val)
136{
137 m_d->m_multipleStringValues[propName]=val;
138}
140 const std::vector<std::pair<std::string,float> >& val)
141{
142 m_d->m_multipleWeightedPropValues[propName]=val;
143}
144
145
146std::pair<uint64_t, bool> GenericDocumentProperties::getIntValue(std::string propName) const
147{
148 auto pos = m_d->m_intValues.find(propName);
149 if( pos == m_d->m_intValues.end() )
150 {
151 return( std::pair<uint64_t, bool>(0,false) );
152 }
153 else
154 {
155 return( std::pair<uint64_t, bool>((*pos).second,true) );
156 }
157}
158
159std::pair<std::string, bool> GenericDocumentProperties::getStringValue(std::string propName) const
160{
161 auto pos = m_d->m_stringValues.find(propName);
162 if( pos == m_d->m_stringValues.end() )
163 {
164 return( std::pair<std::string, bool>("",false) );
165 }
166 else
167 {
168 return( std::pair<std::string, bool>((*pos).second,true) );
169 }
170}
171
172std::pair<QDate, bool> GenericDocumentProperties::getDateValue(std::string propName) const
173{
174 auto pos = m_d->m_dateValues.find(propName);
175 if( pos == m_d->m_dateValues.end() )
176 {
177 return( std::pair<QDate, bool>(QDate(),false) );
178 }
179 else
180 {
181 return( std::pair<QDate, bool>((*pos).second,true) );
182 }
183}
184
185std::pair<std::pair<QDate,QDate>, bool> GenericDocumentProperties::getDateIntervalValue(std::string propName) const
186{
187 auto pos = m_d->m_dateIntervalValues.find(propName);
188 if( pos == m_d->m_dateIntervalValues.end() )
189 {
190 std::pair<QDate,QDate> defaultInterval;
191// (QDate(),QDate());
192 return( std::pair<std::pair<QDate,QDate>, bool>(defaultInterval,false) );
193 }
194 else
195 {
196 return( std::pair<std::pair<QDate,QDate>, bool>((*pos).second,true) );
197 }
198}
199
200std::pair<StringPropMultIter,StringPropMultIter> GenericDocumentProperties::getMultipleStringPropValue(
201 std::string propName) const
202{
203 auto pos = m_d->m_multipleStringValues.find(propName);
204 if( pos == m_d->m_multipleStringValues.end() )
205 {
206 return std::pair<StringPropMultIter, StringPropMultIter>(m_d->m_noStringVal.begin(), m_d->m_noStringVal.end());
207 }
208 else
209 {
210 const auto& val = (*pos).second;
211 return std::pair<StringPropMultIter, StringPropMultIter>(val.begin(),val.end());
212 }
213}
214
215std::pair<WeightedPropMultIter,WeightedPropMultIter> GenericDocumentProperties::getMultipleWeightedPropValue(
216 std::string propName) const
217{
218 auto pos = m_d->m_multipleWeightedPropValues.find(propName);
219 if( pos == m_d->m_multipleWeightedPropValues.end() )
220 {
221 return std::pair<WeightedPropMultIter, WeightedPropMultIter>(m_d->m_noWeightedPropVal.begin(), m_d->m_noWeightedPropVal.end());
222 }
223 else
224 {
225 const std::vector<std::pair<std::string,float> >& val = (*pos).second;
226 return std::pair<WeightedPropMultIter, WeightedPropMultIter>(val.begin(),val.end());
227 }
228}
229
231{
232 auto intProperties = getIntProperties();
233 if (intProperties.first != intProperties.second) return false;
234
235 auto stringProperties = getStringProperties();
236 if (stringProperties.first != stringProperties.second) return false;
237
238 auto dateProperties = getDateProperties();
239 if (dateProperties.first != dateProperties.second) return false;
240
241 auto dateIntervalProperties = getDateIntervalProperties();
242 if (dateIntervalProperties.first != dateIntervalProperties.second) return false;
243
244 auto stringPropertyNames = getStringPropertyNames();
245 if (stringPropertyNames.first != stringPropertyNames.second) return false;
246
247 auto weightedPropPropertyNames = getWeightedPropPropertyNames();
248 if (weightedPropPropertyNames.first != weightedPropPropertyNames.second) return false;
249
250 return true;
251}
252
255{
256 return std::make_pair(m_d->m_intValues.begin(),m_d->m_intValues.end());
257}
258
261{
262 return std::make_pair(m_d->m_stringValues.begin(),m_d->m_stringValues.end());
263}
264
265std::pair<GenericDocumentProperties::DatePropertiesIterator,GenericDocumentProperties::DatePropertiesIterator> GenericDocumentProperties::getDateProperties() const {
266 return std::make_pair(m_d->m_dateValues.begin(),m_d->m_dateValues.end());
267}
268
269std::pair<GenericDocumentProperties::DateIntervalPropertiesIterator,GenericDocumentProperties::DateIntervalPropertiesIterator> GenericDocumentProperties::getDateIntervalProperties() const {
270 return std::make_pair(m_d->m_dateIntervalValues.begin(),m_d->m_dateIntervalValues.end());
271}
272
273
274std::pair<MultiValuedPropertyIterator<std::string>,MultiValuedPropertyIterator<std::string> > GenericDocumentProperties::getStringPropertyNames() const {
275 return std::make_pair(
276 MultiValuedPropertyIterator<std::string>(m_d->m_multipleStringValues.begin()),
277 MultiValuedPropertyIterator<std::string>(m_d->m_multipleStringValues.end()) );
278}
279
280 std::pair<MultiValuedPropertyIterator<std::pair<std::string,float> >,
282 return std::make_pair(
283 MultiValuedPropertyIterator<std::pair<std::string,float> >(m_d->m_multipleWeightedPropValues.begin()),
284 MultiValuedPropertyIterator<std::pair<std::string,float> >(m_d->m_multipleWeightedPropValues.end()) );
285}
286
287void GenericDocumentProperties::addStringValue(const std::string& propName,
288 const std::string& val)
289{
290 std::map<std::string,std::vector<std::string> >::iterator pos = m_d->m_multipleStringValues.find(propName);
291 if( pos == m_d->m_multipleStringValues.end() ) {
292 std::vector<std::string> values;
293 values.push_back(val);
294 m_d->m_multipleStringValues.insert(std::pair<std::string,std::vector<std::string> >(propName,values) );
295 }
296 else {
297 std::vector<std::string>& values = (*pos).second;
298 auto iter = std::find(values.begin(), values.end(), val);
299 if (iter == values.end()){
300 values.push_back(val);
301 }
302 // else avoid duplicate entries: Do not append
303 }
304}
305
306
307bool mypredicate(const std::pair<std::string,float>& a, const std::pair<std::string,float>& b){
308 return a.first == b.first;
309}
310
311void GenericDocumentProperties::addWeightedPropValue(const std::string& propName,
312 const std::pair<std::string,float>& val)
313{
314 std::map<std::string,std::vector<std::pair<std::string,float> > >::iterator pos = m_d->m_multipleWeightedPropValues.find(propName);
315 if( pos == m_d->m_multipleWeightedPropValues.end() ) {
316 std::vector<std::pair<std::string,float> > values;
317 values.push_back(val);
318 m_d->m_multipleWeightedPropValues.insert(std::pair<std::string,std::vector<std::pair<std::string,float> > >(propName,values) );
319 }
320 else {
321 std::vector<std::pair<std::string,float> >& values = (*pos).second;
322
323 const std::pair<std::string,float> needle [1] = { val };
324 auto iter = std::search(values.begin(), values.end(), needle, needle+1, mypredicate);
325 if (iter == values.end()){
326 values.push_back(val);
327 }
328 else // else avoid duplicate entries: Do not append, but overwrite the associated weight
329 {
330 iter->second = val.second;
331 }
332
333 }
334}
335
336
337//***********************************************************************
338// binary read/write functions
339//***********************************************************************
341 m_d->m_intValues.clear();
342 m_d->m_stringValues.clear();
343 m_d->m_dateValues.clear();
344 m_d->m_dateIntervalValues.clear();
345 m_d->m_multipleStringValues.clear();
346 m_d->m_multipleWeightedPropValues.clear();
347}
348
349
350//***********************************************************************
351// binary read/write functions
352//***********************************************************************
353QDate GenericDocumentPropertiesPrivate::readDate(std::istream& file) {
354 // read date as three unsigned short if defined
355 bool isADate(true);
356 file.read((char*) &isADate, sizeof(bool));
357 if (isADate) {
358 unsigned short day(0);
359 unsigned short month(0);
360 unsigned short year(0);
361 file.read((char*) &day, sizeof(unsigned short));
362 file.read((char*) &month, sizeof(unsigned short));
363 file.read((char*) &year, sizeof(unsigned short));
364 return QDate(year,month,day);
365 }
366 else {
367 return QDate();
368 }
369}
370
371void GenericDocumentPropertiesPrivate::writeDate(std::ostream& file,
372 const QDate& d) const {
373 // write date as three unsigned short if defined
374 if (!d.isValid()) {
375 bool isADate(false);
376 file.write((char*) &isADate, sizeof(bool));
377 }
378 else {
379 bool isADate(true);
380 file.write((char*) &isADate, sizeof(bool));
381 unsigned short day=d.day();
382 unsigned short month=d.month();
383 unsigned short year=d.year();
384 file.write((char*) &day, sizeof(unsigned short));
385 file.write((char*) &month, sizeof(unsigned short));
386 file.write((char*) &year, sizeof(unsigned short));
387 }
388}
389
390void GenericDocumentProperties::read(std::istream& file) {
391 uint32_t size(0);
392
393 // clean structures
394 m_d->m_intValues.clear();
395 m_d->m_stringValues.clear();
396 m_d->m_dateValues.clear();
397 m_d->m_dateIntervalValues.clear();
398 m_d->m_multipleStringValues.clear();
399 m_d->m_multipleWeightedPropValues.clear();
400
401#ifdef DEBUG_CD
403 LDEBUG << "GenericDocumentProperties::read()";
404#endif
405 // read integer properties
406 file.read((char*) &size, sizeof(uint32_t));
407#ifdef DEBUG_CD
408 LDEBUG << "read" << size << "int properties";
409#endif
410 for (uint32_t i(0); i<size; i++) {
411 string name;
412 Misc::readStringField(file,name);
413 uint64_t val;
414 file.read((char*) &val, sizeof(uint64_t));
415#ifdef DEBUG_CD
416 LDEBUG << "read int '" << val << "' as value of " << name.c_str();
417#endif
418 m_d->m_intValues.insert(std::pair<std::string,uint64_t>(name,val));
419 }
420
421 // read string properties
422 file.read((char*) &size, sizeof(uint32_t));
423#ifdef DEBUG_CD
424 LDEBUG << "read" << size << "string properties";
425#endif
426 for (uint32_t i(0); i<size; i++) {
427 string name;
428 Misc::readStringField(file,name);
429 string str;
430 Misc::readStringField(file,str);
431#ifdef DEBUG_CD
432 LDEBUG << "read string '" << str.c_str() << "' as value of " << name.c_str();
433#endif
434 m_d->m_stringValues.insert(std::pair<std::string,std::string>(name,str) );
435 }
436
437 // read date properties
438 file.read((char*) &size, sizeof(uint32_t));
439#ifdef DEBUG_CD
440 LDEBUG << "read" << size << "date properties";
441#endif
442 for (uint32_t i(0); i<size; i++) {
443 string name;
444 Misc::readStringField(file,name);
445 QDate d=m_d->readDate(file);
446 string strDate=d.toString().toUtf8().data();
447#ifdef DEBUG_CD
448 LDEBUG << "read date '" << strDate.c_str() << "' as value of " << name.c_str();
449#endif
450 m_d->m_dateValues.insert(std::pair<std::string,QDate>(name,d));
451 }
452
453 // read date interval properties
454 file.read((char*) &size, sizeof(uint32_t));
455#ifdef DEBUG_CD
456 LDEBUG << "read" << size << "date-interval properties";
457#endif
458 for (uint32_t i(0); i<size; i++) {
459 string name;
460 Misc::readStringField(file,name);
461 QDate startD=m_d->readDate(file);
462 QDate endD=m_d->readDate(file);
463 string strStartDate=startD.toString().toUtf8().data();
464 string strEndDate=endD.toString().toUtf8().data();
465#ifdef DEBUG_CD
466 LDEBUG << "read date-interval [" << strStartDate.c_str() << "," << strEndDate.c_str() << "] as value of " << name.c_str();
467#endif
468 std::pair<QDate,QDate> interval(startD,endD);
469 m_d->m_dateIntervalValues.insert(std::pair<std::string,std::pair<QDate,QDate> >(name,interval));
470 }
471
472 // read multi-valued string properties
473 file.read((char*) &size, sizeof(uint32_t));
474#ifdef DEBUG_CD
475 LDEBUG << "read" << size << "multi-valued properties";
476#endif
477 for (uint32_t i(0); i<size; i++) {
478 string name;
479 Misc::readStringField(file,name);
480 uint32_t sizeMultipleValues(0);
481 file.read((char*) &sizeMultipleValues, sizeof(uint32_t));
482 vector<string> val;
483 for (uint32_t j(0); j<sizeMultipleValues; j++) {
484 string str;
485 Misc::readStringField(file,str);
486#ifdef DEBUG_CD
487 LDEBUG << "read string '" << str.c_str() <<"' as "<<j<<"/"<<sizeMultipleValues<< " value of" << name.c_str();
488#endif
489 val.push_back(str);
490 }
491 m_d->m_multipleStringValues.insert(std::pair<std::string,std::vector<std::string> >(name,val) );
492 }
493
494 // read multi-valued weighted properties
495 file.read((char*) &size, sizeof(uint32_t));
496// LDEBUG << "read size " << size;
497 for (uint32_t i(0); i<size; i++) {
498 string name;
499 Misc::readStringField(file,name);
500 uint32_t sizeMultipleValues(0);
501 file.read((char*) &sizeMultipleValues, sizeof(uint32_t));
502 vector<std::pair<std::string,float> > val;
503 for (uint32_t j(0); j<sizeMultipleValues; j++) {
504 string str;
505 Misc::readStringField(file,str);
506 float weight;
507 file.read((char*) &weight, sizeof(float));
508 val.push_back(std::pair<std::string,float>(str,weight) );
509#ifdef DEBUG_CD
510 LDEBUG << "read weighted-string '" << str.c_str() <<":"<<weight<<"' as "<<j<<"/"<<sizeMultipleValues<< " value of" << name.c_str();
511#endif
512 }
513 m_d->m_multipleWeightedPropValues.insert(std::pair<std::string,vector<std::pair<std::string,float> > > (name,val) );
514 }
515
516#ifdef DEBUG_CD
517 LDEBUG << "end of properties";
518#endif
519}
520
521void GenericDocumentProperties::write(std::ostream& file) const {
522 std::map <std::string, uint64_t >::size_type size(0);
523
524#ifdef DEBUG_CD
526 LDEBUG << "GenericDocumentProperties::write()";
527#endif
528
529 // Write integer properties
530 size=m_d->m_intValues.size();
531#ifdef DEBUG_CD
532 LDEBUG << "write" << size << "int properties";
533#endif
534 file.write((char*) &size, sizeof(uint32_t));
535 for (std::map<std::string,uint64_t>::const_iterator it = m_d->m_intValues.begin() ;
536 it != m_d->m_intValues.end() ; it++) {
537 Misc::writeStringField(file,(*it).first);
538#ifdef DEBUG_CD
539 LDEBUG << "write int name" << (*it).first.c_str() << "value" << (*it).second;
540#endif
541 file.write((char*) &((*it).second), sizeof(uint64_t));
542 }
543// Misc::writeStringField(file,"eoi");
544
545 // Write string properties
546 size=m_d->m_stringValues.size();
547#ifdef DEBUG_CD
548 LDEBUG << "write" << size << "string properties";
549#endif
550 file.write((char*) &size, sizeof(uint32_t));
551 for (std::map<std::string,std::string>::const_iterator it = m_d->m_stringValues.begin() ;
552 it != m_d->m_stringValues.end() ; it++) {
553 Misc::writeStringField(file,(*it).first);
554#ifdef DEBUG_CD
555 LDEBUG << "write string name" << (*it).first.c_str() << "value" << (*it).second;
556#endif
557 Misc::writeStringField(file,(*it).second);
558 }
559// Misc::writeStringField(file,"eos");
560
561 // Write date properties
562 size=m_d->m_dateValues.size();
563#ifdef DEBUG_CD
564 LDEBUG << "write" << size << "date properties";
565#endif
566 file.write((char*) &size, sizeof(uint32_t));
567 for (std::map<std::string,QDate>::const_iterator it = m_d->m_dateValues.begin() ;
568 it != m_d->m_dateValues.end() ; it++) {
569 Misc::writeStringField(file,(*it).first);
570 //string strDate=(*it).second.toString().toUtf8().data();
571#ifdef DEBUG_CD
572 LDEBUG << "write date name" << (*it).first.c_str() << "value" << (*it).second;
573#endif
574 m_d->writeDate(file,(*it).second);
575 }
576// Misc::writeStringField(file,"eod");
577
578 // Write date interval properties
579 size=m_d->m_dateIntervalValues.size();
580#ifdef DEBUG_CD
581 LDEBUG << "write" << size << "date-interval properties";
582#endif
583 file.write((char*) &size, sizeof(uint32_t));
584 for (std::map<std::string,std::pair<QDate,QDate> >::const_iterator it
585 = m_d->m_dateIntervalValues.begin() ; it != m_d->m_dateIntervalValues.end() ; it++) {
586 const std::pair<std::string,std::pair<QDate,QDate> >&val=*it;
587 Misc::writeStringField(file,val.first);
588 //string strStartDate=(val.second).first.toString().toUtf8().data();
589 //string strEndDate=(val.second).second.toString().toUtf8().data();
590#ifdef DEBUG_CD
591 LDEBUG << "write date-interval name [" << (val.second).first << "," << (val.second).second << "]";
592#endif
593 m_d->writeDate(file,(val.second).first);
594 m_d->writeDate(file,(val.second).second);
595 }
596
597 // Write multiple string properties
598 size=m_d->m_multipleStringValues.size();
599#ifdef DEBUG_CD
600 LDEBUG << "write" << size << "multi-valued properties";
601#endif
602 file.write((char*) &size, sizeof(uint32_t));
603 for (std::map<std::string,std::vector<std::string> >::const_iterator it = m_d->m_multipleStringValues.begin() ;
604 it != m_d->m_multipleStringValues.end() ; it++) {
605#ifdef DEBUG_CD
606 LDEBUG << "write multi-valued name" << (*it).first.c_str();;
607#endif
608 Misc::writeStringField(file,(*it).first);
609 const std::vector<std::string>& vval = (*it).second;
610 std::vector<std::string >::size_type sizeMultipleValues=vval.size();
611 file.write((char*) &sizeMultipleValues, sizeof(uint32_t));
612 for( std::vector<std::string>::const_iterator vit = vval.begin() ;
613 vit != vval.end() ; vit++ ) {
614 Misc::writeStringField(file,*vit);
615 }
616 }
617// Misc::writeStringField(file,"eoss");
618
619 // Write multiple weighted properties
620 size=m_d->m_multipleWeightedPropValues.size();
621#ifdef DEBUG_CD
622 LDEBUG << "write" << size << "weighted multi-valued properties";
623#endif
624 file.write((char*) &size, sizeof(uint32_t));
625 for (std::map<std::string,std::vector<std::pair<std::string,float> > >::const_iterator it =
626 m_d->m_multipleWeightedPropValues.begin() ;
627 it != m_d->m_multipleWeightedPropValues.end() ; it++) {
628// LDEBUG << "write name " << (*it).first.c_str();
629 Misc::writeStringField(file,(*it).first);
630 const std::vector<std::pair<std::string,float> >& vval = (*it).second;
631 std::vector<std::pair <std::string, float > >::size_type sizeMultipleValues=vval.size();
632 file.write((char*) &sizeMultipleValues, sizeof(uint32_t));
633 for( std::vector<std::pair<std::string,float> >::const_iterator vit = vval.begin() ;
634 vit != vval.end() ; vit++ ) {
635 Misc::writeStringField(file,(*vit).first);
636 file.write((char*) &((*vit).second), sizeof(float));
637 }
638 }
639
640#ifdef DEBUG_CD
641 LDEBUG << "end of properties";
642#endif
643}
644
645//***********************************************************************
646// output
647//***********************************************************************
648std::ostream& operator << (std::ostream& os, const GenericDocumentProperties& p) {
649 p.print(os);
650 return os;
651}
652
653QDebug& operator << (QDebug& os, const GenericDocumentProperties& p) {
654 p.print(os);
655 return os;
656}
657
658QTextStream& operator << (QTextStream& os, const GenericDocumentProperties& p) {
659 p.print(os);
660 return os;
661}
662
663void GenericDocumentProperties::print(std::ostream& os) const {
664
665 // intValues
666 for (std::map<std::string, uint64_t>::const_iterator it =
667 m_d->m_intValues.begin (); it != m_d->m_intValues.end (); it++)
668 {
669 os << (*it).first << "=" << (*it).second;
670 if(it != m_d->m_intValues.end ()) os << ";";
671 }
672 // stringValues
673 for (std::map<std::string, std::string>::const_iterator it =
674 m_d->m_stringValues.begin (); it != m_d->m_stringValues.end ();
675 it++)
676 {
677 os << (*it).first << "=" << (*it).second;
678 if(it != m_d->m_stringValues.end ()) os << ";";
679 }
680 // dateValues
681 for (std::map<std::string, QDate>::const_iterator it =
682 m_d->m_dateValues.begin (); it != m_d->m_dateValues.end (); it++)
683 {
684 os << (*it).first << "="
685 << (*it).second.toString (Qt::ISODate).toStdString();
686 if(it != m_d->m_dateValues.end ()) os << ";";
687 }
688 // dateIntervalValues
689 for (std::map<std::string, std::pair<QDate, QDate> >::const_iterator it =
690 m_d->m_dateIntervalValues.begin ();
691 it != m_d->m_dateIntervalValues.end (); it++)
692 {
693 os << (*it).first << "=["
694 << ((*it).second).first.toString (Qt::ISODate).toStdString() << ","
695 << ((*it).second).second.toString(Qt::ISODate).toStdString() << "]";
696 if(it != m_d->m_dateIntervalValues.end ()) os << ";";
697 }
698 // multipleStringValues
699 for (std::map<std::string, std::vector<std::string> >::const_iterator it =
700 m_d->m_multipleStringValues.begin ();
701 it != m_d->m_multipleStringValues.end (); it++)
702 {
703 os << (*it).first << "=[";
704 const std::vector<std::string>& vval = (*it).second;
705 if (!vval.empty ())
706 {
707 std::vector<std::string>::const_iterator vit = vval.begin();
708 os << *vit;
709 vit++;
710 for (; vit != vval.end (); vit++)
711 {
712 os << "," << *vit;
713 }
714 }
715 os << "]";
716 if(it != m_d->m_multipleStringValues.end ()) os << ";";
717 }
718 // multipleWeightedPropValues
719 for (std::map<std::string, std::vector<std::pair<std::string, float> > >::const_iterator it =
720 m_d->m_multipleWeightedPropValues.begin ();
721 it != m_d->m_multipleWeightedPropValues.end (); it++)
722 {
723 os << (*it).first << "=";
724 const std::vector<std::pair<std::string, float> >& vval =
725 (*it).second;
726 if (!vval.empty ())
727 {
728 std::vector<std::pair<std::string, float> >::const_iterator vit =
729 vval.begin ();
730 os << "(" << (*vit).first << "," << (*vit).second << ")";
731 vit++;
732 for (; vit != vval.end (); vit++)
733 {
734 os << ", (" << (*vit).first << "," << (*vit).second << ")";
735 }
736 }
737 if(it != m_d->m_multipleWeightedPropValues.end ()) os << ";";
738 }
739}
740
741void GenericDocumentProperties::print (QTextStream& qts) const
742{
743 std::ostringstream oss;
744 this->print(oss);
745 qts << QString::fromStdString(oss.str());
746}
747
748
749void GenericDocumentProperties::print (QDebug& qts) const
750{
751 std::ostringstream oss;
752 this->print(oss);
753 qts << QString::fromStdString(oss.str());
754}
755
756
757} // end namespace Misc
758} // end namespace Common
759} // end namespace Lima
#define LDEBUG
Definition LimaCommon.h:157
#define BOWLOGINIT
Definition LimaCommon.h:201
std::pair< uint64_t, bool > getIntValue(std::string propName) const
Read access functions for "only once valued" property propName.
std::pair< QDate, bool > getDateValue(std::string propName) const
std::pair< DateIntervalPropertiesIterator, DateIntervalPropertiesIterator > getDateIntervalProperties() const
std::pair< StringPropMultIter, StringPropMultIter > getMultipleStringPropValue(std::string propName) const
Read access functions for "multiple-valued" property propName Return a pair of iterator (begin,...
void addWeightedPropValue(const std::string &propName, const std::pair< std::string, float > &str)
std::pair< DatePropertiesIterator, DatePropertiesIterator > getDateProperties() const
std::pair< MultiValuedPropertyIterator< std::pair< std::string, float > >, MultiValuedPropertyIterator< std::pair< std::string, float > > > getWeightedPropPropertyNames() const
std::pair< MultiValuedPropertyIterator< std::string >, MultiValuedPropertyIterator< std::string > > getStringPropertyNames() const
Read access functions for all "multiple valued" properties return an iterator of names Types may be a...
std::pair< IntPropertiesIterator, IntPropertiesIterator > getIntProperties() const
std::pair< std::pair< QDate, QDate >, bool > getDateIntervalValue(std::string propName) const
std::pair< std::string, bool > getStringValue(std::string propName) const
void setStringValue(const std::string &propName, const std::string &val)
std::map< std::string, std::string >::const_iterator StringPropertiesIterator
void addStringValue(const std::string &propName, const std::string &str)
void setDateIntervalValue(const std::string &propName, const std::pair< QDate, QDate > &val)
void setMultipleStringPropValue(const std::string &propName, const std::vector< std::string > &val)
GenericDocumentProperties & operator=(const GenericDocumentProperties &)
void setDateValue(const std::string &propName, const QDate &val)
void setMultipleWeightedPropValue(const std::string &propName, const std::vector< std::pair< std::string, float > > &val)
std::pair< StringPropertiesIterator, StringPropertiesIterator > getStringProperties() const
std::pair< WeightedPropMultIter, WeightedPropMultIter > getMultipleWeightedPropValue(std::string propName) const
void setIntValue(const std::string &propName, const uint64_t &val)
std::map< std::string, uint64_t >::const_iterator IntPropertiesIterator
Read access functions for all "only once valued" properties return an iterator Types may be any of (u...
void readStringField(istream &file, string &s)
void writeStringField(ostream &file, const string &s)
std::ostream & operator<<(std::ostream &os, const GenericDocumentProperties &p)
bool mypredicate(const std::pair< std::string, float > &a, const std::pair< std::string, float > &b)
NAUTITIA.
STL namespace.