KSquare Utilities
KKStrMatrix.cpp
Go to the documentation of this file.
1 /* KKStrMatrix.cpp -- 2D Matrix of Strings.
2  * Copyright (C) 1994-2014 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 #include "FirstIncludes.h"
6 #include <ctype.h>
7 #include <limits.h>
8 #include <math.h>
9 #include <stdio.h>
10 #include <iostream>
11 #include <memory>
12 #include <sstream>
13 #include <string>
14 #include <vector>
15 
16 #include "MemoryDebug.h"
17 using namespace std;
18 
19 
20 #include "KKStrMatrix.h"
21 using namespace KKB;
22 
23 
24 
26 {
27  if (row >= (kkuint32)data.QueueSize ())
28  {
29  KKStr errMsg = "KKStrMatrix::operator[] Row dimension[" + StrFormatInt (row, "0") + "] invalid; Rows Available["
30  + StrFormatInt (data.QueueSize (), "0") + "]";
31  cerr << errMsg << std::endl;
32  throw errMsg;
33  }
34  return data[row];
35 }
36 
37 
38 
39 
41 {
42  if (row >= (kkuint32)data.QueueSize ())
43  {
44  KKStr errMsg = "KKStrMatrix::operator[] Row dimension[" + StrFormatInt (row, "0") + "] invalid; Rows Available["
45  + StrFormatInt (data.QueueSize (), "0") + "]";
46  cerr << errMsg << std::endl;
47  throw errMsg;
48  }
49  return data[row];
50 }
51 
52 
53 
55  kkuint32 col
56  )
57 {
58  if (row >= (kkuint32)data.QueueSize ())
59  {
60  KKStr errMsg = "KKStrMatrix::operator[] Row dimension[" + StrFormatInt (row, "0") + "] invalid; Rows Available["
61  + StrFormatInt (data.QueueSize (), "0") + "]";
62  cerr << errMsg << std::endl;
63  throw errMsg;
64  }
65 
66  KKStrList& rowOfData = data[row];
67  if (col >= (kkuint32)rowOfData.QueueSize ())
68  {
69  KKStr errMsg = "KKStrMatrix::operator[] Col dimension[" + StrFormatInt (col, "0") + "] invalid; Rows Available["
70  + StrFormatInt (rowOfData.QueueSize (), "0") + "]";
71  cerr << errMsg << std::endl;
72  throw errMsg;
73  }
74 
75  return rowOfData[col];
76 }
77 
78 
79 
80 
81 void KKStrMatrix::AddRow (KKStrListPtr newRowData)
82 {
83  while ((kkuint32)newRowData->QueueSize () < numCols)
84  newRowData->PushOnBack (new KKStr ());
85  data.PushOnBack (newRowData);
86 }
87 
88 
89 
90 void KKStrMatrix::AddRow () // Will add one row of empty Strings
91 {
92  KKStrListPtr newRowData = new KKStrList (true);
93  while ((kkuint32)newRowData->QueueSize () < numCols)
94  newRowData->PushOnBack (new KKStr ());
95  data.PushOnBack (newRowData);
96 }
A two dimensional matrix of Strings.
Definition: KKStrMatrix.h:30
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
KKTHread * KKTHreadPtr
void AddRow(KKStrListPtr newRowData)
Adds a list of Strings to the end of the Matrix.
Definition: KKStrMatrix.cpp:81
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
KKStr & operator()(kkuint32 row, kkuint32 col)
Definition: KKStrMatrix.cpp:54
KKStrList(bool owner)
Definition: KKStr.cpp:4485
KKStrList & operator[](kkuint32 row)
Definition: KKStrMatrix.cpp:25
KKStrList & operator()(kkuint32 row)
Definition: KKStrMatrix.cpp:40
void AddRow()
Adds a row of empty string to the end of the matrix.
Definition: KKStrMatrix.cpp:90