|
boost.org has a tree class I beleive.
Todd Smith
|
|
|
|
|
Look up Red-Black tree on Google, that is what STL uses for its internal tree mechanism.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Do you need a specialized tree such a binary search tree or a general n-tree?
A general n-tree can be hacked up as:
template <typename T>
struct Node {
T data;
Node* parent;
std::list<Node*> children;
};
template <typename T>
Tree_AppendChild(Node<T>* node, const T& value) {
...
}
template <typename T>
Tree_InsertChild(Node<T>* node, const T& value, int pos) {
...
}
And then you could of course wrap all this into a single class if you want a more object-oriented approach.
N.B. you need to interpret (Node*)NULL as the base case - an empty tree.
--
Only in a world this sh*tty could you even try to say these were innocent people and keep a straight face.
|
|
|
|
|
I'm completely new to ATL . I use VB. I know C++ && API. I have next
questions:
1.How do I define and raise an event from a class defined inside atl.
2.How do I raise errors to the clients that use my DLL.
I'd appreciate if you give me some MSDN refferences or even articles inside CodeProject.
- Any suggestions how to make subclassing for a window through the pass of hWnd parameter inside an ATL DLL? (I have some ideas that worked well under vb using API functions but I really appreciate the experience of the coders that visit this site, so I expect your opinion.)
- I want to use ATL to build an DLL that takes as parameter the hWnd and subclass certain messages secified through an AttachMessage method. When the message is received I want to raise an event WndProc(...) into the caller.
Thanx to all of you. I have a lot to learn from you.
Cosmin Amza
|
|
|
|
|
Answer
Q1.http://msdn.microsoft.com/library/en-ccore/html/vcconATLEventHandling.asp
Q2.AtlReportError() or CComCoClass::Error()
|
|
|
|
|
When i select the object as internetexplorerobject,i would like to call the setsite function onstartup.
How should i call that function.
|
|
|
|
|
Hello.
I have an ActiveX control which I run in Internet Explorer. I want to be able to do some
changes it the html when the control is closed.
I have seen a code example on MSDN:
CComPtr<IOleContainer> spContainer; <br />
m_spClientSite->GetContainer(&spContainer); <br />
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spDoc(spContainer); <br />
if (spDoc)<br />
spDoc->put_bgColor(CComBSTR(_T("pink")));
My problem is I don't know how to obtain the member variable m_spClientSite. Do I have to
implement an interface to use this variable? I tried to include <atlctl.h> but that gave me
a lot of errors.
Any help is greatly appriciated.
Thanks in advance.
/Charlie.
|
|
|
|
|
Hmm, I though I answered this already
m_spClientSite is a member of CComControlBase and as you placed this to ATL forum, I expect, you did that in ATL, so only thing you have to do in your ATL component, which is derived from the CCCBase, is to enjoy using the member
|
|
|
|
|
Hello.
I have an ATL-object in my project, I guess that's not enough then...
Thanks anyway.
|
|
|
|
|
Then if your object is derived from IOleObjectImpl, you have the GetClientSite() possibility (see IOleObjectImpl::GetClientSite() in ATL Library Reference
|
|
|
|
|
find_if is no better than running down the collection yourself, comparing items.
is there anything that will do a binary search (with a predicate) on a sorted vector?
please don't say "binary_search" because that is a totally useless P.O.S. that only tells you if an item exists in the collection (it returns bool)- it doesn't actually give you the item. "Q: can you tell me what time it is? A: yes".
-c
There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'.
--Holgate, from Plastic
|
|
|
|
|
You might be able to use lower_bound() or equal_range()?
I'd wear a miniskirt and pimp myself for an extra ten grand a year. - David Wulff
Awasu[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
close. but lower_bound doesn't really do a search. it just tells you where you could insert a new item. or, from MSDN: "[lower_bound] determines the lowest position before which val can be inserted in the sequence and still preserve its ordering".
i really need it to return the item i'm searching for, not the next-lowest value.
-c
There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'.
--Holgate, from Plastic
|
|
|
|
|
Chris Losinger wrote:
but lower_bound doesn't really do a search.
That's right but I was thinking you could check the *next* element to see if it's the one you want.
note to self: but this doesn't work if the item is not present!
[edit] hmmm... may it does. doesn't matter - equal_range() seems to be the ticket anyway.
Isn't equal_range() exactly what you want anyway? A quick test seems to show that it returns (x,x+1) if you're looking for x and find it or (end,end) if it's not present.
he he he. I like it in the kitchen! - Marc Clifton (on being flamed)
Awasu[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
nope. equal_range is just like lower_bound, but with a span, instead of a single position:
"the function determines the largest range of positions over which val can be inserted in the sequence and still preserve its ordering"
my vector has X elements. each element has an integer member variable that i'm ordering, and searching by. the less than operator for these elements only looks at the ordering and searching integer, nothing else. in the case i'm testing, these values range from 10 to 170.
if i do an equal_range "search" (or lower_bound) for "0", i get an iterator for the first element in the sequence, the one that contains "10".
i suppose i can test that iterator to see if the element is actually the one i'm searching for. but it seems like a huge hole in the STL, to not provide a binary search on a sorted collection.
oh well. guess i'll write my own.
-c
There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'.
--Holgate, from Plastic
|
|
|
|
|
Then MSDN is misleading. ForwardIterator lower_bound(ForwardIterator beg, ForwardIterator end, const T& value, BinaryPredicate op) returns the position of the first element with value equal or greater than value . Just add a comparision and you have the search function you need.
|
|
|
|
|
yeah, that's basically what i ended up doing; i combined the lower_bound code with the equality test into a new function, and named it appropriately: "vector_binary_search".
-c
There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'.
--Holgate, from Plastic
|
|
|
|
|
Chris Losinger wrote:
please don't say "binary_search"
How about bin_search? This should return the position in the vector if that is any better?
int bin_search(vector<char>&A, char key)
{
int left = 0;
int right = A.size() - 1;
while(left < right)
{
int mid = (left + right)/2;
if(A[mid] == key) return mid;
else if(A[mid] < key)
left = mid + 1;
else
right = mid + 1;
}
return A.size();
}
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
close. but it needs to take a predicate, because the elements in the vector are classes and i'm looking an element which has a member variable equal to a certain value.
right now, my code looks like:
class scaneql
{
public:
scaneql( int lookfor) : i(lookfor) {}
bool operator()(const scan & a) const
{
return a.i == i;
}
private:
int i;
};
...
std::vector< scan>::const_iterator curScan = std::find_if(m_rows.begin(), m_rows.end(), scaneql((int)y));
There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'.
--Holgate, from Plastic
|
|
|
|
|
Are you going to use this predicate in more than one spot? Do you need to search for member variables? If this is a one shot deal, just hack up bin_search and be done with it.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Is a binary search faster than using find_if? Is that the reason you are looking for something else?
Todd Smith
|
|
|
|
|
yep. find_if just iterates over all items till it finds one that matches. this is fine, if your collection isn't sorted. but if it is sorted, a binary search is much much faster.
-c
There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'.
--Holgate, from Plastic
|
|
|
|
|
I am programming with ATL 3.0, building an application where I need a main exe server, launching multiple exe server instances (of the same exe) through CoGetObject... To be clearer, I need to have server1.exe and multiple server2.exe process loaded, one for each COM component that is started through CoGetObject.
Is there a way to do this? The code generated automatically creates me only one server2.exe process where all the instances of my COM component are hosted. I read articles about people having problems getting a single instance, but me, I'd like to do the exact contrary!
|
|
|
|
|
When server starts, he registers own class objects at such manner:
hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,REGCLS_MULTIPLEUSE);
You can change REGCLS_MULTIPLEUSE constant with REGCLS_SINGLEUSE to make one object instance per one server process.
With best wishes,
Vita
|
|
|
|
|
Hello,
I have developed an Activex control with VS.NET C++ using ATL 7.0. This control contains two properties, four events and two methods. It works satisfactorily on Activex test container
But, in VB.NET When I put my control on the form, 1. it takes much time to display(Though it doesn't contain any drawing code) 2. VB's properties window displays my control's properties successfully for the first time(Though it displays property's value as junk), but after running test project, and coming back to vb's form containing my control and when I try to see property's value, I can see only one property only.
My other property's name simply vanishes from the list of properties.
What could be wrong. What shall I check. How do I correct it.
Tushar Bhatt
|
|
|
|