|
From what I can tell, the C++ stream system presumes that files are sequences of bytes, not characters - even when you use wide streams - the 'wide' part of wide stream (AFAICT) indicates how the stream object interacts with C++, not the underlying file or whatever. Thus, your codecvt facet has to take in characters.
By changing the declaration of your codecvt facet to that shown below, I was able to get breakpoints in the replacement facet being set.
class utf16_codecvt : public std::codecvt<char16_t, char, std::mbstate_t>
{
typedef std::codecvt<char16_t, char, std::mbstate_t> Base;
typedef char16_t ElemT;
typedef char ByteT;
virtual result __CLR_OR_THIS_CALL do_in(std::mbstate_t& s,
const ByteT *_First1, const ByteT *_Last1, const ByteT *& _Mid1,
ElemT*_First2, ElemT* _Last2, ElemT *& _Mid2) const
{
return Base::do_in(s, _First1, _Last1, _Mid1, _First2, _Last2, _Mid2);
}
virtual result __CLR_OR_THIS_CALL do_out(std::mbstate_t& s,
const ElemT*_First1, const ElemT*_Last1, const ElemT*& _Mid1,
ByteT*_First2, ByteT*_Last2, ByteT*& _Mid2) const
{
return Base::do_out(s, _First1, _Last1, _Mid1, _First2, _Last2, _Mid2);
}
virtual result __CLR_OR_THIS_CALL do_unshift(std::mbstate_t& s,
ByteT*_First2, ByteT*_Last2, ByteT*&_Mid2) const
{
return Base::do_unshift(s, _First2, _Last2, _Mid2);
}
virtual int __CLR_OR_THIS_CALL do_length(const std::mbstate_t& s, const ByteT*_First1,
const ByteT*_Last1, size_t _Count) const
{
return Base::do_length(s, _First1, _Last1, _Count);
}
};
So, your replacement facet will have to know it needs two bytes read for every character (and vice versa, obviously). The best reference for that sort of information is probably Standard C++ IOStreams and Locales by Angelika Langer and Klaus Kreft[^] - but even then, locales and facets are heavy going in C++
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks, Stuart
That worked great; I expected the problem was something like that. Something else I discovered was that the second template parameter has to be ‘char’ or it will not work. That is ‘unsigned char’ will not even work as the second parameter.
I need to dig up a copy of the standard to see if this is compliant and makes since, because having template parameters that can only be of a single integral type is illogical.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
John R. Shaw wrote: Something else I discovered was that the second template parameter has to be ‘char’ or it will not work. That is ‘unsigned char’ will not even work as the second parameter.
I need to dig up a copy of the standard to see if this is compliant and makes since, because having template parameters that can only be of a single integral type is illogical.
I think there are two pertinent ideas here - firstly, files are streams of bytes (that's the basic concept underlying file streams in C++), which is why they always convert to/from bytes. Secondly, codecvt facets can be used on their own, without streams.
So, say you'd read in a file converting from a byte stream to (say) UCS-2. Then you want to write the UTF-32 equivalent to a file. You could use a codecvt facet that could convert from UCS-2 to UTF-32. The example code in the codecvt::in documentation on MSDN[^] shows this sort of scenario.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
I am looking for a possibility to have a two way associative array. What I mean is that I would like to have an array say
My2WayArray<int, string=""> _twoWayArray;
and I can do the following
_twoWayArray["user1"] = 123;
_twoWayArray["user2"] = 456;
and
_twoWayArray[123] = "user1";
_twoWayArray[456] = "user2";
this way I will be able to lookup a user if the integer (used as user id) is specified and integer id if user name is provided.
I don't want to use it anywhere, it is just out of curiosity.
While I am posting this question I am trying to figure it out at my end.
Thanks and Regards
|
|
|
|
|
|
Bah - you beat me to it by a matter of seconds
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Like this[^]?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
It's a pity they don't have something like this in the .NET collection classes. And it doesn't seem to exist in the third party libraries either.
Kevin
|
|
|
|
|
Probably be quite difficult to port the approach used in Boost - one of the first comments I saw in the bimap headers was:
Once you're using the words 'mpl' (== C++ template metaprogramming library) and 'magic' together, there's little to no hope of translating the code directly to another language. I suspect some form of code generator would be the best bet (I seem to remember a container generator being written by someone before C# got generics - that would be similar).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you Andy and Stuart for the reply.
I was looking for boost bi-map type functionality.
Regards
|
|
|
|
|
Hi,
I need to implement the RPC in windows XP based system and I created an IDL file which contains the RPC calls and i created stub files. While compiling with server and client application it shows "You need a Windows NT Version 4.0 or Later to run this stub".But i am using Microsoft Visual C++ 6.0. Can anyone help to solve this problem?
Thanks,
S.Suthakar
|
|
|
|
|
You probably need to set WINVER[^] to reflect you're using Windows XP, rather than Windows 98, which was the current version of Windows when VC6 came out.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
What Stuart said and depending on what you are using you might need to have an updated Platform SDK[^] from the original VC6
|
|
|
|
|
I am using original version. The auto generated code only shows the error(defined in #).if i remove that then it is compiled.
|
|
|
|
|
suthakar56 wrote: I am using original version. The auto generated code only shows the error(defined in #).if i remove that then it is compiled.
I have no new information. Follow the advice previously given by myself and Stuart.
|
|
|
|
|
Good point - I forgot that one. So long since I used VC6....since I moved to VS2003, I've always used a Visual Studio newer than my standard target (Windows 2000 - we've not managed to make the giant leap to XP or Vista at the company I work for).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
I compiled the idl file and it creates server and client (ie client_c.c and server_s.c) stub files.Client stub file is working properly in application.But In server stub file Interface definition is not implemented(generated code).(I created idl file project type is ATL COM AppWizard and server type as Service).
Regrads,
Suthakar
|
|
|
|
|
suthakar56 wrote: But In server stub file Interface definition is not implemented
What do you mean by 'not implemented'?
I just tried a quick sample of IDL, which I processed with midl /server stub /client stub a.idl - seemed to have the correct server marshalling code.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I just compiled .idl by vc++ editer itself.It creates the client and server stub files.I want to know that whether i should compile .idl file using midl compiler only or the the first is enough.
Not implemented -->The function(idl) definition is implemented in server stub file (in my sample code).But original code it was not there.
|
|
|
|
|
suthakar56 wrote: I just compiled .idl by vc++ editer itself.It creates the client and server stub files.I want to know that whether i should compile .idl file using midl compiler only or the the first is enough.
VC++ uses MIDL. That's fine.
suthakar56 wrote: Not implemented -->The function(idl) definition is implemented in server stub file (in my sample code).But original code it was not there.
Can you explain what you mean by 'But original code it was not there'
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I am already having some sample code for RPC which executes perfectly.But my RPC server stub code, implementation of idl function definition (ie auto generated) was not there.
|
|
|
|
|
So - do you mean there was no whatever_s.c file? Or that it was empty? Try posting your IDL, and look in your VC++ project settings for that file to see what the command line to compile the IDL is and post that.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi, now server is working fine but in client side it through an exception while running with breakpoints in client stub file.The idl file is as follows
[ uuid (id),
version(1.0),
pointer_default(unique)
]
interface myidl
{
typedef struct
{
int data;
}DATA_ST;
void function([out] [in] DATA_ST *,DATA_ST);
}
NdrNsGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, myidl__MIDL_AutoBindHandle );
while running this above function it through the exception " Runtime reported exception 0x6e2 = 1762.I want to know how the synchronization is maintained between client and server.
|
|
|
|
|
suthakar56 wrote: I want to know how the synchronization is maintained between client and server.
By maintaining a single thread of control between client and server - the calling thread on the client side waits while an RPC call is made.
suthakar56 wrote: void function([out] [in] DATA_ST *,DATA_ST);
Should that be
void function([out] DATA_ST *,[in] DATA_ST); ?
suthakar56 wrote: Runtime reported exception 0x6e2 = 1762
Error 1762 == RPC_S_NAME_SERVICE_UNAVAILABLE . Means it can't find the server, I think.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart, The problem is solved.As a beginner,I missed the .acf file.So that the problem is created.Now this is working fine.Thank you for your replies.
|
|
|
|
|