s_matrix 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddd7b70b9a3b6c868d129880f137d14ef5a02e0c
4
- data.tar.gz: 24ca4639f1bd9e59266d1e0b2606e8bf0e1b0663
3
+ metadata.gz: e3c71d1514129d41285ca6bcdba7675d8c679a15
4
+ data.tar.gz: 1d805c4c4711ab18cf4265db484c59bfd7aba042
5
5
  SHA512:
6
- metadata.gz: 1b7d99f393d498a2638ece03b1d71c18f88a22414ad1186fe5c5672f4e164a14b793c1eefb4ef5f628beb13934797e3e309601b1237d1874ad553576797227f0
7
- data.tar.gz: 977d508e6a1bd2f163bba07616d6872d105468954e987401504831888220f1dc1148e2ced17560f2cd2b57a0dbd770a9cdabe58156098cbe65c09b4ff5edbb09
6
+ metadata.gz: ce62e5637c30997f00aea492b231b2076f0e4880e052204b648a02bf5e1ac241469134c7adf92250cc2a9c55a2931866ca9c220efd55c383452ce456503c3d83
7
+ data.tar.gz: d5dc439be30b0d6ba4284de0c9ae5d1de460361395ecc1083bbae105dcb87e5771fea1fc224465474d1473fef98b464f0b494cbecf78a8e9224a85e188a99414
data/.gitignore CHANGED
@@ -26,3 +26,9 @@
26
26
  *.exe
27
27
  *.out
28
28
  *.app
29
+
30
+ Gemfile.lock
31
+ *.gem
32
+ tags
33
+ tmp
34
+ s_matrix.bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in s_matrix.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -27,3 +27,10 @@ TODO: Write usage instructions here
27
27
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
28
  4. Push to the branch (`git push origin my-new-feature`)
29
29
  5. Create a new Pull Request
