Archived
This forum has been archived. Please start a new discussion on GitHub.
slice2freeze std::wstring
in Bug Reports
Consider this simple ice definition:
["cpp:type:wstring"]
module syn
{
struct UserDataT
{
string username;
};
};
Genereting a Freeze Map with:
slice2freeze --dict UsersMap,int,syn::UserDataT --dict-index UsersMap,username UserMap syn.ice
This is the header generated:
#ifndef __UserMap_h__
#define __UserMap_h__
#include <Freeze/Map.h>
#include <syn.h>
#ifndef ICE_IGNORE_VERSION
# if ICE_INT_VERSION / 100 != 302
# error Ice version mismatch!
# endif
# if ICE_INT_VERSION % 100 > 50
# error Beta header file detected
# endif
# if ICE_INT_VERSION % 100 < 1
# error Ice patch level mismatch!
# endif
#endif
class UsersMapKeyCodec
{
public:
static void write(::Ice::Int, Freeze::Key&, const ::Ice::CommunicatorPtr&);
static void read(::Ice::Int&, const Freeze::Key&, const ::Ice::CommunicatorPtr&);
static const std::string& typeId();
};
class UsersMapValueCodec
{
public:
static void write(const ::syn::UserDataT&, Freeze::Value&, const ::Ice::CommunicatorPtr&);
static void read(::syn::UserDataT&, const Freeze::Value&, const ::Ice::CommunicatorPtr&);
static const std::string& typeId();
};
class UsersMap : public Freeze::Map< ::Ice::Int, ::syn::UserDataT, UsersMapKeyCodec, UsersMapValueCodec, Freeze::IceEncodingCompare >
{
public:
class UsernameIndex : public Freeze::MapIndex< ::std::string, UsernameIndex, Freeze::IceEncodingCompare >
{
public:
UsernameIndex(const std::string&, const Freeze::IceEncodingCompare& = Freeze::IceEncodingCompare());
static void write(const ::std::string&, Freeze::Key&, const Ice::CommunicatorPtr&);
static void read(::std::string&, const Freeze::Key&, const ::Ice::CommunicatorPtr&);
protected:
virtual void marshalKey(const Freeze::Value&, Freeze::Key&) const;
};
UsersMap(const Freeze::ConnectionPtr&, const std::string&, bool = true, const Freeze::IceEncodingCompare& = Freeze::IceEncodingCompare());
template <class _InputIterator>
UsersMap(const Freeze::ConnectionPtr& __connection, const std::string& __dbName, bool __createDb, _InputIterator __first, _InputIterator __last, const Freeze::IceEncodingCompare& __compare = Freeze::IceEncodingCompare())
: Freeze::Map< ::Ice::Int, ::syn::UserDataT, UsersMapKeyCodec, UsersMapValueCodec, Freeze::IceEncodingCompare >(__connection->getCommunicator())
{
Freeze::KeyCompareBasePtr __keyCompare = new Freeze::KeyCompare< ::Ice::Int, UsersMapKeyCodec, Freeze::IceEncodingCompare >(__compare, this->_communicator);
std::vector<Freeze::MapIndexBasePtr> __indices;
__indices.push_back(new UsernameIndex("username"));
this->_helper.reset(Freeze::MapHelper::create(__connection, __dbName, UsersMapKeyCodec::typeId(), UsersMapValueCodec::typeId(), __keyCompare, __indices, __createDb));
while(__first != __last)
{
put(*__first);
++__first;
}
}
iterator findByUsername(const ::std::string&, bool = true);
const_iterator findByUsername(const ::std::string&, bool = true) const;
iterator lowerBoundForUsername(const ::std::string&);
const_iterator lowerBoundForUsername(const ::std::string&) const;
iterator upperBoundForUsername(const ::std::string&);
const_iterator upperBoundForUsername(const ::std::string&) const;
std::pair<iterator, iterator> equalRangeForUsername(const ::std::string&);
std::pair<const_iterator, const_iterator> equalRangeForUsername(const ::std::string&) const;
int usernameCount(const ::std::string&) const;
};
As you can see for example findByUsername first parameter is mapped to std::string instead of std::wstring.
I think this is not correct, isn't it?
["cpp:type:wstring"]
module syn
{
struct UserDataT
{
string username;
};
};
Genereting a Freeze Map with:
slice2freeze --dict UsersMap,int,syn::UserDataT --dict-index UsersMap,username UserMap syn.ice
This is the header generated:
#ifndef __UserMap_h__
#define __UserMap_h__
#include <Freeze/Map.h>
#include <syn.h>
#ifndef ICE_IGNORE_VERSION
# if ICE_INT_VERSION / 100 != 302
# error Ice version mismatch!
# endif
# if ICE_INT_VERSION % 100 > 50
# error Beta header file detected
# endif
# if ICE_INT_VERSION % 100 < 1
# error Ice patch level mismatch!
# endif
#endif
class UsersMapKeyCodec
{
public:
static void write(::Ice::Int, Freeze::Key&, const ::Ice::CommunicatorPtr&);
static void read(::Ice::Int&, const Freeze::Key&, const ::Ice::CommunicatorPtr&);
static const std::string& typeId();
};
class UsersMapValueCodec
{
public:
static void write(const ::syn::UserDataT&, Freeze::Value&, const ::Ice::CommunicatorPtr&);
static void read(::syn::UserDataT&, const Freeze::Value&, const ::Ice::CommunicatorPtr&);
static const std::string& typeId();
};
class UsersMap : public Freeze::Map< ::Ice::Int, ::syn::UserDataT, UsersMapKeyCodec, UsersMapValueCodec, Freeze::IceEncodingCompare >
{
public:
class UsernameIndex : public Freeze::MapIndex< ::std::string, UsernameIndex, Freeze::IceEncodingCompare >
{
public:
UsernameIndex(const std::string&, const Freeze::IceEncodingCompare& = Freeze::IceEncodingCompare());
static void write(const ::std::string&, Freeze::Key&, const Ice::CommunicatorPtr&);
static void read(::std::string&, const Freeze::Key&, const ::Ice::CommunicatorPtr&);
protected:
virtual void marshalKey(const Freeze::Value&, Freeze::Key&) const;
};
UsersMap(const Freeze::ConnectionPtr&, const std::string&, bool = true, const Freeze::IceEncodingCompare& = Freeze::IceEncodingCompare());
template <class _InputIterator>
UsersMap(const Freeze::ConnectionPtr& __connection, const std::string& __dbName, bool __createDb, _InputIterator __first, _InputIterator __last, const Freeze::IceEncodingCompare& __compare = Freeze::IceEncodingCompare())
: Freeze::Map< ::Ice::Int, ::syn::UserDataT, UsersMapKeyCodec, UsersMapValueCodec, Freeze::IceEncodingCompare >(__connection->getCommunicator())
{
Freeze::KeyCompareBasePtr __keyCompare = new Freeze::KeyCompare< ::Ice::Int, UsersMapKeyCodec, Freeze::IceEncodingCompare >(__compare, this->_communicator);
std::vector<Freeze::MapIndexBasePtr> __indices;
__indices.push_back(new UsernameIndex("username"));
this->_helper.reset(Freeze::MapHelper::create(__connection, __dbName, UsersMapKeyCodec::typeId(), UsersMapValueCodec::typeId(), __keyCompare, __indices, __createDb));
while(__first != __last)
{
put(*__first);
++__first;
}
}
iterator findByUsername(const ::std::string&, bool = true);
const_iterator findByUsername(const ::std::string&, bool = true) const;
iterator lowerBoundForUsername(const ::std::string&);
const_iterator lowerBoundForUsername(const ::std::string&) const;
iterator upperBoundForUsername(const ::std::string&);
const_iterator upperBoundForUsername(const ::std::string&) const;
std::pair<iterator, iterator> equalRangeForUsername(const ::std::string&);
std::pair<const_iterator, const_iterator> equalRangeForUsername(const ::std::string&) const;
int usernameCount(const ::std::string&) const;
};
As you can see for example findByUsername first parameter is mapped to std::string instead of std::wstring.
I think this is not correct, isn't it?
0
Comments
-
Thanks for the report. We will look into this.
Dwayne0 -
The problem is in slice2freeze sources where the function :
string
InputTypeToString(const TypePtr& type, bool useWstring, const StringList& metaData)
is called every time with useWstring=false.0 -
Hi Paolo,
Yes, it's definitely a bug, but it's not that easy to fix. Here is a work-around that should work well, but it also requires a small bug fix to slice2freeze.
1) slice2freeze bug fix: on line 933 of slice2freeze/Main.cpp, insert:
iType.metaData = dataMember->getMetaData();
and then rebuild slice2freeze (you may need to start a full Ice build if you haven't one already)
2) Instead or in addition to the module-level "cpp:type:wstring" metadata, add a wstring metadata to all the data members you want to index. With your example, this would be:
["cpp:type:wstring"]
module syn
{
struct UserDataT
{
["cpp:type:wstring"] string username;
};
};
Please let us know how it goes!
Bernard0 -
Thanks a lot, that patch solved the problem0