×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    9

    Question How to port Symbian OS String Descriptors

    Hi,

    I want to port Symbian OS string descriptors. In this way I can use them in Borland C++, Visual C++ or Java.

    Where can I find implementation of string descriptors?

    Thank you in advance.

    BSekerci

  2. #2
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: How to port Symbian OS String Descriptors

    You may find the corresponding header files and some inline files helpful. Check e32desXX.* in \epoc32\include of your sdk. The rest will be implementing based on docs, etc.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    9

    Re: How to port Symbian OS String Descriptors

    I know the e32desXX.* files.

    Descriptors are defined, also many functions are defined in inline files, like operators. But the important part is defined in LIB files.

    Because of they are releated to memory operations, you should implement these functions differently for each system.

    It is some kind of hard job. I wonder if somebody tried it before

    Thanks.

    BSekerci

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: How to port Symbian OS String Descriptors

    You can't find an implementation of string descriptors because that source code belongs to Symbian and is not publicly available. Hence if you want to port them to standard C++ or java(?!) you will have to duplicate all their header files and them implement them yourself - certianly not an inconsequential task. But even if it were easy, I'd still have to ask why why why?

    why why why

    P.S.
    >>Because of they are releated to memory operations
    Only HBuf and RBuf
    Last edited by hotcheese; 2006-05-26 at 23:12.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    23

    Re: How to port Symbian OS String Descriptors

    Quote Originally Posted by birol.sekerci
    Hi,

    I want to port Symbian OS string descriptors. In this way I can use them in Borland C++, Visual C++ or Java.

    Where can I find implementation of string descriptors?

    Thank you in advance.

    BSekerci
    I can't believe that I'm seeing this!

    Hint: use std::string on other platforms just as efficient, 100 times easier to use than you know what

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    9

    Unhappy Re: How to port Symbian OS String Descriptors

    Thank you for the hint: "use std::string" !

    I just wondered if somebody tried this before.

    Let's say you have written an application for Symbian OS and have some classes using Symbian OS string descriptors.

    And, you want to write java (MIDLET) version of it. What would you do? You can simply refactor Symbian types (like TInt) to Java types and mostly it does not hurt. You cannot easily convert Symbian OS string descriptors to Java's String type (nor STL's std::string).

    I am trying to find out needed effort to writing same application on different platform. And I understood it is not good idea to start with an existing code from Symbian OS c++.

    Many people tried to port something to Symbian OS, like XML parsers. Maybe nobody tried to port something from Symbian OS before.

    Thank you again.

  7. #7
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037

    STL??

    Hi,

    the best you can do is not to port anything from Symbian but do it in reverse order. Just write it in C++ and then make a wrapper for Symbian... On the other side many projects in Symbian don't use descriptors at all... It's not really necessary regardless the docmumentation says something else...

    What should be interesing is to port STL to Symbian, for example I ported partialy IN VERY SIMPLE WAY assocative map - as very useful design pattern which I missed on Symbian... Just look on it. It's simple and useful - may be we can make some OPEN SOURCE project together???

    Bye
    STeN

    epoc_binary_function.h:
    ==================
    template <class XClass1, class XClass2, class Result> struct epoc_binary_function
    {
    typedef XClass1 first_argument_type;
    typedef XClass2 second_argument_type;
    typedef Result result_type;
    };

    epoc_equal_to.h:
    =============
    template <class XClass1>
    struct epoc_equal_to : epoc_binary_function <XClass1, XClass1, bool>
    {
    bool operator()(const XClass1& _x, const XClass1& _y) const { return _x == _y; }
    };

    epoc_map.h:
    ==========
    template <class Key, class XClass, class Compare = epoc_equal_to<Key> >
    class Epoc_map
    {
    public:

    //
    // Default constructor
    //
    Epoc_map();

    //
    // Default destructor
    //
    ~Epoc_map();

    public:

    //
    // find value by given key
    //
    const XClass* Find(const Key& x);

    //
    // insert new pair
    //
    TBool Insert(Key* x, XClass* y);

    //
    // erace name and value pair
    //
    void Erase(const Key& x);

    private:
    RPointerArray<Key> iKeys;
    RPointerArray<XClass> iValues;
    };

    epoc_map.inl:
    ==========

    template <class Key, class XClass, class Compare >
    const XClass* Epoc_map <Key, XClass, Compare>::Find(const Key& x)
    {
    for ( int i = 0; i < iKeys.Count(); i++ )
    {
    if ( Compare()( *(iKeys)[ i ], x ) )
    {
    return (iValues)[ i ];
    }
    }
    return NULL;
    }

    template <class Key, class XClass, class Compare >
    TBool Epoc_map<Key, XClass, Compare>::Insert(Key* x, XClass* y)
    {
    if ( !x || !y )
    return EFalse;

    if ( Find( *x ) )
    Erase( *x );

    if ( iKeys.Append( x ) == KErrNone )
    {
    if ( iValues.Append( y ) != KErrNone )
    {
    for ( int i = 0; i < iKeys.Count(); i++ )
    {
    if ( Compare()( *(iKeys)[ i ], *x ) )
    {
    iKeys.Remove( i );
    break;
    }
    }
    return EFalse;
    }
    }
    return ETrue;
    }

    template <class Key, class XClass, class Compare >
    void Epoc_map<Key, XClass, Compare>::Erase(const Key& x)
    {
    for ( int i = 0; i < iKeys.Count(); i++ )
    {
    if ( Compare()( *(iKeys)[ i ], x ) )
    {
    delete iKeys[ i ];
    iKeys.Remove( i );

    delete iValues[ i ];
    iValues.Remove( i );
    return;
    }
    }
    }

    template <class Key, class XClass, class Compare >
    Epoc_map <Key, XClass, Compare>::Epoc_map()
    {
    }

    template <class Key, class XClass, class Compare >
    Epoc_map <Key, XClass, Compare>::~Epoc_map()
    {
    for ( int i = 0; i < iKeys.Count(); i++ )
    delete iKeys[i];
    iKeys.Reset();
    iKeys.Close();

    for ( i = 0; i < iValues.Count(); i++ )
    delete iValues[i];
    iValues.Reset();
    iValues.Close();
    }

  8. #8
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: How to port Symbian OS String Descriptors

    >> What should be interesing is to port STL to Symbian

    Except that templates take up potentially a tw*t load of space, exactly why there aren't harndly any in Symbian, so you'd have to be carfull to fully investigate the thin template idiom.

  9. #9
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037

    Re: How to port Symbian OS String Descriptors

    Hi,

    I know, but mobile phones becomes still better and better. Look on the memory problems we faced before 4 years (aprox. 10KB for all J2ME app... on some phones). Of course everything must be carefuly checked... I just ask if there's will to do something like that... I've used presented class only in some test prj to simplify my life... It's definitely nothing really presentable

    Bye

    STeN

  10. #10
    Registered User
    Join Date
    Sep 2004
    Posts
    9

    Smile Re: How to port Symbian OS String Descriptors

    Thank you for your reply.

    This is what I came up;

    I copied typedefs from "e32def.h" for simple types.

    Code:
    typedef void TAny;
    typedef signed char TInt8;
    typedef unsigned char TUint8;
    typedef short int TInt16;
    typedef unsigned short int TUint16;
    typedef long int TInt32;
    typedef unsigned long int TUint32;
    typedef signed int TInt;
    typedef unsigned int TUint;
    typedef float TReal32;
    typedef double TReal64;
    typedef double TReal;
    typedef unsigned char TText8;
    typedef unsigned short int TText16;
    typedef int TBool;
    For descriptors, I created a new class named "TDesB"

    Code:
    class TDesB
    {
    protected:
    	string iBuf;
    public:
    	TDesB()
            {
            	iBuf = string("");
            }
    
    	TDesB(const char* str)
            {
            	iBuf = string(str);
            }
    
    	TDesB(char* str)
            {
            	iBuf = string(str);
            }
    
            static TDesB *NewL(TInt aMaxLength)
            {
    		TDesB *des = new TDesB("");
                    return des;
            }
    
            static TDesB *NewLC(TInt aMaxLength)
            {
                    return NewL(aMaxLength);
            }
    
            TDesB& Des()
            {
            	return *this;
            }
    
            const TDesB& Des() const
            {
            	return *this;
            }
    
    	const char* c_str() const
            {
            	return iBuf.c_str();
            }
    
            const char* Ptr() const
            {
            	return iBuf.c_str();
            }
    
    	void Copy(const TDesB &aDes)
            {
            	iBuf = string(aDes.c_str());
            }
    
            void Set(const TDesB &aDes)
            {
            	iBuf = string(aDes.c_str());
            }
    
            void Set(const char* aBuf,TInt aLength)
            {
            	char *buf = new char[aLength+10];
                    strncpy(buf, aBuf, aLength);
                    buf[aLength] = 0;
                    iBuf = string((char*)buf);
                    delete [] buf;
            }
    
            TInt Format(const char *fmt,...)
            {
                    char pline[4096];
                    int cnt;
    
                    va_list argptr;
                    va_start(argptr,fmt);
                    cnt = vsprintf(pline,fmt,argptr);
                    va_end(argptr);
    
                    Copy(pline);
                    return cnt;
            }
    
            void FormatList(const TDesB &aFmt,VA_LIST aList)
            {
    		char pline[4096];
                    vsprintf(pline, aFmt.c_str(), aList);
                    Copy(pline);
            }
    
            TInt Length() const
            {
            	return iBuf.size();
            }
    
            void SetLength(TInt aLength)
            {
            }
    
            TInt Size() const
            {
            	return iBuf.size();
            }
    
            TInt Find(const TDesB &aDes) const
            {
            	return iBuf.find(aDes.c_str());
            }
    
            TInt Locate(const char &aCh) const
            {
            	return iBuf.find(aCh);
            }
    
    	const TDesB Mid(TInt aPos,TInt aLength) const
            {
            	TDesB des(iBuf.substr(aPos, aLength).c_str());
                    return des;
            }
    
            const TDesB Mid(TInt aPos) const
            {
            	TDesB des(iBuf.substr(aPos).c_str());
                    return des;
            }
    
            const TDesB Left(TInt aLength) const
            {
            	TDesB des(iBuf.substr(0, aLength).c_str());
                    return des;
            }
    
            TDesB* AllocL() const
            {
            	TDesB* des = new TDesB(c_str());
            	return des;
            }
    
            TDesB* ReAlloc(TInt aMaxLength)
            {
                 iBuf = string(c_str());
                 return this;	
            }
    
            TDesB* ReAllocL(TInt aMaxLength)
            {
            	return ReAlloc(aMaxLength);
            }
    
            void setChar(TInt anIndex, TChar aChar)
            {
                  iBuf[anIndex] = aChar;
            }
    
            const char& operator[](TInt anIndex) const
            {
            	return iBuf[anIndex];
            }
    
            void Delete(TInt aPos,TInt aLength)
            {
            	iBuf.erase(aPos, aLength);
            }
    
            void Insert(TInt aPos,const TDesB& aDes)
            {
            	iBuf.insert(aPos, aDes.c_str());
            }
    
    	void Append(const TDesB& aDes)
            {
            	iBuf.append(aDes.c_str());
            }
    
            TInt Compare(const TDesB& aDes) const
            {
            	return iBuf.compare(aDes.c_str());
            }
    
            void Zero()
            {
            	iBuf = string("");
            }
    
    };
    
    typedef TDesB TDesB16;
    typedef TDesB TPtrB;
    typedef TPtrB TPtrB16;
    typedef TDesB HBufB16;
    
    #define KNullDesB ""
    
    template <TInt T>
    class TBufB : public TDesB
    {
    public:
    	TBufB() : TDesB("")
            {
            }
    };
    
    typedef TPtrB HBufB;
    
    class TDesB8 : public TDesB {};
    class HBufB8 : public TDesB
    {
    public:
    	HBufB8(const TDesB& aDes) : TDesB(aDes)
            {
            }
    };
    
    class TFileNameB : public TDesB
    {
    public:
    	TFileNameB() : TDesB("")
            {
            }
            TFileNameB(const TDesB& aDes) : TDesB(aDes)
            {
            }
    
    };
    
    class TLexB
    {
    private:
    	TDesB des;
    public:
    	TLexB(const TDesB& aDes)
            	: des(aDes.c_str())
            {
            }
    
            TInt Val(TInt& aVal) const
            {
            	try {
                    	aVal = atoi(des.c_str());
                    } catch(...)
                    {
                    	return -1;
                    }
            	return KErrNone;
            }
    
            TInt Val(TUint32& aVal,TRadix aRadix)
            {
    		try {
                    	switch (aRadix) {
                            //case EBinary :
    			//case EOctal:
    			case EDecimal:
                            {
                            	TInt val;
                            	TInt res = Val(val);
                                    aVal = val;
                            	return res;
                            }
    			case EHex:
                              {
                                    sscanf(des.c_str(), "%x", &aVal);
                              }
                              break;
                            }
                    } catch(...)
                    {
                    	return -1;
                    }
            	return KErrNone;
            }
    
    };
    I renamed all TDes,TDesC,TDesC16, HBufC,... with my TDesB on symbian source file (of course this is a copy of of the one used in Symbian project).

    And I simulated RArray and RPointerArray classes with these;

    Code:
    template <class T>
    class RArrayB : private std::vector<T>
    {
    public:
    
    	TInt Append(const T& anEntry)
            {
            	push_back(anEntry);
            }
    
            TInt Count() const
            {
            	return size();
            }
    
            void Close()
            {
            }
    
            const T& operator[](TInt anIndex) const
            {
            	RArrayB& vec = *this;
            	return vec[anIndex];
            }
    
            T& operator[](TInt anIndex)
            {
            	RArrayB& vec = *this;
            	return vec[anIndex];
            }
    
    };
    
    template <class T>
    class RPointerArrayB : private std::vector<T*>
    {
    public:
    
    	TInt Append(const T* anEntry)
            {
            	push_back((T*)anEntry);
            }
    
            TInt Insert(const T* anEntry,TInt aPos)
            {
            	if (aPos >= 0 && aPos < size())
                    {
                    	insert(begin()+aPos, (T*)anEntry);
                    }
            }
    
            TInt Count() const
            {
            	return size();
            }
    
            void Close()
            {
            }
    
            const T* operator[](TInt anIndex) const
            {
            	RPointerArrayB& vec = *this;
            	return vec[anIndex];
            }
    
            T* operator[](TInt anIndex)
            {
            	RPointerArrayB& vec = *this;
            	return vec[anIndex];
            }
    
            TInt Find(const T* anEntry) const
            {
            	RPointerArrayB& vec = *this;
            	for (TInt i=0;i<size();i++)
                    {
                    	if (vec[i] == anEntry)
                            {
                            	return i;
                            }
                    }
                    return -1;
            }
    
            void Reset()
            {
            	clear();
            }
    
            void ResetAndDestroy()
            {
            	RPointerArrayB& vec = *this;
            	for (TInt i=0;i<size();i++)
                    {
                    	T* item = vec[i];
                            delete item;
                    }
                    vec.clear();
            }
    
            void Remove(TInt anIndex)
            {
    		if (anIndex >= 0 && anIndex < size())
                    {
                    	erase(begin()+anIndex);
                    }
            }
    
    };

    As a result this helped me using existing Symbian code without changing many code.

    Birol Sekerci

  11. #11
    Registered User
    Join Date
    May 2006
    Posts
    23

    Re: How to port Symbian OS String Descriptors

    Be careful when deriving from std containers, they don;t have a virtual dtor. better use aggregation.

  12. #12
    Regular Contributor
    Join Date
    Oct 2006
    Posts
    157

    Re: How to port Symbian OS String Descriptors

    It's a myth that mobile development needs to be much different from develpment on more powerful hardware. E.g. developing for Windows Mobile is clamed to be 85% simular to developing for PC in .net. I guess it's something simular on iPhone vs. iMac for OS X, even though they don't have a official development environment what I know of.

    And yes, there is a port of STL for Symbian OS, using inheritens instead of templates, uSTL. It's only formally tested on UIQ, but should work on S60.

    I've also missed an assocative array(map) for Symbian, found RHashMap which seemed to fill the purpose, unfortunately this is not for S60. I also wrote my own special container where I could give elements a key.
    This somehow looses it's purpose since if you'r using strings as keys, or rather descriptors, you either have to use _L() which is depricated or _LIT() which creates a constant for you.
    Having a constant for every key makes the assocative array meaningless.

    Ugly macros doesn't belong to modern software development anyway, please make them go away!
    Last edited by erst; 2007-06-04 at 14:01.

  13. #13
    Registered User
    Join Date
    Feb 2007
    Posts
    39

    Re: How to port Symbian OS String Descriptors

    I Saw on this forum a guy porting stl on symbian, the project is called STLPort I think you should look for it.

  14. #14
    Registered User
    Join Date
    Oct 2006
    Location
    Cumbria, UK
    Posts
    4

    Re: How to port Symbian OS String Descriptors

    ... And of course you should take a look at our Symbian uSTL. That handles all the problems of conversion between std::string and Symbian OS descriptors. For Symbian 9 (UIQ3, S60E3).

    And it also gives small code sizes!

    http://www.penrillian.com/stl
    - Charles Weir
    Penrillian
    http://www.penrillian.com

  15. #15
    Regular Contributor
    Join Date
    Oct 2006
    Posts
    157

    Re: How to port Symbian OS String Descriptors

    Hi Charles,

    I'm using your Symbian uSTL with success.
    I got some issues when using std::string though:

    1. Using strings in class member function definition causes compilation errors (like 'string TheClass::GetString()'):
    /Development/Symbian/S60_3rd_FP1_2/EPOC32/include/ustl\/ualgo.h error: invalid function declaration Hello line 321 1180978443171 2586
    /Development/Symbian/S60_3rd_FP1_2/EPOC32/include/ustl\/ualgo.h macro "remove" passed 3 arguments, but takes just 1 Hello line 320 1180978443171 2585
    /Development/Symbian/S60_3rd_FP1_2/EPOC32/include/ustl\/uctralgo.h error: invalid function declaration Hello line 259 1180978443187 2588
    /Development/Symbian/S60_3rd_FP1_2/EPOC32/include/ustl\/uctralgo.h error: invalid function declaration Hello line 272 1180978443187 2590
    /Development/Symbian/S60_3rd_FP1_2/EPOC32/include/ustl\/uctralgo.h macro "remove" passed 2 arguments, but takes just 1 Hello line 258 1180978443187 2587
    /Development/Symbian/S60_3rd_FP1_2/EPOC32/include/ustl\/uctralgo.h macro "remove" passed 3 arguments, but takes just 1 Hello line 271 1180978443187 2589
    /Development/Symbian/S60_3rd_FP1_2/EPOC32/include/ustl\/ulist.h error: `remove' is not a member of `std' Hello line 52 1180978443187 2592
    /Development/Symbian/S60_3rd_FP1_2/EPOC32/include/ustl\/ulist.h macro "remove" passed 2 arguments, but takes just 1 Hello line 52 1180978443187 2591
    ...and then some minor issues:

    2. No string constructor that takes TDesC8 (only TDesC)

    3. Using std::string:esL() and std::string:es8L() is not possible on constant strings (since DesL() nor Des8L() is const). This forces me to use const_casts sometimes.

Similar Threads

  1. Can I test SMS receiver on the phone without port number?
    By brighteyes in forum Mobile Java General
    Replies: 10
    Last Post: 2007-11-26, 23:38
  2. String manipulation in Symbian.
    By khurshed79 in forum Symbian
    Replies: 3
    Last Post: 2005-08-09, 07:48
  3. Bluetooth port on Symbian
    By ronny60299 in forum Bluetooth Technology
    Replies: 0
    Last Post: 2004-12-24, 06:37
  4. D211 new linux driver 1.04 not working !!
    By franz_meyer in forum Multimodecards
    Replies: 1
    Last Post: 2002-12-12, 08:31

Posting Permissions

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