30
+
31
+ gem build s_matrix.gemspec
32
+
33
+ gem install ./s_matrix-0.0.1.gem # please change version number to current one.
34
+
35
+ gem push s_matrix-0.0.1.gem
36
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/extensiontask'
4
+
5
+ Rake::ExtensionTask.new "s_matrix" do |ext|
6
+ ext.ext_dir = 'ext/s_matrix'
7
+ ext.lib_dir = "lib/s_matrix"
8
+ end
9
+
10
+ #Rake::ExtensionTask.new('s_matrix')
11
+
@@ -0,0 +1,239 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@:)
9
+ ECHO = $(ECHO1:0=@echo)
10
+
11
+ #### Start of system configuration section. ####
12
+
13
+ srcdir = .
14
+ topdir = /Users/zhangyuan/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0
15
+ hdrdir = $(topdir)
16
+ arch_hdrdir = /Users/zhangyuan/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/x86_64-darwin13.0
17
+ PATH_SEPARATOR = :
18
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
19
+ prefix = $(DESTDIR)/Users/zhangyuan/.rvm/rubies/ruby-2.1.0
20
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
21
+ rubyarchprefix = $(rubylibprefix)/$(arch)
22
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
23
+ exec_prefix = $(prefix)
24
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
25
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
26
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
27
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
28
+ sitehdrdir = $(rubyhdrdir)/site_ruby
29
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
30
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
31
+ vendorlibdir = $(vendordir)/$(ruby_version)
32
+ vendordir = $(rubylibprefix)/vendor_ruby
33
+ sitearchdir = $(sitelibdir)/$(sitearch)
34
+ sitelibdir = $(sitedir)/$(ruby_version)
35
+ sitedir = $(rubylibprefix)/site_ruby
36
+ rubyarchdir = $(rubylibdir)/$(arch)
37
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
38
+ sitearchincludedir = $(includedir)/$(sitearch)
39
+ archincludedir = $(includedir)/$(arch)
40
+ sitearchlibdir = $(libdir)/$(sitearch)
41
+ archlibdir = $(libdir)/$(arch)
42
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
43
+ mandir = $(datarootdir)/man
44
+ localedir = $(datarootdir)/locale
45
+ libdir = $(exec_prefix)/lib
46
+ psdir = $(docdir)
47
+ pdfdir = $(docdir)
48
+ dvidir = $(docdir)
49
+ htmldir = $(docdir)
50
+ infodir = $(datarootdir)/info
51
+ docdir = $(datarootdir)/doc/$(PACKAGE)
52
+ oldincludedir = $(DESTDIR)/usr/include
53
+ includedir = $(prefix)/include
54
+ localstatedir = $(prefix)/var
55
+ sharedstatedir = $(prefix)/com
56
+ sysconfdir = $(prefix)/etc
57
+ datadir = $(datarootdir)
58
+ datarootdir = $(prefix)/share
59
+ libexecdir = $(exec_prefix)/libexec
60
+ sbindir = $(exec_prefix)/sbin
61
+ bindir = $(exec_prefix)/bin
62
+ archdir = $(rubyarchdir)
63
+
64
+
65
+ CC = gcc
66
+ CXX = g++
67
+ LIBRUBY = $(LIBRUBY_SO)
68
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
69
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
70
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation
71
+ empty =
72
+ OUTFLAG = -o $(empty)
73
+ COUTFLAG = -o $(empty)
74
+
75
+ RUBY_EXTCONF_H =
76
+ cflags = $(optflags) $(debugflags) $(warnflags)
77
+ optflags = -O3 -fno-fast-math
78
+ debugflags = -ggdb3
79
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wextra-tokens
80
+ CCDLFLAGS = -fno-common
81
+ CFLAGS = $(CCDLFLAGS) $(cflags) -fno-common -pipe -Wall $(ARCH_FLAG)
82
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
83
+ DEFS =
84
+ CPPFLAGS = -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
85
+ CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
86
+ ldflags = -L. -fstack-protector -L/usr/local/lib
87
+ dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
88
+ ARCH_FLAG =
89
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
90
+ LDSHARED = $(CC) -dynamic -bundle
91
+ LDSHAREDXX = $(CXX) -dynamic -bundle
92
+ AR = ar
93
+ EXEEXT =
94
+
95
+ RUBY_INSTALL_NAME = ruby
96
+ RUBY_SO_NAME = ruby.2.1.0
97
+ RUBYW_INSTALL_NAME =
98
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
99
+ RUBYW_BASE_NAME = rubyw
100
+ RUBY_BASE_NAME = ruby
101
+
102
+ arch = x86_64-darwin13.0
103
+ sitearch = $(arch)
104
+ ruby_version = 2.1.0
105
+ ruby = $(bindir)/ruby
106
+ RUBY = $(ruby)
107
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
108
+
109
+ RM = rm -f
110
+ RM_RF = $(RUBY) -run -e rm -- -rf
111
+ RMDIRS = rmdir -p
112
+ MAKEDIRS = mkdir -p
113
+ INSTALL = /usr/bin/install -c
114
+ INSTALL_PROG = $(INSTALL) -m 0755
115
+ INSTALL_DATA = $(INSTALL) -m 644
116
+ COPY = cp
117
+ TOUCH = exit >
118
+
119
+ #### End of system configuration section. ####
120
+
121
+ preload =
122
+
123
+ libpath = . $(libdir) /usr/local/opt/libyaml/lib /usr/local/opt/readline/lib /usr/local/opt/libksba/lib /usr/local/opt/openssl/lib
124
+ LIBPATH = -L. -L$(libdir) -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib
125
+ DEFFILE =
126
+
127
+ CLEANFILES = mkmf.log
128
+ DISTCLEANFILES =
129
+ DISTCLEANDIRS =
130
+
131
+ extout =
132
+ extout_prefix =
133
+ target_prefix = /s_matrix
134
+ LOCAL_LIBS =
135
+ LIBS = $(LIBRUBYARG_SHARED) -lstdc++ -lpthread -ldl -lobjc
136
+ ORIG_SRCS = gmatx.cpp s_matrix.cpp
137
+ SRCS = $(ORIG_SRCS)
138
+ OBJS = gmatx.o s_matrix.o
139
+ HDRS = $(srcdir)/gmatx.h
140
+ TARGET = s_matrix
141
+ TARGET_NAME = s_matrix
142
+ TARGET_ENTRY = Init_$(TARGET_NAME)
143
+ DLLIB = $(TARGET).bundle
144
+ EXTSTATIC =
145
+ STATIC_LIB =
146
+
147
+ TIMESTAMP_DIR = .
148
+ BINDIR = $(bindir)
149
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
150
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
151
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
152
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
153
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
154
+
155
+ TARGET_SO = $(DLLIB)
156
+ CLEANLIBS = $(TARGET).bundle
157
+ CLEANOBJS = *.o *.bak
158
+
159
+ all: $(DLLIB)
160
+ static: $(STATIC_LIB)
161
+ .PHONY: all install static install-so install-rb
162
+ .PHONY: clean clean-so clean-static clean-rb
163
+
164
+ clean-static::
165
+ clean-rb-default::
166
+ clean-rb::
167
+ clean-so::
168
+ clean: clean-so clean-static clean-rb-default clean-rb
169
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
170
+
171
+ distclean-rb-default::
172
+ distclean-rb::
173
+ distclean-so::
174
+ distclean-static::
175
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
176
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
177
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
178
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
179
+
180
+ realclean: distclean
181
+ install: install-so install-rb
182
+
183
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.-.s_matrix.time
184
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
185
+ clean-static::
186
+ -$(Q)$(RM) $(STATIC_LIB)
187
+ install-rb: pre-install-rb install-rb-default
188
+ install-rb-default: pre-install-rb-default
189
+ pre-install-rb: Makefile
190
+ pre-install-rb-default: Makefile
191
+ pre-install-rb-default:
192
+ $(ECHO) installing default s_matrix libraries
193
+ $(TIMESTAMP_DIR)/.RUBYARCHDIR.-.s_matrix.time:
194
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
195
+ $(Q) $(TOUCH) $@
196
+
197
+ site-install: site-install-so site-install-rb
198
+ site-install-so: install-so
199
+ site-install-rb: install-rb
200
+
201
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
202
+
203
+ .cc.o:
204
+ $(ECHO) compiling $(<)
205
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
206
+
207
+ .mm.o:
208
+ $(ECHO) compiling $(<)
209
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
210
+
211
+ .cxx.o:
212
+ $(ECHO) compiling $(<)
213
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
214
+
215
+ .cpp.o:
216
+ $(ECHO) compiling $(<)
217
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
218
+
219
+ .C.o:
220
+ $(ECHO) compiling $(<)
221
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
222
+
223
+ .c.o:
224
+ $(ECHO) compiling $(<)
225
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
226
+
227
+ .m.o:
228
+ $(ECHO) compiling $(<)
229
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
230
+
231
+ $(DLLIB): $(OBJS) Makefile
232
+ $(ECHO) linking shared-object s_matrix/$(DLLIB)
233
+ -$(Q)$(RM) $(@)
234
+ $(Q) $(LDSHAREDXX) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
235
+ $(Q) $(POSTLINK)
236
+
237
+
238
+
239
+ $(OBJS): $(HDRS) $(ruby_headers)
@@ -0,0 +1,15 @@
1
+ #---
2
+ # Excerpted from "Programming Ruby 1.9",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/ruby3 for more book information.
8
+ #---
9
+ require 'mkmf'
10
+
11
+ have_library( 'stdc++' );
12
+ $CFLAGS << " -Wall"
13
+
14
+
15
+ create_makefile("s_matrix/s_matrix")
@@ -0,0 +1,66 @@
1
+ #include <assert.h>
2
+ #include <sstream>
3
+
4
+ #include "gmatx.h"
5
+ #include "stdio.h"
6
+
7
+
8
+ GMatx::GMatx(void)
9
+ {
10
+ }
11
+
12
+ void GMatx::add_row(const std::string& id, const t_key_value_hash& row_content)
13
+ {
14
+ // 处理新增的title
15
+ //
16
+ for (t_key_value_hash::const_iterator iter = row_content.begin();
17
+ iter != row_content.end(); ++iter)
18
+ {
19
+ const std::string& title = iter->first;
20
+ if (m_titles.is_title_exist(title) == false)
21
+ m_titles.add_title(title);
22
+ }
23
+
24
+ // 加到content中
25
+ //
26
+ m_contents.set_row_with_order(id, row_content, m_titles.get_titles());
27
+ }
28
+
29
+ t_key_value_hash GMatx::get_row(const std::string& id) const
30
+ {
31
+ t_key_value_hash result;
32
+ const std::vector<std::string>& titles = m_titles.get_titles();
33
+ const MatxRow& row = m_contents.get_row(id);
34
+ if (&row == &MatxRow::null_row)
35
+ return result;
36
+
37
+ return row.to_key_value_hash(titles);
38
+ }
39
+
40
+ // typedef void (*each_call_func)(const std::string& /*key*/, const t_key_value_hash& /*row_content*/);
41
+ void GMatx::each_call(each_call_func func) const
42
+ {
43
+ const std::vector<std::string>& titles = m_titles.get_titles();
44
+ for (std::map<std::string /* id */, MatxRow>::const_iterator iter = m_contents.begin();
45
+ iter != m_contents.end(); ++iter)
46
+ {
47
+ const std::string& id = iter->first;
48
+ const MatxRow& row = iter->second;
49
+ func(id, row.to_key_value_hash(titles));
50
+ }
51
+ }
52
+
53
+ std::string GMatx::to_s(void) const
54
+ {
55
+ std::ostringstream ret;
56
+ ret << "GMatx: " << m_contents.size() << '\n';
57
+
58
+ const std::vector<std::string>& titles = m_titles.get_titles();
59
+ ret << m_contents.to_s(titles);
60
+ return ret.str();
61
+ }
62
+
63
+ size_t GMatx::size(void) const
64
+ {
65
+ return m_contents.size();
66
+ }
@@ -0,0 +1,28 @@
1
+ #ifndef _GMATX_H_
2
+ #define _GMATX_H_
3
+
4
+ #include "matx_title.h"
5
+ #include "matx_content.h"
6
+ #include "matx_type_def.h"
7
+
8
+ class GMatx
9
+ {
10
+ public:
11
+ GMatx(void);
12
+
13
+ void add_row(const std::string& id, const t_key_value_hash& row_content);
14
+
15
+ // 当找不到id所对应的行时,返回的t_key_value_hash数据的size=0
16
+ t_key_value_hash get_row(const std::string& id) const;
17
+ std::string to_s(void) const;
18
+ size_t size(void) const;
19
+
20
+ typedef void (*each_call_func)(const std::string& /*key*/, const t_key_value_hash& /*row_content*/);
21
+ void each_call(each_call_func func) const;
22
+
23
+ private:
24
+ MatxTitle m_titles;
25
+ MatxContent m_contents;
26
+ };
27
+
28
+ #endif
@@ -0,0 +1,82 @@
1
+ #include <sstream>
2
+
3
+ #include "matx_content.h"
4
+ #include "stdio.h"
5
+
6
+
7
+ MatxContent::MatxContent(void)
8
+ {
9
+ }
10
+
11
+ const MatxRow& MatxContent::get_row(const std::string& id) const
12
+ {
13
+ std::map<std::string, MatxRow>::const_iterator iter = m_rows.find(id);
14
+ if (iter == m_rows.end())
15
+ return MatxRow::null_row;
16
+
17
+ return iter->second;
18
+ }
19
+
20
+ const std::map<std::string /* id */, MatxRow>::const_iterator MatxContent::begin(void) const
21
+ {
22
+ return m_rows.begin();
23
+ }
24
+
25
+ const std::map<std::string /* id */, MatxRow>::const_iterator MatxContent::end(void) const
26
+ {
27
+ return m_rows.end();
28
+ }
29
+
30
+ size_t MatxContent::size(void) const
31
+ {
32
+ return m_rows.size();
33
+ }
34
+
35
+ void MatxContent::set_row(const std::string& id, const MatxRow& row)
36
+ {
37
+ m_rows[id] = row;
38
+ }
39
+
40
+ std::string MatxContent::to_s(const std::vector<std::string>& titles) const
41
+ {
42
+ std::ostringstream ret;
43
+ std::map<std::string, MatxRow>::const_iterator iter;
44
+ for (iter = m_rows.begin(); iter != m_rows.end(); ++iter)
45
+ {
46
+ const std::string& id = iter->first;
47
+ const MatxRow& row = iter->second;
48
+
49
+ ret << " \"" << id << "\"\n";
50
+
51
+ const std::vector<std::string>& values = row.get_values();
52
+ for (size_t i = 0; i < values.size(); ++i)
53
+ {
54
+ const std::string& value = values[i];
55
+ std::string value_show = (value == MatxRow::null_string ? "nil" : value);
56
+ ret << " -- \"" << titles[i] << "\" \"" << value_show << "\"\n";
57
+ }
58
+
59
+ }
60
+ return ret.str();
61
+ }
62
+
63
+ void MatxContent::set_row_with_order(const std::string& id, const t_key_value_hash& row_content, const std::vector<std::string>& titles_for_order)
64
+ {
65
+ // 根据titles_for_order的顺序,组装出value
66
+ std::vector<std::string> values;
67
+ for (std::vector<std::string>::const_iterator iter = titles_for_order.begin();
68
+ iter != titles_for_order.end(); ++iter)
69
+ {
70
+ const std::string& title = *iter;
71
+ t_key_value_hash::const_iterator content_iter = row_content.find(title);
72
+ if (content_iter == row_content.end())
73
+ {
74
+ values.push_back(MatxRow::null_string); // 没有的项目,使用nil字符串来保存
75
+ }
76
+ else
77
+ values.push_back(content_iter->second);
78
+ }
79
+
80
+ // 保存行
81
+ m_rows[id] = MatxRow(values);
82
+ }
@@ -0,0 +1,32 @@
1
+ #ifndef _MATX_CONTENT_H_
2
+ #define _MATX_CONTENT_H_
3
+
4
+ #include <string>
5
+ #include <map>
6
+ #include "matx_row.h"
7
+ #include "matx_type_def.h"
8
+
9
+ class MatxContent
10
+ {
11
+ public:
12
+ MatxContent(void);
13
+
14
+ // 按照titles_for_order中的顺序,格式化row_content中的内容,来设置新行
15
+ void set_row_with_order(const std::string& id, const t_key_value_hash& row_content, const std::vector<std::string>& titles_for_order);
16
+
17
+ const MatxRow& get_row(const std::string& id) const;
18
+ void set_row(const std::string& id, const MatxRow& row);
19
+
20
+ const std::map<std::string /* id */, MatxRow>::const_iterator begin(void) const;
21
+ const std::map<std::string /* id */, MatxRow>::const_iterator end(void) const;
22
+
23
+ std::string to_s(const std::vector<std::string>& titles) const;
24
+ size_t size(void) const;
25
+
26
+ private:
27
+ std::map<std::string /* id */, MatxRow> m_rows; // each row of this matrix
28
+ };
29
+
30
+
31
+
32
+ #endif // _MATX_CONTENT_H_
@@ -0,0 +1,97 @@
1
+ #include <assert.h>
2
+ #include "matx_row.h"
3
+ #include "stdio.h"
4
+
5
+ MatxRow MatxRow::null_row = MatxRow();
6
+ std::string MatxRow::null_string(")(=+matx_null#!^&");
7
+ static std::string empty_string;
8
+
9
+ MatxRow::MatxRow(void)
10
+ {
11
+ }
12
+
13
+ MatxRow::MatxRow(const MatxRow& r)
14
+ {
15
+ *this = r;
16
+ }
17
+
18
+ MatxRow& MatxRow::operator=(const MatxRow& r)
19
+ {
20
+ if (&r == this)
21
+ return *this;
22
+ set_values(r.get_values());
23
+ return *this;
24
+ }
25
+
26
+ MatxRow::MatxRow(const std::vector<std::string>& values)
27
+ {
28
+ set_values(values);
29
+ }
30
+
31
+ MatxRow::~MatxRow()
32
+ {
33
+ reset_container();
34
+ }
35
+
36
+ void MatxRow::reset_container(void)
37
+ {
38
+ for (size_t i = 0; i < m_values.size(); ++i)
39
+ {
40
+ std::string* pStr = m_values[i];
41
+ if (pStr != &null_string && pStr != &empty_string)
42
+ delete pStr;
43
+ }
44
+ m_values.clear();
45
+ }
46
+
47
+ void MatxRow::set_values(const std::vector<std::string>& values)
48
+ {
49
+ reset_container();
50
+ for (size_t i = 0; i < values.size(); ++i)
51
+ {
52
+ const std::string& value = values[i];
53
+ if (value.size() == 0)
54
+ m_values.push_back(&empty_string);
55
+ else if (value == MatxRow::null_string)
56
+ m_values.push_back(&null_string);
57
+ else
58
+ {
59
+ std::string* pValue = new std::string(value);
60
+ m_values.push_back(pValue);
61
+ }
62
+ }
63
+ }
64
+
65
+ std::vector<std::string> MatxRow::get_values(void) const
66
+ {
67
+ std::vector<std::string> values;
68
+ for (size_t i = 0; i < m_values.size(); ++i)
69
+ values.push_back(*m_values[i]);
70
+ return values;
71
+ }
72
+
73
+ const std::string& MatxRow::operator[](size_t index) const
74
+ {
75
+ if (index >= m_values.size())
76
+ return null_string;
77
+ return *m_values[index];
78
+ }
79
+
80
+ t_key_value_hash MatxRow::to_key_value_hash(const std::vector<std::string>& titles) const
81
+ {
82
+ t_key_value_hash result;
83
+ const std::vector<std::string>& values = get_values();
84
+ assert(titles.size() >= values.size());
85
+
86
+ for (size_t i = 0; i < titles.size(); ++i)
87
+ {
88
+ const std::string& title = titles[i];
89
+ if (i < values.size())
90
+ result[title] = values[i];
91
+ else
92
+ result[title] = MatxRow::null_string;
93
+ }
94
+ return result;
95
+ }
96
+
97
+
@@ -0,0 +1,36 @@
1
+ #ifndef _MATX_ROW_H_
2
+ #define _MATX_ROW_H_
3
+
4
+ #include <string>
5
+ #include <vector>
6
+ #include "matx_string.h"
7
+ #include "matx_type_def.h"
8
+
9
+ class MatxRow
10
+ {
11
+ public:
12
+ static MatxRow null_row;
13
+ static std::string null_string;
14
+
15
+ MatxRow(void);
16
+ MatxRow(const MatxRow& r);
17
+ MatxRow(const std::vector<std::string>& values);
18
+ ~MatxRow();
19
+
20
+ MatxRow& operator=(const MatxRow& r);
21
+
22
+ void set_values(const std::vector<std::string>& values);
23
+ std::vector<std::string> get_values(void) const;
24
+ const std::string& operator[](size_t index) const;
25
+ t_key_value_hash to_key_value_hash(const std::vector<std::string>& titles) const;
26
+
27
+ private:
28
+ void reset_container(void);
29
+
30
+ private:
31
+ std::vector<matx_string*> m_values; // values in one row
32
+ };
33
+
34
+
35
+
36
+ #endif // _MATX_ROW_H_
@@ -0,0 +1,7 @@
1
+ #ifndef _MATX_STRING_H_
2
+ #define _MATX_STRING_H_
3
+
4
+ typedef std::string matx_string;
5
+
6
+
7
+ #endif // _MATX_STRING_H_
@@ -0,0 +1,30 @@
1
+ #include "matx_title.h"
2
+ #include <algorithm>
3
+ #include <stdio.h>
4
+
5
+
6
+ MatxTitle::MatxTitle(void)
7
+ {
8
+ }
9
+
10
+
11
+ void MatxTitle::add_title(const std::string& title)
12
+ {
13
+ m_titles.push_back(title);
14
+ }
15
+
16
+ const std::vector<std::string>& MatxTitle::get_titles(void) const
17
+ {
18
+ return m_titles;
19
+ }
20
+
21
+ const std::string& MatxTitle::operator[](size_t index) const
22
+ {
23
+ return m_titles[index];
24
+ }
25
+
26
+ bool MatxTitle::is_title_exist(const std::string& title) const
27
+ {
28
+ std::vector<std::string>::const_iterator iter = find(m_titles.begin(), m_titles.end(), title);
29
+ return (iter != m_titles.end());
30
+ }