|
Iain,
hmmm. I'll look into that, thanks. It certainly doesn't help matters when the documentation is written in "engrish", with no practical examples.
Regards,
Sternocera
|
|
|
|
|
I've been trying to work out a design problem with one of my pet projects. Essentially, it works on the process of Streams. A program will write to a Stream; this is an abstract class which multiple classes inherit from. For example, a program will write to a Stream, and this could write to either a file or the system console
This all works rather well so far, but one of my additions has made things difficult. This is the daisy-chaining of Streams. A Stream can forward its data onto another Stream. The problem is that this is rather easy to take advantage of. Currently, there's nothing stopping a Stream from forwarding its data to itself, causing a recursive loop. I'm not using Windows in any way, so there's nothing to stop the loop from continuing until the stack overflows into the text segment, rewriting the kernel's code. Is there any way to stop this from happening?
|
|
|
|
|
One way is to only allow daisy-chaining in stream constructors. Then, by definition, you can't daisy chain a stream to itself.
I believe .NET and the Java class library have that restriction on stream daisy-chaining.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
That sounds like it will work. As soon as I implement thread synchronisation, I'll do that. Just one more question though: how would I pass a WriteFormat call down to the chained Stream? I can't pass it in the normal way, because there's no parameter name. I have no va_arg definitions. I'm thinking of something like this:
LinkedStream->WriteFormat(fmt, *((uint *)&fmt + 1))
Would this have any side-effects (disregarding security)?
|
|
|
|
|
Computafreak wrote: I have no va_arg definitions
Why not? Is it a platform limitation?
If there's no other reason, then va_args could work.
Alternatively, you could use operator chaining as with Boost.Format[^]?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
It's quite a mixture. I'm developing an operating system, so haven't added most of the standard definitions. But based upon the #defines it appears to be doing pretty much the same thing as the code snippet I posted. Should it theoretically work? Thanks for the link though, I'm looking through it now; it should be helpful
|
|
|
|
|
Computafreak wrote: But based upon the #defines it appears to be doing pretty much the same thing as the code snippet I posted.
(Presuming you mean va_args) yes, it will be - it's all just stack hackery, which is more dependent on the compiler you're using and hte way it lays out parameters than the OS or anything else really.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
That really helps. I've still got one or two problems, but I'll work through those on my own. Thank you
|
|
|
|
|
I know it doesnt answer all your issues - but maybe you can glean something useful from this :- http://www.codeproject.com/KB/library/ssaxpipe.aspx
'g'
|
|
|
|
|
hiii..i am trying to implement huffman coding for compressing text files...here i have to write bits of variable length into a file...but i am not able to do so...please help...
|
|
|
|
|
krish_amrita wrote: please help...
That will be very difficul since you didn't provide any useful information... What is a bit of variable lenght ?
|
|
|
|
|
Hi,
that is not beginner's stuff.
I did it once, long ago; you need to come up with a way to represent bit strings of limited length.
Here is one way of doing it:
imagine a struct "BITPATTERN" containing:
- int value; // holding up to 32 bits (right-aligned)
- int signif; // holding how many bits of value are significant.
Now implement a CONCAT(BITPATTERN a, BITPATTERN b) function that appends b to a.
The easiest way is by implementing a for loop, iterating over all the bits of b by:
- left-shifting a.value
- incrementing a.signif
- testing one bit of b.value
- if that bit is non-zero incrementing a.value
In addition one has to deal with overflows, i.e. data is not allowed to get lost in a.value while
shifting; one approach is to test for a.signif==8 and store a.value somewhere (to a file), clear it, and reset a.signif inside the CONCAT loop.
Finally, when all concatenations are done, some data may be left in a.value; so some extra zero bits should be concatenated until a.signif becomes 8 and everything gets flushed out.
BTW: you could do similar things using strings containing "0" and "1"; that is slightly easier to code, but far worse as performance goes; and the highest-performance implementations would not have a loop over the significant bits in b, they would use table lookups.
PS: I would expect some implementations to be available on the internet (and a fraction of them to be correct); make Google your friend.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Does this[^] help?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
#pragma once
using namespace std::tr1::function;
template<class _Fty>
class CDelegate : public function<_Fty>
{
public:
explicit CDelegate()
{
this->_Reset();
}
CDelegate(const _Myt& _Right)
{
this->_Reset((const _Mybase&)_Right);
}
//How to write here?
//operator()(****) //many parameters
//{
// m_funcs[0](****); //many parameters
// m_funcs[1](****); //many parameters
//}
~CDelegate()
{
this->_Tidy();
}
protected:
function<_Fty> m_funcs[2];
//reference_wrapper
};
|
|
|
|
|
That's the 'perfect forwarding' problem[^], that will only be solved well with the introduction of rvalue references in C++0x.
I would suggest you take a look at the implementation of Boost.Signals[^] - that does exactly what you're trying to implement (by which I mean the delegate concept).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello everyone,
Thanks a million for all the help you have all provided so far.
I would like to use the CTabCtrl. All the searches and examples I have been through in order for me to use it I have to create a TestTabCtrl class that is derived from CTabCtrl class and create a CPropertyPage class.
Please could someone confirm this for me or have I missed on other ways.
Thanks a million.
|
|
|
|
|
My english is pool, I can't explain for english. so I put code to you!
class CProperty1Dlg : public CDialog
{
// Construction
public:
CProperty1Dlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CProperty1Dlg)
enum { IDD = IDD_PROPERTY1_DIALOG };
CButton m_button2;
CButton m_button1;
CTabCtrl m_tab;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CProperty1Dlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CProperty1Dlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CProperty1Dlg::CProperty1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CProperty1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProperty1Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CProperty1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProperty1Dlg)
DDX_Control(pDX, IDC_BUTTON2, m_button2);
DDX_Control(pDX, IDC_BUTTON1, m_button1);
DDX_Control(pDX, IDC_TAB1, m_tab);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProperty1Dlg, CDialog)
//{{AFX_MSG_MAP(CProperty1Dlg)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProperty1Dlg message handlers
BOOL CProperty1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_tab.InsertItem( 0, _T("Tab1") );
m_tab.InsertItem( 1, _T("Tab2") );
m_button2.ShowWindow( SW_HIDE );
return TRUE; // return TRUE unless you set the focus to a control
}
void CProperty1Dlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int sel = m_tab.GetCurSel();
switch(sel)
{
case 0:
m_button1.ShowWindow( SW_SHOW );
m_button2.ShowWindow( SW_HIDE );
break;
case 1:
m_button2.ShowWindow( SW_SHOW );
m_button1.ShowWindow( SW_HIDE );
break;
}
*pResult = 0;
}
|
|
|
|
|
|
Hello,
I have a CRichEditCtrl box on a CMDIChildWnd. When I move the mouse over this edit box its cursor changes to caret pointer indicating that the box is there. This CMDIChildWnd is made by Create()of CMDIChildWNd
Now when I make a Child window by CreateNewChild() and the add CRichEditCTrl on the childwindow the edit box is seen but when I move the mouse cursor on the edit box the cursor doesnt change to caret pointer .
What is the difference or what must be the problem in making child
windows in diff ways?
Pritha
|
|
|
|
|
how to create 2 state hover button or many state?!!
can one tell me
|
|
|
|
|
If you have another question, click on the "new question" link - but read the "how to get answers" post at the top first. It makes things better for you and us.
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
hi
Can you help in asking the question?!
|
|
|
|
|
I'll try - when you post it as a new question, so other people can try to help / learn from the answers.
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
I sent you the question
If you rewrite it in your own words
thanks
|
|
|
|
|
Hello,
i managed to rotate a rectangle 45 degrees. Now i have an picture that i need to map to this reversed rectangle. I heard there is an inverse mapping way. Something about u and v. I am not familiar with it. Can someone tell me how to use this?
thanks
|
|
|
|