Results 1 to 5 of 5

Thread: slice2freeze std::wstring

  1. #1
    paolo is offline Registered User
    Name: paolo volpi
    Organization: tvblob
    Project: tvblob blobbox
    Join Date
    Aug 2007
    Posts
    22

    slice2freeze std::wstring

    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(__connect ion, __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:air<iterator, iterator> equalRangeForUsername(const ::std::string&);
    std:air<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?
    Last edited by paolo; 01-15-2008 at 05:09 AM.

  2. #2
    dwayne's Avatar
    dwayne is offline ZeroC Staff
    Name: Dwayne Boone
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Jan 2005
    Location
    St. John's, Newfoundland
    Posts
    397
    Thanks for the report. We will look into this.

    Dwayne

  3. #3
    paolo is offline Registered User
    Name: paolo volpi
    Organization: tvblob
    Project: tvblob blobbox
    Join Date
    Aug 2007
    Posts
    22
    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.

  4. #4
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    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!

    Bernard
    Bernard Normier
    ZeroC, Inc.

  5. #5
    paolo is offline Registered User
    Name: paolo volpi
    Organization: tvblob
    Project: tvblob blobbox
    Join Date
    Aug 2007
    Posts
    22
    Thanks a lot, that patch solved the problem

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. session using std::wstring instead of std::string
    By Andrew in forum Help Center
    Replies: 2
    Last Post: 01-23-2008, 08:06 AM
  2. std::string in interface
    By dthompson in forum Help Center
    Replies: 1
    Last Post: 06-21-2006, 04:49 PM
  3. Status on wstring?
    By jgaa in forum Help Center
    Replies: 2
    Last Post: 03-21-2005, 08:59 PM
  4. ICE std-ization?
    By marlowa in forum Comments
    Replies: 3
    Last Post: 03-21-2005, 04:41 PM
  5. non-std scandir function
    By marlowa in forum Patches
    Replies: 1
    Last Post: 02-28-2003, 01:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •