|
Hi.
How do you definte a comparison function for an container of std::pair other than map? I need to search a container of std::pair. For example:
typedef std::deque<std::pair<std::string, int=""> > deqStringInt;
deqStringInt example;
example.push_back(std::pair<"December", 21>);
// How do you search an element?
std::find_if(example.begin(), example.end(), std::bind2nd(???
// Functor
class Search : std::binary_function<std::pair<std::string, int="">, std::string, bool>
{
public:
bool operator()(const std::pair<std::string, int=""> &lp, const std::string &rp)
{
return lp->first == rp;
}
};
Thanks,
Kuphryn
|
|
|
|
|
#pragma warning(disable:4786)
#include <queue>
#include <string>
#include <algorithm>
typedef std::deque<std::pair<std::string,int> > deqStringInt;
struct my_search
{
my_search(const std::string s):s(s){}
bool operator()(const std::pair<std::string,int>& c) const
{
return c.first==s;
}
private:
std::string s;
};
int main(void)
{
deqStringInt example;
example.push_back(std::make_pair(std::string("December"), 21));
std::find_if(example.begin(),example.end(),my_search("December"));
return 0;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Nice! Thanks.
Here is another solution and the one I implemented.
class Searc : std::binary_function<pairstringint, std::string,="" bool="">
{
public:
bool operator()(const pairStringInt &lp, const std::string &rp) const
{
return (lp.first == rp);
}
};
std::find_if(data.begin(), data.end(), std::bind2nd(Search(), theString))
Kuphryn
|
|
|
|
|
Hi.
Is it possible to have an unsorted map and/or multimap STL container? The map is an extremely useful STL container because of its key and value feature. I need to set a map container to not sort its keys, i.e. insert them if they do not exist, but in a queue fashion as in FIFO.
Thanks,
Kuphryn
|
|
|
|
|
Just combine the key and value into another structure/class or use std::pair and then use std::deque as your container. It works well as a FIFO where as by definition, a map is sorted and would perform poorly as a FIFO.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Nice! Thanks
Can you give a quick example of std::pair in other containers beside the map? I did not know it was possible to use std::pair as a datatype. How about searches?
Kuphryn
|
|
|
|
|
No. You want vector<< pair <type1, type2 > >
A map cannot deliver it's performance guarentees if it does not sort the values.
A hash map might, I'm not sure.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Nice! Does search works for std::pair as map's std::pair? In other words, do you have to write a special search algorithm to find an element in std::vector<std::pair<t, u=""> >?
Kuphryn
|
|
|
|
|
You can't use [] on a vector in that way ( you can by providing a numeric index ), but you can write a functor to find based on the first element, yes.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
|
hi all,
i am stuck. I want to make a setup for my VC application as we have in VC. But can't find anything helpful.
if anyone can suggest me anything would be a great help.
thanks in advance
Himanshu
|
|
|
|
|
There is a large variety of setup toolkits to fit any budget. We use Wise InstallBuilder but there are a number of lower-cost options as well. For example take a look at InnoSetup. For a list of others, visit any popular download site such as download.com or tucows.com.
-Anatoly
Anatoly Ivasyuk is co-founder of DTLink Software, a company specializing in Internet software and technologies. He is the author of DTLink's Windows products: AnswerTool, FAQTool, AppUpdate, and Personal Stock Monitor
|
|
|
|
|
hi~
I apologize being not good at English.
I wanna serialize my own data for network/file/etc...
I thought that stream of c++ standard library is suitable.
but, there's no facilities exactly for my use.
1. I wanna store stream data into memory.(not file)
2. insertion and extraction must operate in binary mode.
// example of usage
// proc A
omystream ms; // mystream is that I wanted..
int n = 1;
short s = 2;
ms << n << s;
// or ms << int_b(n) << short_b(s);
// int_b(), short_b() is custom manipulators
::send(ms.buf(),...); // send to network
// proc B
BYTE buf[4096];
::revc(buf,...); // receive from network
imystream ms(buf, dwSizeReceived); // dwSizeReceived = 6
int n;
short s;
ms >> n >> s; // n = 1, s = 2
// or ms >> int_b(n) >> short_b(s);
// result
data occupy 6 bytes memory. (4 for n(int), 2 for s(short))
send and receive 6 byte of memory.
memory layout:
00 00 00 01 00 02 // 6 byte
not
"000000010002" // 12 byte
this mean not string but binary.
how can I achieve it?
derive strstream or stream?
derive stream_buf?
I need your advice.
thanks in advance.
|
|
|
|
|
What you are looking for is ::CreateStreamOnHGlobal.
You might consider SAFEARRAY(BYTE) as well (instead of).
|
|
|
|
|
The simplest way would be to deliminate all the data. In the case of streams, it would be easiest to use spaces, as the stream's default behaviour is to skip them.
ostringstream out;
int n = 1;
short s = 2;
out << n << ' ' << s;
istringstream in ( out.str () );
n = s = 0;
in >> n >> s;
cout << "n = " << n << ", s = " << s << endl;
cheers,
-B
|
|
|
|
|
hi,
I'm developing ATL ActiveX DLL that used by ASP/VBScript client.
This server uses VARIANT as a parameter input :
HRESULT UseThis([in] VARIANT StringParam, [out, retval] long *ret);<br />
<br />
STDMETHODIMP CObj::UseThis(VARIANT StringParam, long *ret)<br />
{<br />
*ret = 1;<br />
<br />
if((StringParam.vt & VT_ARRAY) && (StringParam.vt & VT_BSTR))<br />
{ <br />
SAFEARRAY *pString = StringParam.parray;<br />
BSTR *bstrArray;<br />
CComBSTR bstrRet;<br />
SafeArrayAccessData(pString, (void**)&bstrArray);<br />
<br />
for(ULONG i = 0; i < pString->rgsabound->cElements; i++)<br />
{<br />
bstrRet = bstrArray[i]; <br />
}<br />
SafeArrayUnaccessData(pString);<br />
SafeArrayDestroy(pString);<br />
<br />
*ret = 0;<br />
}<br />
<br />
return S_OK;<br />
}
When I try to use the function from VB client it OK, but when used from ASP/VBScript client it just FAILED !
VBscript client running on IIS:
Dim obj<br />
Dim ret<br />
Dim strParam(2)<br />
<br />
Set obj = Server.CreateObject("MyATL.Obj") <br />
<br />
strParam(0) = "We"<br />
strParam(1) = "love"<br />
strParam(2) = "COM" <br />
<br />
ret = obj.UseThis(strParam)<br />
<br />
Response.Write "Result is : " & ret<br />
<br />
Set obj = Nothing
Thank u very very much in advance . Any advice, help and suggestions strongly aprreciated.
Regards.
|
|
|
|
|
Din Krop wrote:
SAFEARRAY *pString = StringParam.parray;<br />
BSTR *bstrArray;<br />
CComBSTR bstrRet;<br />
SafeArrayAccessData(pString, (void**)&bstrArray);
I did the following when using variants + safearrays:
long lowerBounds, upperBounds;<br />
SafeArrayGetLBound( StringParam.parray, 1, &lowerBounds);<br />
SafeArrayGetUBound( StringParam.parray, 1, &upperBounds);<br />
long nArgs = (upperBounds - lowerBounds) + 1;<br />
CComVariant* pvVariant;<br />
HRESULT hr = SafeArrayAccessData(StringParam.parray, (void**) &pvVariant);<br />
<br />
USES_CONVERSION;<br />
for(int i = 0; i < nArgs; i++)<br />
{<br />
char szTemp[255];<br />
if (pvVariant[i].vt == VT_BSTR)<br />
strcpy(szTemp, OLE2T(pvVariant[i].bstrVal));<br />
}<br />
hr = SafeArrayUnaccessData(StringParam.parray);<br />
if (pvVariant)<br />
delete pvVariant;<br />
This may help.
Regards
Barry
|
|
|
|
|
1. The following is wrong on several levels, it will create huge runtime problems. Please do not follow that example.
if (pvVariant)
delete pvVariant;
2. I am not familiar with CComVariant, but the next 2 lines look dangerous as well
CComVariant* pvVariant;
HRESULT hr = SafeArrayAccessData(StringParam.parray, (void**) &pvVariant);
safer approach fould be
VARIANT* pvVariant;
|
|
|
|
|
AleXO wrote:
it will create huge runtime problems.
Funny, never had any, boundschecker, + lint never complained either. Why would it cause problems then? Or should you really leave a dangling pointer?
Regards
Barry
|
|
|
|
|
1. It is not dangling pointer. It is a pointer to the memory allocated by ::SafeArrayCreate.
It should only be deallocated by matching SafeArrayDestroy.
2. This memory most probably allocated through HeapAlloc delete can not be applied here
3. even if #1 and #2 were not true (they are). the object that is allocated is of type VARIANT, not CComVariant.
|
|
|
|
|
AlexO wrote:
1. It is not dangling pointer. It is a pointer to the memory allocated by ::SafeArrayCreate.
It should only be deallocated by matching SafeArrayDestroy.
2. This memory most probably allocated through HeapAlloc delete can not be applied here
3. even if #1 and #2 were not true (they are). the object that is allocated is of type VARIANT, not CComVariant.
Looks like you're right about 1+2, but not about 3.
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_atl_ccomvariant.asp[^]
Regards
Barry
|
|
|
|
|
hi,
Thanx a lot for ur replay.
When use in ASP I got exception error,
in vb I got error :
Method '~' of object '~' failed
regards.
|
|
|
|
|
even in VB/ASP you need error handling
|
|
|
|
|
Hello everybody:
Does any body has used the .exe server type in .NET?
After doing so I add an ATL Control class and build.
The control works without problems when I show it in Explorer or in Test Container.
Now I insert it into a normal .exe MFC dialog based application and want to add an MFC Class From ActiveX Control for this control, but it is not part of the "available ActiveX control" list.
If I add it from the .exe file and the execute the application the following error appears.
CoCreateInstance of OLE control {7A55CBB2-5043-43F4-894F-CD656330617E} failed.
>>> Result code: 0x800401f9
>>> Is the control is properly registered?
Unhandled exception at 0x7c17f774 (mfc70d.dll) in CallerPrueba2.exe: User breakpoint.
The control is in the register and Test Container and IExplorer don´t complaint about this.
Any helping hint?
Thanks,Jesus.
|
|
|
|
|
Hello,
Here is the problem I have run into. I have an Atl Server Web App that is structured like the following:
\bin (dll's)
\include (common srf that get included)
\secure (srf pages that need to be under SSL, also needs access to inlcudes)
*.srf general srf pages that need access to the includes
Here is the problem, when one of the general srf files uses an include the path for the include internal handler is \bin\something.dll. The path used for the include is relative to the file that included it, not the include itself. Now when one of the secure pages includes the same file the handler path to the dll is wrong, it tries to load the library from ...secure\bin\something.dll. This causes an issue, if the handler paths were relative to the actual file being rendered all would be well. Has anybody run accross this before and have any suggestions? Seems like the alternative is assign SSL access on a file by file basis? Other than this issue ATL server seems like a slick framework!
Thanks for any suggestions!
|
|
|
|