|
6Qing88 wrote: I run across a problem, briefly, following the concept that a Linked List is a Collection
of some kind, that is to say, a LinkedList class is derived from a Collection class.
The STL-designers did deliberatly do without a common base class/interface of all STL-collections.
They have, instead devised certain concepts or aspects, which an STL-container "models".
So, a set is a model of "associative container" - without inheriting any interface.
6Qing88 wrote: bool Insert(void *pItem);
Here, templates seem to be the wapon of choice.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
jhwurmbach wrote: without inheriting any interface
That's not proper.
They don't inherit by class inheritance, but they all "inherit" (make use of)a same "interface" (set of public methods) from a common "model" (not a C++ concept, but an abstract concept) so that a generic algorithm can invoke them regardless of the kind of collection you are using. Unless your dealing with specific method not supported by all the collection types.
Template generic programming don't inherits function from the bottom, but construct it on top. But always "inheritance" (in plain English) is.
An "idiot" append algorithm like
template<clas A, class C>
void add(const A& item, C& collection)
{ collection.push_back(item); }
works the same for vector , list , deque , stack .
And does'nt compile for collection that don't support push_back or if you try it with not properly related A and C .
Unfortunately for STL, in all the cases where value semantics is not desirable (i.e: A is a huge structure you don't want to continuously copy), or when classic C++ inheritance is needed, (you need proper translation units, not template instantiation) its not the way to go...
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
You are right, in an implicit, conceptual way, the STL *uses* ihheritance. Or rather common concepts implemented in differnet classes - like iterators.
But it does not use inheritance in the C++-sense, which was the point to make to the OP.
emilio_grv wrote: Unfortunately for STL, in all the cases where value semantics is not desirable (i.e: A is a huge structure you don't want to continuously copy),
In this case, I would use smart-pointers anyway. Preferably in some Interface-based-programming-style.
emilio_grv wrote: or when classic C++ inheritance is needed, (you need proper translation units, not template instantiation)
Yes - STL-containers in module interfaces are very tricky. E.G. in a DLL-interface: sometimes it works, sometimes not.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
jhwurmbach wrote: In this case, I would use smart-pointers anyway
Sure. but this introduce a level of indirection that influence the algorithm semantics
(like
for(mylist::iterator i=alist.begin(); i!=alist.end(); ++i) (**i).do_something(.); )
(note there's two "*", so the algorithm where the "for" is, must be designed to track that,
or you've to design algorithms to have an extra "traits" parameter to define how to handle the dereference e the dereferenced type, that list is not directly aware of).
in other words, there is always something missing, whether the approach is.
What we can do is choose what to miss.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
emilio_grv wrote: in other words, there is always something missing, whether the approach is. What we can do is choose what to miss.
There is something deeply philosophical in this words.
But yes, you are right: There is no one size fits all - Tool. Which makes much of our qualification.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
you're talking about a "type-dependent" type.
Templates are the right way to go.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
I wanto an edit box which takes only numbers and special character.
Is there a property that can be set like we have 'numbers' or do i have to make my logic inside?
KIRAN PINJARLA
|
|
|
|
|
A raw sample code for filtering the space may look like...
BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
if( pMsg->hwnd == GetDlgItem( IDC_EDIT1 )->m_hWnd )
{
if( pMsg->wParam == VK_SPACE )
{
pMsg->message = WM_NULL;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
- NS -
|
|
|
|
|
you do have to write your own logic for that.
i can share it with you if you come back with the actual requirement with an example.
|
|
|
|
|
I have to create login codes which will contain only numbers and special characters like *,#,$,+,-. So i want the edit control to accept only therse characters and numbers.
-- modified at 3:16 Friday 31st August, 2007
KIRAN PINJARLA
|
|
|
|
|
use onchange event of the edit box.
in that box, keep scanning the string available in the edit box.
there if you find any un required character,
simply, update the edit box with a new string, which omits that character.
ultimately, you will get the output as if the un desired characters are not being taken by the control.
-- modified at 3:37 Friday 31st August, 2007
|
|
|
|
|
Windows hooking mechnism may be desired to solve your problem.
|
|
|
|
|
I am afraid that is bulky... since there are simple solutions.
- NS -
|
|
|
|
|
Why?
Wouldn't subclassing be much easier?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
kiran.pinjarla wrote: I wanto an edit box which takes only numbers and special character.
You can have a edit box that takes only numbers. No way of inserting "-1.0".
Useless crap. One of the larest omissions in the Windows GUI-classes.
For usable numeric edit fields, scan the "controls"-section of codeproject.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Create a new class with base class CEdit and override the OnChar event handler.
void CharEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ( (nChar >= 65 && nChar <= 90) || (nChar >= 97 && nChar <= 122))
{
MessageBeep ( 0 ) ;
return ;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
Thats it.
|
|
|
|
|
Search for Masked Edit controls on CP, there are a bunch of articles doing subclassed edit controls to do what you want.
Iain.
|
|
|
|
|
Dear Friends,
Using a thread i m writting a file and i want to wait untill the file is written.
For this i have used WaitForSingleObject but its not working..
here is the code
MAIN FILE
pApp->m_hEvent = ::CreateEvent(NULL, FALSE, FALSE, "FileEvent");
pSLMDoc->UpdateJobOrderInfo(m_pJobOrderInfo);
WaitForSingleObject(pApp->m_hEvent, INFINITE);
if (file.Open(strFileName, CFile::modeRead, &e) == FALSE)
{
AfxMessageBox(e.m_cause);
}
UINT nRet = file.Read(pFileJobOrder, sizeof(FILE_JOBORDER));
IN THREAD FILE
CBackupFile file;
file.WriteFile(pDBJobOrder);
delete pDBJobOrder;
::SetEvent( ((CSLMApp*) AfxGetApp())->m_hEvent );
return;
It is not wating till the time file writing is going on. And then it will throw an error in file opening..
Can u plz help me.. if u need any more input plzz tell me
Megha
|
|
|
|
|
definitely, i can solve this coz, i also faced these such problems in past.
but please let me know the purpose and architecture of your program.
|
|
|
|
|
In Main File
In my application on click of a button, i'l check if DB connection is there. if its not then
pApp->m_hEvent = ::CreateEvent(NULL, FALSE, FALSE, "FileEvent");
pSLMDoc->UpdateJobOrderInfo(m_pJobOrderInfo); //This fuction starts a thread to write a file.
In the thread File
CBackupFile file;
file.WriteFile(pDBJobOrder); //Calls a fuction to write a file
delete pDBJobOrder;
::SetEvent( ((CSLMApp*) AfxGetApp())->m_hEvent ); // Set the event
return;
I want to wait untill this thread executes.. but it is not happening...
Did u get my problem..
megha
|
|
|
|
|
you mean, you want to wait in the button till the thread comletes. am i right?
|
|
|
|
|
Often, if you have/want to wait for another thread to execute, you don't need another thread.
If the creating thread can't continue executing until the second thread finishes, do you
really need another thread?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
try to follow this algorithm.
int flag=0;//global variable
button code
{
pApp->m_hEvent = ::CreateEvent(NULL, FALSE,
FALSE, "FileEvent");
pSLMDoc->UpdateJobOrderInfo(m_pJobOrderInfo); //This
fuction starts a thread to write a file.
while(flag==0);//wait till flag is made 1.
}
thread code
{
//perform your writing here
then at the end of the thread, make flag=1;
}
}
|
|
|
|
|
I tried this one
It is working.
Thank u
|
|
|
|
|
If this is the solution, then what is the use of events...
- NS -
|
|
|
|
|