Click here to Skip to main content
15,890,399 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMFC - Printing - Changing page orientation from a custom pagesetup dialog [SOLVED] Pin
Un Suthee31-Jan-11 15:11
Un Suthee31-Jan-11 15:11 
AnswerRe: MFC - Printing - Changing page orientation from a custom pagesetup dialog Pin
Roger Allen2-Feb-11 5:46
Roger Allen2-Feb-11 5:46 
GeneralRe: MFC - Printing - Changing page orientation from a custom pagesetup dialog Pin
Un Suthee3-Feb-11 16:30
Un Suthee3-Feb-11 16:30 
Question2D dynamic wchar array Pin
csrss31-Jan-11 13:30
csrss31-Jan-11 13:30 
AnswerRe: 2D dynamic wchar array Pin
Andrew Brock31-Jan-11 16:41
Andrew Brock31-Jan-11 16:41 
GeneralRe: 2D dynamic wchar array Pin
csrss31-Jan-11 22:35
csrss31-Jan-11 22:35 
AnswerRe: 2D dynamic wchar array [DONE] Pin
csrss1-Feb-11 2:25
csrss1-Feb-11 2:25 
AnswerRe: 2D dynamic wchar array [modified] Pin
Emilio Garavaglia31-Jan-11 20:50
Emilio Garavaglia31-Jan-11 20:50 
An abrupt way of doing this is creating a
std::vector<std::vector<std::string> > and create some functions to properly arrange its sizing taking two parameters (rows and cols).
something like:

C++
#include <vector>
#include <string>

class text_table:
	public std::vector<std::vector<std::wstring > >
{
	typedef std::vector<std::vector<std::wstring > > super;
public:
	typedef std::wstring string_t;
	
	void resize(size_t rows, size_t colums)
	{
		super::resize(rows);
		for(size_t i=0; i<rows; ++i)
			super::at(i).resize(cols);
	}
	
	const string_t& at(size_t rew, size_t col) const
	{ return super::at(row).at(col); }

	string_t& at(size_t rew, size_t col)
	{ return super::at(row).at(col); }
	
};


If you need to return it from a function, probably a std::auto_ptr may avoid the copy-on return of a relatively huge structure.
Something like:

C++
#include <memory>
#include "texttable.h"

std::auto_ptr<text_table> create_table( ... )
{
	std::auto_ptr<text_table> p(new text_table);
	p->resize(...);
	.... //add content initialization stuff
	.... //here, to fill-uip table cell texts
	
	return p;
}


If you want better isolation, you can elaborate by encapsulating (rather then inheriting) the
std::vector<std::vector<std::wstring> > as a private member
and write a brand new interface for all the tex_table operation you may suppose to need.
In that case you can also avoid the use of auto_ptr if you store a pointer (rather than the structure itself) and manage copy and assignment by handling a reference count, and create an effective copy of the data only if the data are shared and needed to be modified.

There are lot of improvements possible!

2 bugs found.
> recompile ...
65534 bugs found.
D'Oh! | :doh:


modified on Tuesday, February 1, 2011 2:58 AM

GeneralRe: 2D dynamic wchar array Pin
csrss31-Jan-11 22:45
csrss31-Jan-11 22:45 
QuestionString array comparison Pin
jharn31-Jan-11 4:48
jharn31-Jan-11 4:48 
QuestionRe: String array comparison Pin
David Crow31-Jan-11 4:57
David Crow31-Jan-11 4:57 
AnswerRe: String array comparison Pin
jharn31-Jan-11 5:08
jharn31-Jan-11 5:08 
AnswerRe: String array comparison Pin
David Crow31-Jan-11 5:41
David Crow31-Jan-11 5:41 
GeneralRe: String array comparison Pin
jharn31-Jan-11 6:09
jharn31-Jan-11 6:09 
GeneralRe: String array comparison Pin
Matthew Barnett1-Feb-11 1:06
Matthew Barnett1-Feb-11 1:06 
AnswerRe: String array comparison Pin
jharn31-Jan-11 5:46
jharn31-Jan-11 5:46 
AnswerRe: String array comparison Pin
David Crow31-Jan-11 6:08
David Crow31-Jan-11 6:08 
GeneralRe: String array comparison Pin
jharn31-Jan-11 6:10
jharn31-Jan-11 6:10 
GeneralRe: String array comparison Pin
jharn31-Jan-11 9:03
jharn31-Jan-11 9:03 
GeneralRe: String array comparison Pin
jsc421-Feb-11 0:13
professionaljsc421-Feb-11 0:13 
QuestionRe: String array comparison Pin
David Crow1-Feb-11 8:51
David Crow1-Feb-11 8:51 
AnswerRe: String array comparison Pin
jsc421-Feb-11 23:36
professionaljsc421-Feb-11 23:36 
AnswerRe: String array comparison Pin
Niklas L31-Jan-11 12:31
Niklas L31-Jan-11 12:31 
GeneralRe: String array comparison Pin
jharn31-Jan-11 12:41
jharn31-Jan-11 12:41 
GeneralRe: String array comparison Pin
KP Lee1-Feb-11 2:22
KP Lee1-Feb-11 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.