Whiteboard
An interface and tools for visualizing large and complex datasets
mutil.h
Go to the documentation of this file.
1 // Utilities based on an open source library...
2 
3 
4 #ifndef _MUTIL_H_
5 #define _MUTIL_H_
6 
7 
8 #ifdef WIN32
9 #define SOME_GENERIC_WINDOWS
10 #endif
11 
12 
13 #ifdef SOME_GENERIC_WINDOWS
14 #define MDLLEXPORT __declspec (dllexport)
15 #else /* SOME_GENERIC_WINDOWS */
16 #define MDLLEXPORT
17 #endif /* SOME_GENERIC_WINDOWS */
18 
19 #include <string.h>
20 #include <stdio.h>
21 
22 #ifdef SOME_GENERIC_WINDOWS
23 #ifdef MCL_UNICODE_ENABLE
24 #define MCL_USE_UNICODE_IF_DESIRED
25 #endif //MCL_UNICODE
26 #else //SOME_GENERIC_WINDOWS
27 #endif //SOME_GENERIC_WINDOWS
28 
29 
30 
31 #ifdef MCL_USE_UNICODE_IF_DESIRED
32 
33 #include <tchar.h>
34 //WIN 32
35 
36 typedef TCHAR MCL_TCHAR;
37 
39 #define __mccl_strcpy _tcscpy
40 #define __mccl_strcat _tcscat
41 #define __mccl_strlen _tcslen
42 #define __mccl_strcmp _tcscmp
43 #define __mccl_strncmp strncmp
44 #define __mccl_printf _tprintf
45 #define __mccl_sprintf _stprintf
46 
47 #define __mccl_fopen _tfopen
48 #define __mccl_fclose fclose
49 #define __mccl_atoi _ttoi
50 #define __mccl_fscanf _ftscanf
51 #define __mccl_fgets _fgetts
52 #define __mccl_fprintf _ftprintf
53 
54 #define __mccl_tolwr _tcslwr
55 #define __mccl_toupr _tcsupr
56 
57 #define __mccl_atof wcstod
58 
59 #define _TMCL _T
60 
62 #else //MCL_USE_UNICODE_IF_DESIRED
63 
64 // GENERIC
65 typedef char MCL_TCHAR;
66 #define _TMCL
67 
68 
70 // Generic string operation definitions for Unices/Linux (UNICODE? MBCS?)
71 #define __mccl_strcpy strcpy
72 #define __mccl_strcat strcat
73 #define __mccl_strlen strlen
74 #define __mccl_strcmp strcmp
75 #define __mccl_strncmp strncmp
76 #define __mccl_printf printf
77 #define __mccl_sprintf sprintf
78 
79 #define __mccl_fopen fopen
80 #define __mccl_fclose fclose
81 #define __mccl_atoi atoi
82 
83 #define __mccl_fscanf fscanf
84 #define __mccl_fgets fgets
85 #define __mccl_fprintf fprintf
86 
87 #ifdef WIN32
88 #ifdef UNICODE
89 #define __mccl_tolwr _strlwr
90 #define __mccl_toupr _strupr
91 #else
92 #define __mccl_tolwr strlwr
93 #define __mccl_toupr strupr
94 #endif
95 #else //WIN32
96 void __mccl_tolwr(MCL_TCHAR * szText);
97 void __mccl_toupr(MCL_TCHAR * szText);
98 #endif /* WIN32 */
99 
100 #define __mccl_atof atof
101 #endif //MCL_USE_UNICODE_IF_DESIRED
103 
104 
105 MDLLEXPORT void SetMemoryManage(bool b = true);
106 MDLLEXPORT void MCLSetUTF8Encode(bool b = true);
108 MDLLEXPORT void MCLSetCasing(bool b = true);
109 
110 class CMString
111 {
112 public:
113 
114  MDLLEXPORT CMString();
115  MDLLEXPORT CMString(const CMString& S);
116  MDLLEXPORT CMString(const MCL_TCHAR* a);
117 
119 
120  MDLLEXPORT operator const MCL_TCHAR*() const;
121 
122  MDLLEXPORT bool IsEmpty() const;
123  MDLLEXPORT long length() const;
124  MDLLEXPORT long len() const {return length();}
125 
126  // Assignment:
127  MDLLEXPORT CMString& operator=(const MCL_TCHAR*);
128  MDLLEXPORT CMString& operator=(const CMString&);
129  MDLLEXPORT CMString& operator+=(const MCL_TCHAR*);
130  MDLLEXPORT CMString& operator+=(const CMString& s);
131  MDLLEXPORT CMString& operator+=(const MCL_TCHAR);
132 
133 
134  // Indexing operators:
135  //() is bounds checking in DEBUG, [] does bounds check ALWAYS
138  MDLLEXPORT MCL_TCHAR operator[](long) const;
139  MDLLEXPORT MCL_TCHAR operator()(long) const;
140 
141 
142  MDLLEXPORT bool operator == (const CMString& s1) const;
143  MDLLEXPORT bool operator == (const MCL_TCHAR * s1) const;
144 
145  MDLLEXPORT bool operator != (const CMString& s1) const;
146  MDLLEXPORT bool operator != (const MCL_TCHAR * s1) const;
147 
148  MDLLEXPORT bool operator > (const CMString& s1) const;
149  MDLLEXPORT bool operator > (const MCL_TCHAR * s1) const;
150 
151  MDLLEXPORT bool operator < (const CMString& s1) const;
152  MDLLEXPORT bool operator < (const MCL_TCHAR * s1) const;
153 
154  MDLLEXPORT bool operator >= (const CMString& s1) const;
155  MDLLEXPORT bool operator >= (const MCL_TCHAR * s1) const;
156 
157  MDLLEXPORT bool operator <= (const CMString& s1) const;
158  MDLLEXPORT bool operator <= (const MCL_TCHAR * s1) const;
159 
160  MDLLEXPORT void toLower();
161  MDLLEXPORT void toUpper();
162  MDLLEXPORT void removeLeadingChars(char c = ' ');
163  MDLLEXPORT void removeTrailingChars(char c = ' ');
164  MDLLEXPORT void removeSpaces();
165 
166 private:
167  //We might want to hook in a mem mgr at some point...
168  MCL_TCHAR * GetMemory(long charLen) const;
169  void DeleteMemory(MCL_TCHAR *) const;
170 
172 
173 };
174 
179 class IMStream
180 {
181 public:
182  virtual ~IMStream() {}
183 
184  virtual bool Open(const CMString &) = 0;
185  virtual bool Close() = 0;
186  virtual bool IsOpen() = 0;
187  virtual bool IsEnd() = 0;
188 
189  virtual long BytesProcessed() = 0;
190 };
191 
192 
193 
198 class IMReadStream : public IMStream
199 {
200 public:
201 
202  virtual ~IMReadStream() {}
203 
204  bool Read(long & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
205  bool Read(unsigned long & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
206 
207  bool Read(int & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
208  bool Read(unsigned int & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
209 
210  bool Read(short & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
211  bool Read(unsigned short & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
212 
213  bool Read(char & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
214  bool Read(unsigned char & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
215  bool Read(signed char & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
216 
217  bool Read(float & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
218  bool Read(double & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
219 
220  bool Read(long long & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
221  bool Read(unsigned long long & d) { return ReadSimpleType((void*)&d, sizeof(d)); }
222 
223  bool Read(CMString & d) { return ReadString(d); }
224  bool ReadLine(CMString & d) { return ReadStringLine(d); }
225 
226  bool Read(void * p, long lenInElements, long elSize = 1) { return ReadBlob(p, lenInElements, elSize); }
227 
228  virtual IMReadStream * CloneAndOpen(const CMString &name) = 0;
229 
230 protected:
231  virtual bool ReadSimpleType(void * pData, long lenInBytes) = 0;
232  virtual bool ReadBlob(void * pData, long lenInElements, long elSize) = 0;
233  virtual bool ReadString(CMString & string) = 0;
234  virtual bool ReadStringLine(CMString & string) = 0;
235 
236 };
237 
238 
243 class IMWriteStream : public IMStream
244 {
245 public:
246  virtual ~IMWriteStream() {}
247 
248  bool Write(const long & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
249  bool Write(const unsigned long & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
250 
251  bool Write(const int & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
252  bool Write(const unsigned int & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
253 
254  bool Write(const short & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
255  bool Write(const unsigned short & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
256 
257  bool Write(const char & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
258  bool Write(const unsigned char & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
259  bool Write(const signed char & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
260 
261  bool Write(const float & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
262  bool Write(const double & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
263 
264  bool Write(const long long & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
265  bool Write(const unsigned long long & d) { return WriteSimpleType((const void*)&d, sizeof(d)); }
266 
267 
268  bool Write(const CMString & d) { return WriteString(d); }
269  bool WriteLine(const CMString & d) { return WriteStringLine(d); }
270 
271  bool Write(const void * p, long lenInElements, long elSize = 1) { return WriteBlob(p, lenInElements, elSize); }
272 
273  virtual IMWriteStream * CloneAndOpen(const CMString &name) = 0;
274 
275 protected:
276  virtual bool WriteSimpleType(const void * pData, long lenInBytes) = 0;
277  virtual bool WriteBlob(const void * pData, long lenInElements, long elSize) = 0;
278  virtual bool WriteString(const CMString & string) = 0;
279  virtual bool WriteStringLine(const CMString & string) = 0;
280 };
281 
282 
283 
284 
285 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
287 {
288 public:
289  virtual ~IMLogSink() {}
290  virtual void OnLog(const MCL_TCHAR * szText, bool bLineFeed) = 0;
291 };
292 
293 MDLLEXPORT void MLog(const MCL_TCHAR * szText, bool bLineFeed = true);
294 MDLLEXPORT void MLog(const MCL_TCHAR * szText, long val, bool bLineFeed = true);
295 MDLLEXPORT void MLog(const MCL_TCHAR * szText, const MCL_TCHAR * szText2, bool bLineFeed = true);
296 
298 
299 
300 class CMLog;
302 {
303  public:
304  MDLLEXPORT VerbositySetting(int verboseLevel)
305  {
306  setLevel(verboseLevel);
307  };
308  MDLLEXPORT void setLevel(int verboseLevel)
309  {
310  mVerboseLevel = verboseLevel;
311  };
312  MDLLEXPORT int getLevel() const
313  {
314  return mVerboseLevel;
315  };
316  protected:
317  int mVerboseLevel;
318 };
319 
320 
321 #define ML_ENDL "\n"
322 
323 
324 class CMLog
325 {
326  public:
327  MDLLEXPORT CMLog();
328  MDLLEXPORT ~CMLog();
329 
330  MDLLEXPORT CMLog & operator<<(char c);
331  MDLLEXPORT CMLog & operator<<(unsigned char c);
332  MDLLEXPORT CMLog & operator<<(signed char c);
333  MDLLEXPORT CMLog & operator<<(const MCL_TCHAR *s);
334  MDLLEXPORT CMLog & operator<<(const CMString & s);
335  MDLLEXPORT CMLog & operator<<(const unsigned char *s);
336  MDLLEXPORT CMLog & operator<<(const signed char *s);
337  MDLLEXPORT CMLog & operator<<(const void *p);
338  MDLLEXPORT CMLog & operator<<(int n);
339  MDLLEXPORT CMLog & operator<<(unsigned int n);
340  MDLLEXPORT CMLog & operator<<(long n);
341  MDLLEXPORT CMLog & operator<<(unsigned long n);
342  MDLLEXPORT CMLog & operator<<(double n);
343  MDLLEXPORT CMLog & operator<<(float n);
344 
345  MDLLEXPORT CMLog & operator<<(const VerbositySetting &rVs);
346 
347  //CMLog & operator<<(ostream & (*op)(ostream&));
348  protected:
350 
351  //void print(const MCL_TCHAR * szText, bool bLineFeed);
352 
353 
354 };
355 
356 MDLLEXPORT CMLog & mlog();
357 
358 
359 #ifdef _DEBUG
360 #ifndef DEBUG
361 #define DEBUG
362 #endif
363 #endif /* DEBUG */
364 
365 #ifdef DEBUG
366 #ifndef MLIST_BOUNDSCHECK
367 // #define MLIST_BOUNDSCHECK
368 #endif
369 #endif /* DEBUG */
370 
371 template <class Item> class TMValueVector;
372 template <class Item> class TMSTValueVector;
373 
383 
384 
385 
390 template <class Item, long size>
392 {
393 public:
397 
398  inline const Item & operator[](const long index) const;
399  inline const Item & operator()(const long index) const;
400 
401  inline Item & operator[](long index);
402  inline Item & operator()(long index);
403 
404  inline long length() const;
405 
406  inline Item * data();
407 
409  inline const TMFixedValueVector<Item, size> & operator = (const Item item);
410 
411 protected:
412 
413  inline void BoundsCheck(const long index) const;
414  Item m_array[size];
415 
416 private:
417 
418 };
419 
420 template <class Item, long size>
422 {
423 }
424 
425 
426 template <class Item, long size>
428 {
429  *this = vector;
430 }
431 
432 template <class Item, long size>
434 {
435 }
436 
437 template <class Item, long size>
439 {
440  for (long i=0; i<size; i++)
441  m_array[i] = val;
442 
443  return *this;
444 }
445 
446 template <class Item, long size>
448 {
449  for (long i=0; i<size; i++)
450  m_array[i] = vector(i);
451 
452  return *this;
453 }
454 
455 
456 
457 template <class Item, long size>
458 inline void TMFixedValueVector<Item, size>::BoundsCheck(const long index) const
459 {
460 #ifdef MLIST_BOUNDSCHECK
461  if (index < size)
462  return;
463 
464  ThrowException(_TMCL("TMValueVector<Item>::BoundsCheck"));
465 
466 #endif
467 }
468 
469 template <class Item, long size>
470 inline const Item & TMFixedValueVector<Item, size>::operator[](const long index) const
471 {
472 #ifdef MLIST_BOUNDSCHECK
473  BoundsCheck(index);
474 #endif
475  return m_array[index];
476 }
477 
478 template <class Item, long size>
479 inline const Item & TMFixedValueVector<Item, size>::operator()(const long index) const
480 {
481 #ifdef MLIST_BOUNDSCHECK
482  BoundsCheck(index);
483 #endif
484  return m_array[index];
485 }
486 
487 template <class Item, long size>
489 {
490 #ifdef MLIST_BOUNDSCHECK
491  BoundsCheck(index);
492 #endif
493  return m_array[index];
494 }
495 
496 template <class Item, long size>
498 {
499 #ifdef MLIST_BOUNDSCHECK
500  BoundsCheck(index);
501 #endif
502  return m_array[index];
503 }
504 
505 
506 template <class Item, long size>
508 {
509  return m_array;
510 }
511 
512 template <class Item, long size>
514 {
515  return size;
516 }
517 
518 
523 template <class Item, long size>
524 class TMIOFixedValueVector : public TMFixedValueVector<Item, size>
525 {
526 public:
527  bool Read(IMReadStream & stream) {
528 
529  for (int i=0; i<size; i++)
530  this->m_array[i].Read(stream);
531 
532  return true;
533  }
534 
535  bool Write(IMWriteStream & stream) {
536 
537  for (int i=0; i<size; i++)
538  this->m_array[i].Write(stream);
539 
540  return true;
541  }
542 };
543 
548 template <class Item, long size>
549 class TMSTFixedValueVector : public TMFixedValueVector<Item, size>
550 {
551 public:
552  bool Read(IMReadStream & stream)
553  {
554  return stream.Read(this->m_array,
555  size,
556  sizeof(Item));
557  }
558 
559  bool Write(IMWriteStream & stream)
560  {
561  return stream.Write(this->m_array,
562  size,
563  sizeof(Item));
564  }
565 };
566 
571 template <class Item>
572 class TMValueVector
573 {
574 public:
575  TMValueVector(const TMValueVector &);
576  TMValueVector();
577  ~TMValueVector();
578 
579  inline const Item & operator[](const long index) const;
580  inline const Item & operator()(const long index) const;
581 
582  inline Item & operator[](long index);
583  inline Item & operator()(long index);
584 
585  inline long length() const;
586 
587  inline void reshape(long);
588 
589  inline const Item * data() const;
590 
591  inline const TMValueVector<Item> & operator = (const TMValueVector &);
592 protected:
593 
594  inline void BoundsCheck(const long index) const;
595  long m_length;
596  Item * m_pArray;
597 
598 private:
599 
600 };
601 
602 template <class Item>
604 {
605  m_length = 0;
606  m_pArray = NULL;
607 }
608 
609 
610 template <class Item>
612 {
613  m_length = 0;
614  m_pArray = NULL;
615  *this = vector;
616 }
617 
618 template <class Item>
620 {
621  if (m_pArray != NULL)
622  delete [] m_pArray;
623 }
624 
625 
626 template <class Item>
628 {
629  reshape(vector.length());
630  for (long i=0; i<m_length; i++)
631  m_pArray[i] = vector(i);
632 
633  return *this;
634 }
635 
636 
637 
638 template <class Item>
639 inline void TMValueVector<Item>::BoundsCheck(const long index) const
640 {
641 #ifdef MLIST_BOUNDSCHECK
642  if (index < m_length)
643  return;
644 
645  ThrowException(_TMCL("TMValueVector<Item>::BoundsCheck"));
646 
647 #endif
648 }
649 
650 template <class Item>
651 inline const Item & TMValueVector<Item>::operator[](const long index) const
652 {
653 #ifdef MLIST_BOUNDSCHECK
654  BoundsCheck(index);
655 #endif
656  return m_pArray[index];
657 }
658 
659 template <class Item>
660 inline const Item & TMValueVector<Item>::operator()(const long index) const
661 {
662 #ifdef MLIST_BOUNDSCHECK
663  BoundsCheck(index);
664 #endif
665  return m_pArray[index];
666 }
667 
668 template <class Item>
669 inline Item & TMValueVector<Item>::operator[](long index)
670 {
671 #ifdef MLIST_BOUNDSCHECK
672  BoundsCheck(index);
673 #endif
674  return m_pArray[index];
675 }
676 
677 template <class Item>
678 inline Item & TMValueVector<Item>::operator()(long index)
679 {
680 #ifdef MLIST_BOUNDSCHECK
681  BoundsCheck(index);
682 #endif
683  return m_pArray[index];
684 }
685 
686 
687 template <class Item>
688 inline const Item * TMValueVector<Item>::data() const
689 {
690  return m_pArray;
691 }
692 
693 template <class Item>
694 inline long TMValueVector<Item>::length() const
695 {
696  return m_length;
697 }
698 
699 template <class Item>
700 inline void TMValueVector<Item>::reshape(long length)
701 {
702 
703  Item * pNewArray;
704  if (length > 0)
705  pNewArray = new Item[length];
706  else
707  pNewArray = NULL;
708 
709  long realLength = m_length;
710  if (m_length > length)
711  realLength = length;
712 
713  m_length = length;
714 
715  for (long i=0; i<realLength; i++)
716  pNewArray[i] = m_pArray[i];
717 
718  Item * pTempArray = m_pArray;
719  m_pArray = pNewArray;
720 
721  if (pTempArray != NULL)
722  delete [] pTempArray;
723 }
724 
725 
726 
727 
732 template <class Item>
733 class TMIOValueVector : public TMValueVector<Item>
734 {
735 public:
736  bool Read(IMReadStream & stream)
737  {
738 
739  long length;
740  stream.Read(length);
741 
742  this->reshape(length);
743 
744  for (int i=0; i<length; i++)
745  (this->operator())(i).Read(stream);
746 
747  return true;
748  }
749 
750  bool Write(IMWriteStream & stream)
751  {
752 
753  stream.Write(this->m_length);
754 
755  for (int i = 0; i < this->length(); i++)
756  (this->operator())(i).Write(stream);
757 
758  return true;
759  }
760 };
761 
766 template <class Item>
767 class TMSTValueVector : public TMValueVector<Item>
768 {
769 public:
770  bool Read(IMReadStream & stream)
771  {
772  long length;
773  stream.Read(length);
774  this->reshape(length);
775 
776  return stream.Read(this->m_pArray,
777  length,
778  sizeof(Item));
779  }
780 
781  bool Write(IMWriteStream & stream)
782  {
783  stream.Write(this->m_length);
784 
785  return stream.Write(this->m_pArray,
787  sizeof(Item));
788  }
789 
790 };
791 
792 
797 template <class Item, unsigned long ChunkSize = 64>
799 {
800 public:
801  TMPtrList();
802  ~TMPtrList();
803 
804  inline const Item * operator[](const long index) const;
805  inline const Item * operator()(const long index) const;
806 
807  inline Item * operator[](long index);
808  inline Item * operator()(long index);
809 
810  inline long length() const;
811 
812  //References the pointer
813  inline void add(Item *);
814  //Makes a copy
815  inline void add(const Item &);
816 
817  //References the pointer
818  inline void insert(Item *, long);
819  //Makes a copy
820  inline void insert(const Item &, long);
821 
822  //Creates an element
823  inline long add();
824  inline void remove(const Item *);
825  inline void remove(long index);
826  inline void removeNoDelete(const Item *);
827  inline void removeNoDelete(long index);
828 
829  inline void removeNoDeleteAll();
830  inline void removeAll();
831 
832  TMPtrList<Item> & operator = (const TMPtrList<Item> & toCopy);
833 
834  //Deletes the object and sets it to NULL
835  //- but it does NOT remove it!!
836  inline void nullify(long i);
837 
838  //Copies the last object over the current; does NOT delete it
839  inline void replaceWithLast(long i);
840 
841 protected:
842 
845 
846 private:
847 
848 };
849 
850 
851 template <class Item, unsigned long ChunkSize>
853 {
854  m_realLength = 0;
855 }
856 
857 template <class Item, unsigned long ChunkSize>
859 {
860  removeAll();
861 }
862 
863 
864 
865 template <class Item, unsigned long ChunkSize>
866 inline const Item * TMPtrList<Item, ChunkSize>::operator[](const long index) const
867 {
868  return m_list(index);
869 }
870 
871 template <class Item, unsigned long ChunkSize>
872 inline const Item * TMPtrList<Item, ChunkSize>::operator()(const long index) const
873 {
874  return m_list(index);
875 }
876 
877 
878 template <class Item, unsigned long ChunkSize>
879 inline Item * TMPtrList<Item, ChunkSize>::operator[](long index) {
880  return m_list(index);
881 }
882 
883 template <class Item, unsigned long ChunkSize>
884 inline Item * TMPtrList<Item, ChunkSize>::operator()(long index)
885 {
886  return m_list(index);
887 }
888 
889 template <class Item, unsigned long ChunkSize>
891 {
892  removeAll();
893  for (long i=0; i<toCopy.length(); i++) {
894  Item * pNew = new Item;
895  *pNew = *(toCopy(i));
896  add(pNew);
897  }
898  return *this;
899 }
900 
901 
902 template <class Item, unsigned long ChunkSize>
904 {
905  return m_realLength;
906 }
907 
908 //References the pointer
909 template <class Item, unsigned long ChunkSize>
910 inline void TMPtrList<Item, ChunkSize>::add(Item * pItem)
911 {
912  if (m_realLength == m_list.length())
913  m_list.reshape(m_realLength + ChunkSize);
914 
915  m_list(m_realLength) = pItem;
916  m_realLength++;
917 }
918 
919 //Makes a copy
920 template <class Item, unsigned long ChunkSize>
921 inline void TMPtrList<Item, ChunkSize>::add(const Item & item)
922 {
923  Item * pItem = new Item(item);
924  add(pItem);
925 }
926 
927 //Creates an element
928 template <class Item, unsigned long ChunkSize>
930 {
931  Item * pItem = new Item;
932  add(pItem);
933  return m_realLength - 1;
934 }
935 
936 //References the pointer
937 template <class Item, unsigned long ChunkSize>
938 inline void TMPtrList<Item, ChunkSize>::insert(Item * pItem, long pos)
939 {
940  if (m_realLength == 0) {
941  add(pItem);
942  return;
943  }
944 
945  add(m_list(m_realLength - 1));
946 
947  for (long i=m_realLength - 1; i>pos; i--) {
948  m_list(i) = m_list(i-1);
949  }
950  m_list(pos) = pItem;
951 }
952 
953 //Makes a copy
954 template <class Item, unsigned long ChunkSize>
955 inline void TMPtrList<Item, ChunkSize>::insert(const Item & item, long pos)
956 {
957  Item * pItem = new Item(item);
958  insert(pItem, pos);
959 }
960 
961 template <class Item, unsigned long ChunkSize>
962 inline void TMPtrList<Item, ChunkSize>::remove(const Item * pItem)
963 {
964  for (long i=0; i<m_realLength; i++) {
965  if (m_list(i) == pItem) {
966  remove(i);
967  break;
968  }
969  }
970 }
971 
972 template <class Item, unsigned long ChunkSize>
973 inline void TMPtrList<Item, ChunkSize>::remove(long index)
974 {
975  delete m_list(index);
976  for (long i=index + 1; i<m_realLength; i++) {
977  m_list(i - 1) = m_list(i);
978  }
979  m_realLength--;
980 }
981 
982 template <class Item, unsigned long ChunkSize>
983 inline void TMPtrList<Item, ChunkSize>::removeNoDelete(const Item * pItem)
984 {
985  for (long i=0; i<m_realLength; i++) {
986  if (m_list(i) == pItem) {
987  removeNoDelete(i);
988  break;
989  }
990  }
991 }
992 
993 template <class Item, unsigned long ChunkSize>
995 {
996  for (long i=index + 1; i<m_realLength; i++) {
997  m_list(i - 1) = m_list(i);
998  }
999  m_realLength--;
1000 }
1001 
1002 template <class Item, unsigned long ChunkSize>
1004 {
1005  m_realLength = 0;
1006 }
1007 
1008 template <class Item, unsigned long ChunkSize>
1010 {
1011  delete m_list(i);
1012  m_list(i) = NULL;
1013 }
1014 
1015 template <class Item, unsigned long ChunkSize>
1017 {
1018  m_list(i) = m_list(m_realLength - 1);
1019  m_realLength--;
1020 }
1021 
1022 
1023 template <class Item, unsigned long ChunkSize>
1025 {
1026  for (long i=0; i<m_realLength; i++) {
1027  if (m_list(i) != NULL) {
1028  delete m_list(i);
1029  }
1030  }
1031 
1032  m_realLength = 0;
1033 }
1034 
1039 template <class Item, unsigned long ChunkSize = 64>
1040 class TMNoOwnPtrList : public TMPtrList<Item, ChunkSize>
1041 {
1042 public:
1044  inline TMNoOwnPtrList<Item> & operator = (const TMNoOwnPtrList<Item> & toCopy);
1045 };
1046 
1047 template <class Item, unsigned long ChunkSize>
1049 {
1050  this->removeNoDeleteAll();
1051  //Just "borrows" the objects...
1052  for (long i=0; i<toCopy.length(); i++) {
1053  add((Item*)toCopy(i));
1054  }
1055  return *this;
1056 }
1057 
1058 
1063 template <class Item>
1064 class TMIOPtrList : public TMPtrList<Item>
1065 {
1066 public:
1067  bool Read(IMReadStream & stream)
1068  {
1069 
1070  long len;
1071  stream.Read(len);
1072 
1073  this->removeAll();
1074 
1075  for (int i=0; i<len; i++) {
1076  Item * pItem = new Item;
1077  add(pItem);
1078  pItem->Read(stream);
1079  }
1080 
1081  return true;
1082  }
1083 
1084  bool Write(IMWriteStream & stream)
1085  {
1086 
1087  stream.Write(this->m_realLength);
1088 
1089  for (int i = 0; i < this->length(); i++)
1090  (this->operator())(i)->Write(stream);
1091 
1092  return true;
1093  }
1094 };
1095 
1096 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1097 
1100 
1101 
1103 {
1104 public:
1105  CMStringMap(const CMString & string1, const CMString & string2) : m_string1(string1), m_string2(string2)
1106  {
1107  }
1108 
1109  CMStringMap(const CMString & string1) : m_string1(string1), m_string2(string1)
1110  {
1111  }
1112 
1113  const CMString & GetString() {return m_string1;}
1114  const CMString & GetMap() {return m_string2;}
1115 
1116  void SetString(const CMString & s) {m_string1 = s;}
1117  void SetMap(const CMString & s) {m_string2 = s;}
1118 
1119 private:
1122 };
1123 
1124 
1126 
1127 MDLLEXPORT bool Tokenize(CMPtrStringList & result, const CMString & source, char delimiter = ' ', long limit = 0x7FFFFFFF);
1128 MDLLEXPORT bool GetNextToken(CMString & result, CMString & source, char delimiter = ' ');
1129 
1130 
1132 {
1133 public:
1136 
1137  MDLLEXPORT bool Tokenize(CMPtrStringList & result, const CMString & source);
1138  MDLLEXPORT void AddDelimiter(const CMString & delimiter, const CMString & replacement = "");
1139 
1140 private:
1141  bool IsDelimiter(const char * pBuffer, long & inc, long & mapIndex);
1142 
1144 };
1145 
1146 
1147 
1148 
1154 {
1155 public:
1158 
1159 
1160  MDLLEXPORT virtual bool Open(const CMString &);
1161  MDLLEXPORT virtual bool Close();
1162  MDLLEXPORT virtual bool IsOpen();
1163  MDLLEXPORT virtual bool IsEnd();
1164 
1165  virtual IMReadStream * CloneAndOpen(const CMString &name);
1166 
1167  virtual long BytesProcessed() {return m_bytesProcessed;}
1168 
1169 protected:
1170  virtual bool ReadSimpleType(void * pData, long lenInBytes);
1171  virtual bool ReadBlob(void * pData, long lenInElements, long elSize);
1172  virtual bool ReadString(CMString & string);
1173  virtual bool ReadStringLine(CMString & string);
1174 
1175 
1176 private:
1177 
1178  FILE * m_pFile;
1181  bool m_bIsEof;
1183 
1184 };
1185 
1186 
1192 {
1193 public:
1196 
1197 
1198  MDLLEXPORT virtual bool Open(const CMString &);
1199  MDLLEXPORT virtual bool Close();
1200  MDLLEXPORT virtual bool IsOpen();
1201  MDLLEXPORT virtual bool IsEnd();
1202 
1203  MDLLEXPORT virtual bool WriteLine(const CMString & line);
1204  virtual IMWriteStream * CloneAndOpen(const CMString &name) {
1205  CMString tmp = name; // Suppress compiler warning.
1206  return NULL;
1207  }
1208 
1209  virtual long BytesProcessed() {return m_bytesProcessed;}
1210 
1211 protected:
1212  virtual bool WriteSimpleType(const void * pData, long lenInBytes);
1213  virtual bool WriteBlob(const void * pData, long lenInElements, long elSize);
1214  virtual bool WriteString(const CMString & string);
1215  virtual bool WriteStringLine(const CMString & string);
1216 
1217 private:
1218 
1219  FILE * m_pFile;
1222  bool m_bIsEof;
1224 
1225 };
1226 
1227 
1228 
1234 {
1235 public:
1237  MDLLEXPORT virtual ~CMReadFileStream();
1238 
1239 
1240  MDLLEXPORT virtual bool Open(const CMString & name);
1241  MDLLEXPORT virtual bool Close();
1242  MDLLEXPORT virtual bool IsOpen();
1243  MDLLEXPORT virtual bool IsEnd();
1244  virtual IMReadStream * CloneAndOpen(const CMString &name) {
1245  CMString tmp = name; // Suppress compiler warning.
1246  return NULL;
1247  }
1248  virtual long BytesProcessed() {return m_bytesProcessed;}
1249 
1250 protected:
1251  virtual bool ReadSimpleType(void * pData, long lenInBytes);
1252  virtual bool ReadBlob(void * pData, long lenInElements, long elSize);
1253  virtual bool ReadString(CMString & string);
1254  virtual bool ReadStringLine(CMString & string);
1255 
1256 
1257 private:
1258 
1259  FILE * m_pFile;
1262  bool m_bIsEof;
1264 
1265 };
1266 
1267 
1273 {
1274 public:
1276  MDLLEXPORT virtual ~CMWriteFileStream();
1277 
1278 
1279  MDLLEXPORT virtual bool Open(const CMString & name);
1280  MDLLEXPORT virtual bool Close();
1281  MDLLEXPORT virtual bool IsOpen();
1282  MDLLEXPORT virtual bool IsEnd();
1283  virtual IMWriteStream * CloneAndOpen(const CMString &name) {
1284  CMString tmp = name; // Suppress compiler warning.
1285  return NULL;
1286  }
1287  virtual long BytesProcessed() {return m_bytesProcessed;}
1288 
1289 protected:
1290  virtual bool WriteSimpleType(const void * pData, long lenInBytes);
1291  virtual bool WriteBlob(const void * pData, long lenInElements, long elSize);
1292  virtual bool WriteString(const CMString & string);
1293  virtual bool WriteStringLine(const CMString & string) {return WriteString(string);}
1294 
1295 private:
1296 
1297  FILE * m_pFile;
1300  bool m_bIsEof;
1302 
1303 };
1304 
1305 #ifdef MCL_NO_EXCEPTIONS
1306 #define MCL_TRY
1307 #else //MCL_NO_EXCEPTIONS
1308 #define MCL_TRY try
1309 #endif//MCL_NO_EXCEPTIONS
1310 
1311 MDLLEXPORT void ThrowException();
1312 MDLLEXPORT void ThrowException(const CMString & reason);
1313 MDLLEXPORT void ThrowException(const CMString & comment, const CMString & reason);
1314 
1315 
1317 {
1318 public:
1319  MDLLEXPORT CMException(const CMString & error);
1320  MDLLEXPORT virtual ~CMException();
1321 
1322  MDLLEXPORT const CMString & GetErrorText();
1323 
1324  MDLLEXPORT void Print();
1325 private:
1327 };
1328 
1329 
1330 
1331 
1332 
1337 template <class Item>
1339 {
1340 public:
1343 
1344  inline void SetTo(const Item * pSearchList, long length);
1345  inline bool Search(long & index, const Item & toFind);
1346 
1347 private:
1349 
1350  long m_length;
1352 
1353 };
1354 
1355 
1360 template <class Item, class Index>
1362 {
1363 public:
1366 
1367  inline void Add(const Item & , Index);
1368 
1369  inline void SetDataPtr(const TMValueVector<Item> * pSearchList);
1370  inline bool Search(Index & index, const Item & toFind);
1371 
1373  long & GetLength() {return m_length;}
1374  long & GetVirtualLength() {return m_virtLength;}
1375 
1376  inline const Index IndexToIndex(const long index) const { return m_index(index); }
1377  inline bool Peek(const long & index, Item & toFind);
1378  inline bool InternalSearch(long & i, const Item & toFind);
1379 
1380  bool Write(IMWriteStream &);
1381  bool Read(IMReadStream &);
1382 
1384  {
1385  m_pSearchPtr = NULL;
1386  m_index = idx.m_index;
1387  m_length = idx.m_length;
1388  m_virtLength = idx.m_virtLength;
1389  return *this;
1390  }
1391 
1392 
1393 
1394 protected:
1397 
1398  long m_length;
1400 };
1401 
1402 
1403 
1404 
1405 //--------------------------------------------------------------
1406 //--------------------------------------------------------------
1407 
1408 template <class Item>
1409 inline void TMBinaryArraySearcher<Item>::SetTo(const Item * pSearchList, long length)
1410 {
1411  m_pSearchPtr = (Item *)pSearchList;
1412 
1413  m_length = (long)length;
1414  m_virtLength = 1;
1415  while (m_virtLength < m_length)
1416  m_virtLength = m_virtLength << 1;
1417 
1418 }
1419 
1420 template <class Item>
1421 inline bool TMBinaryArraySearcher<Item>::Search(long & index, const Item & toFind)
1422 {
1423 
1424  long i = 0;
1425  long interval = (long)m_virtLength / 2;
1426  index = 0;
1427 
1428  if (m_pSearchPtr[0] > toFind) {
1429  index = 0;
1430  return false;
1431  }
1432 
1433  if (m_pSearchPtr[m_length - 1] < toFind) {
1434  index = m_length;
1435  return false;
1436  }
1437 
1438  if (m_pSearchPtr[0] == toFind) {
1439  index = 0;
1440  return true;
1441  }
1442 
1443  while (interval > 0) {
1444 
1445  if (i < m_length && m_pSearchPtr[i] == toFind) {
1446  index = i;
1447  return true;
1448  }
1449 
1450  if (i >= m_length || m_pSearchPtr[i] > toFind) {
1451  interval = interval >> 1;
1452  i -= interval;
1453  } else {
1454  i += interval;
1455  }
1456 
1457  }
1458 
1459  if (i >= m_length) {
1460  index = m_length;
1461  } else {
1462  index = (long)i;
1463  }
1464 
1465  return false;
1466 
1467 }
1468 
1469 
1470 //-----------------------------------------------------
1471 //-----------------------------------------------------
1472 template <class Item, class Index>
1474 {
1475  stream.Write(m_length);
1476  stream.Write(m_virtLength);
1477  m_index.Write(stream);
1478 
1479  return true;
1480 }
1481 
1482 template <class Item, class Index>
1484 {
1485  stream.Read(m_length);
1486  stream.Read(m_virtLength);
1487  m_index.Read(stream);
1488  return true;
1489 }
1490 
1491 template <class Item, class Index>
1493 {
1494  m_pSearchPtr = pSearchList;
1495 
1496 }
1497 
1498 
1499 template <class Item, class Index>
1500 inline void TMBinaryIndexSearcher<Item, Index>::Add(const Item & item, Index wordIndex)
1501 {
1502  if (m_length == m_virtLength) {
1503  m_virtLength = 1;
1504  while (m_virtLength < m_length + 1)
1505  m_virtLength = m_virtLength << 1;
1506  }
1507 
1508 
1509  long index;
1510  if (m_length > 0) {
1511  if (InternalSearch(index, item)) {
1512  }
1513  } else {
1514  index = 0;
1515  }
1516 
1517  if (m_length + 1 >= m_index.length())
1518  m_index.reshape(m_index.length() + 256);
1519 
1520  for (long i=m_length; i>(long)index; i--) {
1521  m_index(i) = m_index(i - 1);
1522  }
1523  m_index(index) = wordIndex;
1524  m_length++;
1525 
1526 }
1527 
1528 
1529 template <class Item, class Index>
1530 inline bool TMBinaryIndexSearcher<Item, Index>::InternalSearch(long & i, const Item & toFind)
1531 {
1532  if(m_length<=0)
1533  return false;
1534 
1535  i=0;
1536  long interval = (long)m_virtLength / 2;
1537 
1538  if ((*m_pSearchPtr)[m_index(0)] > toFind) {
1539  i=0;
1540  return false;
1541  }
1542 
1543  if ((*m_pSearchPtr)[m_index(m_length - 1)] < toFind) {
1544  i=m_length;
1545  return false;
1546  }
1547 
1548  if (m_length > 0 && (*m_pSearchPtr)[m_index(0)] == toFind) {
1549  i=0;
1550  return true;
1551  }
1552 
1553  while (interval > 0) {
1554 
1555  if (i < m_length && (*m_pSearchPtr)[m_index(i)] == toFind)
1556  return true;
1557 
1558 
1559  if (i >= m_length || (*m_pSearchPtr)[m_index(i)] > toFind) {
1560  interval = interval >> 1;
1561  i -= interval;
1562  } else {
1563  i += interval;
1564  }
1565 
1566  }
1567 
1568  if (i >= m_length)
1569  i = (long)m_length;
1570 
1571 
1572  return false;
1573 
1574 }
1575 
1576 template <class Item, class Index>
1577 inline bool TMBinaryIndexSearcher<Item, Index>::Peek(const long & index, Item & toFind)
1578 {
1579  if(index>=m_length)
1580  return false;
1581  toFind=(*m_pSearchPtr)[m_index(index)];
1582  return true;
1583 }
1584 
1585 template <class Item, class Index>
1586 inline bool TMBinaryIndexSearcher<Item, Index>::Search(Index & index, const Item & toFind)
1587 {
1588 
1589  long i = 0;
1590  bool res=InternalSearch(i,toFind);
1591  if(res)
1592  index=m_index(i);
1593  else
1594  index=(Index)i;
1595  return res;
1596 }
1597 
1598 
1600 {
1601 public:
1604 
1605  MDLLEXPORT long GetVersion();
1606  MDLLEXPORT long GetRevision();
1607 
1608  MDLLEXPORT void SetVersion(long v);
1609  MDLLEXPORT void SetRevision(long r);
1610 
1611  MDLLEXPORT bool Read(IMReadStream & stream);
1612  MDLLEXPORT bool Write(IMWriteStream & stream);
1613 
1614 private:
1617 };
1618 
1619 
1620 #define INVALID_STRING_DICT_ID -1
1621 
1623 {
1624 public:
1627 
1628  MDLLEXPORT long GetDictID(const CMString & word);
1629  MDLLEXPORT long GetDictIDList(CMInt32List & result, const CMString & word);
1630  MDLLEXPORT const CMString & GetWord(long id);
1631 
1632  MDLLEXPORT long GetWordCount();
1633  MDLLEXPORT long GetDictIDByIndex(long index);
1634  MDLLEXPORT const CMString & GetWordByIndex(long index);
1635 
1636 
1637  //Add a word...
1638  MDLLEXPORT long AddWord(const CMString & word);
1639  MDLLEXPORT long AddWordDontCheck(const CMString & word);
1640 
1641  MDLLEXPORT bool Read(IMReadStream & stream);
1642  MDLLEXPORT bool Write(IMWriteStream & stream);
1643  MDLLEXPORT long IndexToIndex(long index) {return m_searcher.IndexToIndex(index);}
1644  MDLLEXPORT CMStringDictionary & operator = (const CMStringDictionary & dict);
1645 
1646 private:
1650 
1651 };
1652 
1653 
1654 
1655 
1656 MDLLEXPORT const char * GetUTF8Sig();
1657 
1658 MDLLEXPORT bool IsUTF8(const CMString & string);
1659 
1660 MDLLEXPORT bool RemoveUTF8Sig(CMString & string);
1661 
1662 MDLLEXPORT bool AddUTF8Sig(CMString & string);
1663 
1664 #endif
1665 
1666 
Item * m_pArray
Definition: mutil.h:596
bool Read(CMString &d)
Definition: mutil.h:223
bool Read(IMReadStream &stream)
Definition: mutil.h:1067
virtual bool WriteBlob(const void *pData, long lenInElements, long elSize)
Definition: mutil.cc:526
#define _TMCL
Definition: mutil.h:66
long m_length
Definition: mutil.h:1350
virtual long BytesProcessed()
Definition: mutil.h:1287
MDLLEXPORT long GetDictID(const CMString &word)
Definition: mutil.cc:1709
Definition: mutil.h:1361
MDLLEXPORT void SetRevision(long r)
Definition: mutil.cc:1881
MDLLEXPORT ~CMTokenizer()
Definition: mutil.cc:1563
MDLLEXPORT void ThrowException()
Definition: mutil.cc:171
virtual bool WriteStringLine(const CMString &string)
Definition: mutil.cc:542
~TMPtrList()
Definition: mutil.h:858
MDLLEXPORT void removeSpaces()
Definition: mutil.cc:1486
MDLLEXPORT long IndexToIndex(long index)
Definition: mutil.h:1643
TMValueVector< CMString > CMStringList
Definition: mutil.h:1099
virtual IMReadStream * CloneAndOpen(const CMString &name)
Definition: mutil.cc:229
MDLLEXPORT bool RemoveUTF8Sig(CMString &string)
Definition: mutil.cc:1666
const TMValueVector< Item > & operator=(const TMValueVector &)
Definition: mutil.h:627
virtual MDLLEXPORT bool Close()
Definition: mutil.cc:983
CMStringMap(const CMString &string1)
Definition: mutil.h:1109
virtual bool WriteStringLine(const CMString &string)=0
void Add(const Item &, Index)
Definition: mutil.h:1500
bool Search(Index &index, const Item &toFind)
Definition: mutil.h:1586
Item * data()
Definition: mutil.h:507
MDLLEXPORT bool operator==(const CMString &s1) const
Definition: mutil.cc:1361
Definition: mutil.h:1131
long m_realLength
Definition: mutil.h:843
bool Write(IMWriteStream &stream)
Definition: mutil.h:750
void SetMap(const CMString &s)
Definition: mutil.h:1117
~TMBinaryIndexSearcher()
Definition: mutil.h:1365
MDLLEXPORT long len() const
Definition: mutil.h:124
MDLLEXPORT long GetDictIDList(CMInt32List &result, const CMString &word)
Definition: mutil.cc:1729
MDLLEXPORT bool Write(IMWriteStream &stream)
Definition: mutil.cc:1893
bool Write(IMWriteStream &stream)
Definition: mutil.h:559
TMSTValueVector< double > CMDoubleList
Definition: mutil.h:382
FILE * m_pFile
Definition: mutil.h:1178
CMString m_fileName
Definition: mutil.h:1220
Definition: mutil.h:1064
MDLLEXPORT bool operator>(const CMString &s1) const
Definition: mutil.cc:1396
bool m_bIsEof
Definition: mutil.h:1262
virtual bool ReadStringLine(CMString &string)=0
MDLLEXPORT MCL_TCHAR & operator()(long)
Definition: mutil.cc:1239
MDLLEXPORT bool GetNextToken(CMString &result, CMString &source, char delimiter= ' ')
Definition: mutil.cc:1528
virtual IMReadStream * CloneAndOpen(const CMString &name)=0
char MCL_TCHAR
Definition: mutil.h:65
void BoundsCheck(const long index) const
Definition: mutil.h:458
virtual bool ReadBlob(void *pData, long lenInElements, long elSize)
Definition: mutil.cc:330
void SetString(const CMString &s)
Definition: mutil.h:1116
int mVerboseLevel
Definition: mutil.h:349
bool Read(void *p, long lenInElements, long elSize=1)
Definition: mutil.h:226
bool Write(const unsigned long &d)
Definition: mutil.h:249
virtual bool ReadString(CMString &string)=0
long m_wordCount
Definition: mutil.h:1648
const TMValueVector< Item > * m_pSearchPtr
Definition: mutil.h:1395
MDLLEXPORT const CMString & GetWord(long id)
Definition: mutil.cc:1770
CMString m_string2
Definition: mutil.h:1121
TMSTValueVector< short > CMInt16List
Definition: mutil.h:379
MDLLEXPORT bool Read(IMReadStream &stream)
Definition: mutil.cc:1886
MDLLEXPORT ~CMLog()
Definition: mutil.cc:598
bool m_bIsEof
Definition: mutil.h:1300
void SetTo(const Item *pSearchList, long length)
Definition: mutil.h:1409
TMSTValueVector< long > CMInt32List
Definition: mutil.h:380
virtual MDLLEXPORT bool Open(const CMString &name)
Definition: mutil.cc:826
bool Read(unsigned int &d)
Definition: mutil.h:208
bool Write(const unsigned int &d)
Definition: mutil.h:252
Definition: mutil.h:549
bool m_bIsOpen
Definition: mutil.h:1221
MDLLEXPORT bool Read(IMReadStream &stream)
Definition: mutil.cc:1817
Definition: mutil.h:1102
virtual MDLLEXPORT bool IsOpen()
Definition: mutil.cc:502
MDLLEXPORT long AddWord(const CMString &word)
Definition: mutil.cc:1806
TMValueVector< Index > & GetIndexTable()
Definition: mutil.h:1372
Definition: mutil.h:372
virtual MDLLEXPORT bool IsOpen()
Definition: mutil.cc:854
bool Read(long long &d)
Definition: mutil.h:220
MDLLEXPORT CMStringDictionary()
Definition: mutil.cc:1700
Definition: mutil.h:110
virtual MDLLEXPORT bool IsOpen()
Definition: mutil.cc:293
Definition: mutil.h:243
virtual bool Close()=0
MDLLEXPORT CMAsciiReadFileStream()
Definition: mutil.cc:217
CMPtrStringMapList m_map
Definition: mutil.h:1143
MDLLEXPORT long GetDictIDByIndex(long index)
Definition: mutil.cc:1780
const Item & operator[](const long index) const
Definition: mutil.h:470
MDLLEXPORT bool operator<=(const CMString &s1) const
Definition: mutil.cc:1438
MDLLEXPORT void MCLSetCasing(bool b=true)
Definition: mutil.cc:1085
Definition: mutil.h:179
virtual bool ReadStringLine(CMString &string)
Definition: mutil.cc:903
MDLLEXPORT long AddWordDontCheck(const CMString &word)
Definition: mutil.cc:1790
virtual MDLLEXPORT ~CMReadFileStream()
Definition: mutil.cc:821
virtual bool WriteBlob(const void *pData, long lenInElements, long elSize)=0
virtual bool WriteString(const CMString &string)
Definition: mutil.cc:1033
MDLLEXPORT const CMString & GetWordByIndex(long index)
Definition: mutil.cc:1785
int mVerboseLevel
Definition: mutil.h:315
virtual bool WriteString(const CMString &string)
Definition: mutil.cc:552
bool Read(unsigned short &d)
Definition: mutil.h:211
bool Write(const short &d)
Definition: mutil.h:254
void __mccl_toupr(MCL_TCHAR *szText)
Definition: mutil.cc:1074
Definition: mutil.h:1338
TMSTValueVector< unsigned char > CMUInt8List
Definition: mutil.h:372
MDLLEXPORT CMReadFileStream()
Definition: mutil.cc:813
bool Read(signed char &d)
Definition: mutil.h:215
CMStringList m_dict
Definition: mutil.h:1647
MDLLEXPORT bool IsEmpty() const
Definition: mutil.cc:1134
bool Write(const double &d)
Definition: mutil.h:262
MDLLEXPORT void AddDelimiter(const CMString &delimiter, const CMString &replacement="")
Definition: mutil.cc:1568
MDLLEXPORT CMLog()
Definition: mutil.cc:593
void BoundsCheck(const long index) const
Definition: mutil.h:639
bool Read(long &d)
Definition: mutil.h:204
Definition: mutil.h:1272
bool Write(const long long &d)
Definition: mutil.h:264
MDLLEXPORT bool operator<(const CMString &s1) const
Definition: mutil.cc:1409
bool Write(const int &d)
Definition: mutil.h:251
const Item & operator()(const long index) const
Definition: mutil.h:660
long & GetLength()
Definition: mutil.h:1373
CMString m_fileName
Definition: mutil.h:1260
const CMString & GetString()
Definition: mutil.h:1113
Definition: mutil.h:524
CMString m_fileName
Definition: mutil.h:1298
MDLLEXPORT bool AddUTF8Sig(CMString &string)
Definition: mutil.cc:1683
Definition: mutil.h:733
virtual MDLLEXPORT bool Close()
Definition: mutil.cc:843
virtual bool WriteSimpleType(const void *pData, long lenInBytes)
Definition: mutil.cc:1005
TMSTValueVector< Index > m_index
Definition: mutil.h:1396
bool Write(const signed char &d)
Definition: mutil.h:259
virtual bool ReadBlob(void *pData, long lenInElements, long elSize)=0
bool Read(IMReadStream &stream)
Definition: mutil.h:770
long m_bytesProcessed
Definition: mutil.h:1223
long length() const
Definition: mutil.h:694
TMValueVector()
Definition: mutil.h:603
virtual bool Open(const CMString &)=0
void removeNoDeleteAll()
Definition: mutil.h:1003
long length() const
Definition: mutil.h:513
bool Read(IMReadStream &stream)
Definition: mutil.h:736
bool IsDelimiter(const char *pBuffer, long &inc, long &mapIndex)
Definition: mutil.cc:1574
bool Write(const unsigned long long &d)
Definition: mutil.h:265
long m_length
Definition: mutil.h:1398
TMPtrList< CMString > CMPtrStringList
Definition: mutil.h:1098
Definition: mutil.h:286
void DeleteMemory(MCL_TCHAR *) const
Definition: mutil.cc:1124
Item * m_pSearchPtr
Definition: mutil.h:1348
bool Read(unsigned char &d)
Definition: mutil.h:214
virtual bool ReadSimpleType(void *pData, long lenInBytes)
Definition: mutil.cc:864
CMString m_text
Definition: mutil.h:1326
MDLLEXPORT CMString & operator+=(const MCL_TCHAR *)
Definition: mutil.cc:1184
virtual MDLLEXPORT bool Open(const CMString &)
Definition: mutil.cc:474
MDLLEXPORT void removeTrailingChars(char c= ' ')
Definition: mutil.cc:1475
long m_bytesProcessed
Definition: mutil.h:1182
void nullify(long i)
Definition: mutil.h:1009
bool Write(const CMString &d)
Definition: mutil.h:268
MDLLEXPORT CMTokenizer()
Definition: mutil.cc:1559
virtual MDLLEXPORT bool IsEnd()
Definition: mutil.cc:298
bool m_bIsEof
Definition: mutil.h:1181
TMSTValueVector< char > CMCharList
Definition: mutil.h:376
Definition: mutil.h:391
bool m_bIsOpen
Definition: mutil.h:1261
bool WriteLine(const CMString &d)
Definition: mutil.h:269
TMSTValueVector< unsigned short > CMUInt16List
Definition: mutil.h:377
virtual bool ReadBlob(void *pData, long lenInElements, long elSize)
Definition: mutil.cc:885
MDLLEXPORT void toUpper()
Definition: mutil.cc:1347
MDLLEXPORT bool operator>=(const CMString &s1) const
Definition: mutil.cc:1424
long m_virtLength
Definition: mutil.h:1399
const Item * operator[](const long index) const
Definition: mutil.h:866
virtual MDLLEXPORT bool IsEnd()
Definition: mutil.cc:859
void __mccl_tolwr(MCL_TCHAR *szText)
Definition: mutil.cc:1065
MDLLEXPORT CMWriteFileStream()
Definition: mutil.cc:953
MDLLEXPORT long GetWordCount()
Definition: mutil.cc:1775
TMSTValueVector< int > CMIntList
Definition: mutil.h:381
virtual bool WriteSimpleType(const void *pData, long lenInBytes)=0
TMPtrList< CMStringMap > CMPtrStringMapList
Definition: mutil.h:1125
long length() const
Definition: mutil.h:903
Definition: mutil.h:324
MDLLEXPORT void removeLeadingChars(char c= ' ')
Definition: mutil.cc:1458
bool Read(short &d)
Definition: mutil.h:210
long m_bytesProcessed
Definition: mutil.h:1301
virtual bool ReadSimpleType(void *pData, long lenInBytes)
Definition: mutil.cc:303
MDLLEXPORT ~CMFileHeader()
Definition: mutil.cc:1862
virtual long BytesProcessed()
Definition: mutil.h:1248
const CMString & GetMap()
Definition: mutil.h:1114
void replaceWithLast(long i)
Definition: mutil.h:1016
bool Write(IMWriteStream &)
Definition: mutil.h:1473
bool Write(const unsigned char &d)
Definition: mutil.h:258
virtual MDLLEXPORT ~CMException()
Definition: mutil.cc:203
FILE * m_pFile
Definition: mutil.h:1297
long m_length
Definition: mutil.h:595
virtual MDLLEXPORT bool IsEnd()
Definition: mutil.cc:1000
long m_virtLength
Definition: mutil.h:1351
Definition: mutil.h:798
void reshape(long)
Definition: mutil.h:700
virtual IMWriteStream * CloneAndOpen(const CMString &name)
Definition: mutil.h:1204
virtual IMWriteStream * CloneAndOpen(const CMString &name)
Definition: mutil.h:1283
MCL_TCHAR * m_pData
Definition: mutil.h:171
MDLLEXPORT long GetRevision()
Definition: mutil.cc:1871
virtual void OnLog(const MCL_TCHAR *szText, bool bLineFeed)=0
MDLLEXPORT long length() const
Definition: mutil.cc:1451
const TMFixedValueVector< Item, size > & operator=(const TMFixedValueVector< Item, size > &)
Definition: mutil.h:447
virtual bool ReadString(CMString &string)
Definition: mutil.cc:416
Definition: mutil.h:1153
MDLLEXPORT void SetLogSink(IMLogSink *p)
Definition: mutil.cc:733
bool Read(double &d)
Definition: mutil.h:218
MDLLEXPORT void SetVersion(long v)
Definition: mutil.cc:1876
virtual bool WriteString(const CMString &string)=0
bool m_bIsEof
Definition: mutil.h:1222
virtual MDLLEXPORT bool Open(const CMString &name)
Definition: mutil.cc:967
virtual MDLLEXPORT bool Open(const CMString &)
Definition: mutil.cc:264
MDLLEXPORT void setLevel(int verboseLevel)
Definition: mutil.h:308
bool Read(unsigned long long &d)
Definition: mutil.h:221
TMFixedValueVector()
Definition: mutil.h:421
virtual long BytesProcessed()=0
MDLLEXPORT VerbositySetting(int verboseLevel)
Definition: mutil.h:304
long add()
Definition: mutil.h:929
Item m_array[size]
Definition: mutil.h:414
void insert(Item *, long)
Definition: mutil.h:938
~TMValueVector()
Definition: mutil.h:619
Definition: mutil.h:1040
TMValueVector< Item * > m_list
Definition: mutil.h:844
bool Read(IMReadStream &stream)
Definition: mutil.h:527
MDLLEXPORT void MCLSetUTF8Encode(bool b=true)
Definition: mutil.cc:1288
MDLLEXPORT CMStringDictionary & operator=(const CMStringDictionary &dict)
Definition: mutil.cc:1718
bool Write(IMWriteStream &stream)
Definition: mutil.h:1084
void remove(const Item *)
Definition: mutil.h:962
TMBinaryIndexSearcher()
Definition: mutil.h:1364
void removeNoDelete(const Item *)
Definition: mutil.h:983
MDLLEXPORT CMString & operator=(const MCL_TCHAR *)
Definition: mutil.cc:1152
bool Write(const unsigned short &d)
Definition: mutil.h:255
bool Read(unsigned long &d)
Definition: mutil.h:205
bool ReadLine(CMString &d)
Definition: mutil.h:224
TMPtrList()
Definition: mutil.h:852
MDLLEXPORT int getLevel() const
Definition: mutil.h:312
bool Search(long &index, const Item &toFind)
Definition: mutil.h:1421
virtual MDLLEXPORT bool Close()
Definition: mutil.cc:490
bool Read(IMReadStream &)
Definition: mutil.h:1483
virtual MDLLEXPORT ~CMAsciiWriteFileStream()
Definition: mutil.cc:469
Definition: mutil.h:1599
MDLLEXPORT void Print()
Definition: mutil.cc:212
virtual IMWriteStream * CloneAndOpen(const CMString &name)=0
CMString m_fileName
Definition: mutil.h:1179
MDLLEXPORT bool operator!=(const CMString &s1) const
Definition: mutil.cc:1382
MDLLEXPORT CMString()
Definition: mutil.cc:1092
virtual MDLLEXPORT ~CMAsciiReadFileStream()
Definition: mutil.cc:224
#define MDLLEXPORT
Definition: mutil.h:16
MDLLEXPORT CMException(const CMString &error)
Definition: mutil.cc:199
virtual long BytesProcessed()
Definition: mutil.h:1167
virtual bool ReadSimpleType(void *pData, long lenInBytes)=0
bool Peek(const long &index, Item &toFind)
Definition: mutil.h:1577
MDLLEXPORT bool Tokenize(CMPtrStringList &result, const CMString &source, char delimiter= ' ', long limit=0x7FFFFFFF)
Definition: mutil.cc:1493
const Item & operator()(const long index) const
Definition: mutil.h:479
bool Read(char &d)
Definition: mutil.h:213
virtual bool ReadString(CMString &string)
Definition: mutil.cc:908
bool m_bIsOpen
Definition: mutil.h:1299
MDLLEXPORT CMLog & mlog()
Definition: mutil.cc:585
bool Read(int &d)
Definition: mutil.h:207
virtual MDLLEXPORT bool WriteLine(const CMString &line)
Definition: mutil.cc:562
CMStringMap(const CMString &string1, const CMString &string2)
Definition: mutil.h:1105
virtual MDLLEXPORT bool IsEnd()
Definition: mutil.cc:507
MCL_TCHAR * GetMemory(long charLen) const
Definition: mutil.cc:1115
Definition: mutil.h:1191
long & GetVirtualLength()
Definition: mutil.h:1374
Definition: mutil.h:1622
virtual bool WriteSimpleType(const void *pData, long lenInBytes)
Definition: mutil.cc:512
bool Write(const long &d)
Definition: mutil.h:248
Definition: mutil.h:301
MDLLEXPORT long GetVersion()
Definition: mutil.cc:1866
~TMFixedValueVector()
Definition: mutil.h:433
virtual bool IsOpen()=0
virtual MDLLEXPORT ~CMWriteFileStream()
Definition: mutil.cc:962
Definition: mutil.h:198
MDLLEXPORT void toLower()
Definition: mutil.cc:1300
virtual long BytesProcessed()
Definition: mutil.h:1209
MDLLEXPORT CMAsciiWriteFileStream()
Definition: mutil.cc:460
bool Write(const float &d)
Definition: mutil.h:261
long m_revision
Definition: mutil.h:1616
MDLLEXPORT bool IsUTF8(const CMString &string)
Definition: mutil.cc:1650
bool InternalSearch(long &i, const Item &toFind)
Definition: mutil.h:1530
virtual MDLLEXPORT bool IsOpen()
Definition: mutil.cc:995
bool Write(const char &d)
Definition: mutil.h:257
MDLLEXPORT ~CMString()
Definition: mutil.cc:1110
virtual ~IMLogSink()
Definition: mutil.h:289
MDLLEXPORT bool Tokenize(CMPtrStringList &result, const CMString &source)
Definition: mutil.cc:1593
const Item & operator[](const long index) const
Definition: mutil.h:651
virtual bool WriteBlob(const void *pData, long lenInElements, long elSize)
Definition: mutil.cc:1019
virtual MDLLEXPORT bool Close()
Definition: mutil.cc:282
MDLLEXPORT const char * GetUTF8Sig()
Definition: mutil.cc:1645
bool Write(IMWriteStream &stream)
Definition: mutil.h:781
const Item * data() const
Definition: mutil.h:688
virtual bool IsEnd()=0
MDLLEXPORT void SetMemoryManage(bool b=true)
Definition: mutil.cc:1059
bool Read(IMReadStream &stream)
Definition: mutil.h:552
virtual bool WriteStringLine(const CMString &string)
Definition: mutil.h:1293
MDLLEXPORT MCL_TCHAR & operator[](long)
Definition: mutil.cc:1220
const Index IndexToIndex(const long index) const
Definition: mutil.h:1376
Definition: mutil.h:371
MDLLEXPORT bool Write(IMWriteStream &stream)
Definition: mutil.cc:1838
long m_bytesProcessed
Definition: mutil.h:1263
bool m_bIsOpen
Definition: mutil.h:1180
MDLLEXPORT bool MCLIsUTF8Encode()
Definition: mutil.cc:1293
MDLLEXPORT void MLog(const MCL_TCHAR *szText, bool bLineFeed=true)
Definition: mutil.cc:738
TMBinaryIndexSearcher< CMString, long > m_searcher
Definition: mutil.h:1649
bool Write(const void *p, long lenInElements, long elSize=1)
Definition: mutil.h:271
MDLLEXPORT CMFileHeader()
Definition: mutil.cc:1856
virtual ~IMStream()
Definition: mutil.h:182
TMSTValueVector< signed char > CMInt8List
Definition: mutil.h:375
~TMNoOwnPtrList()
Definition: mutil.h:1043
bool Read(float &d)
Definition: mutil.h:217
MDLLEXPORT const CMString & GetErrorText()
Definition: mutil.cc:207
virtual ~IMReadStream()
Definition: mutil.h:202
long m_version
Definition: mutil.h:1615
FILE * m_pFile
Definition: mutil.h:1259
virtual ~IMWriteStream()
Definition: mutil.h:246
MDLLEXPORT CMLog & operator<<(char c)
Definition: mutil.cc:627
~TMBinaryArraySearcher()
Definition: mutil.h:1342
TMPtrList< Item > & operator=(const TMPtrList< Item > &toCopy)
Definition: mutil.h:890
Definition: mutil.h:1233
virtual IMReadStream * CloneAndOpen(const CMString &name)
Definition: mutil.h:1244
Definition: mutil.h:1316
TMSTValueVector< unsigned long > CMUInt32List
Definition: mutil.h:378
MDLLEXPORT ~CMStringDictionary()
Definition: mutil.cc:1705
TMBinaryArraySearcher()
Definition: mutil.h:1341
TMNoOwnPtrList< Item > & operator=(const TMNoOwnPtrList< Item > &toCopy)
Definition: mutil.h:1048
const Item * operator()(const long index) const
Definition: mutil.h:872
FILE * m_pFile
Definition: mutil.h:1219
void removeAll()
Definition: mutil.h:1024
TMBinaryIndexSearcher & operator=(const TMBinaryIndexSearcher &idx)
Definition: mutil.h:1383
bool Write(IMWriteStream &stream)
Definition: mutil.h:535
virtual bool ReadStringLine(CMString &string)
Definition: mutil.cc:349
CMString m_string1
Definition: mutil.h:1120
void SetDataPtr(const TMValueVector< Item > *pSearchList)
Definition: mutil.h:1492