Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

Estring


Estring

Postby Ryumaster » Feb 26, 2008 @ 5:15pm

Hi, edgelib! I've just notice, there is new EString class. I really can't imagine, how it works. Before this I used StrCpy to copy some text into variable.
Lets say, it was:

Code: Select all



ClassEStd::StrCpy(drawtext, "Start Game");

buffer->DrawFont(buffer->GetWidth() / 2, ypos, &shared->font, drawtext, EFX_COLORKEY | EFX_COLORIZE | EFO_HCENTER, textcolor);
3 lines; 0 keywds; 1 nums; 26 ops; 1 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


Now, how would this part of code look like using EString? maybe my question is sort of stupid, but I just wanna know. because "Also, it will handle memory allocation and protection automatically." attracts me a lot.
I love postindustrial life.
User avatar
Ryumaster
pm Member
 
Posts: 86
Joined: Sep 17, 2006 @ 11:24am
Location: Lithuania, Kaunas


Postby edge » Feb 27, 2008 @ 11:20am

Hi Ryumaster,

You can create new EString objects, and cast them to WCHAR when using them as a parameter to functions. For example:

Code: Select all


EString test("hello");
ClassEConsole::MsgWindow((WCHAR *)test);
2 lines; 0 keywds; 0 nums; 11 ops; 1 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


You can even add strings and do more complicated things like:

Code: Select all

ClassEConsole::MsgWindow((WCHAR *)(EString("hello") + "world"));
1 lines; 0 keywds; 0 nums; 13 ops; 2 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


This creates a new string object, adds another string and casts it to WCHAR.
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby Ryumaster » Mar 7, 2008 @ 8:55am

WOW! That is great! Looks like now I can add cool effects to my dialogs system. I'll take a look on it for sure.
I love postindustrial life.
User avatar
Ryumaster
pm Member
 
Posts: 86
Joined: Sep 17, 2006 @ 11:24am
Location: Lithuania, Kaunas


Postby Zalo » Mar 11, 2008 @ 11:55am

Hi, Edge I have noticed some problems with this class.

The declaration of operator= with EString as parameter is like this

Code: Select all

EString &operator=(EString &str)
1 lines; 1 keywds; 0 nums; 5 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


instead of

Code: Select all

EString &operator=(const EString &str)
1 lines; 2 keywds; 0 nums; 5 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


I don't understand why, because the othe two options (with char* and WCHAR*) receive this param as const.

The problem is that I have implemented a Vector class, similar to std::vector, and I have instantiated a Vector< EString >. I can't add an element to this vector because internally my vector calls to operator= wich receives a const &EString param.

If you try something like
Code: Select all



const MenuItem m1;
MenuItem m2;
m2 = m1;
3 lines; 1 keywds; 0 nums; 4 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


you'll see it doesn't compile because of that operator=. Can you change it?
Zalo
pm Member
 
Posts: 25
Joined: Nov 5, 2007 @ 4:23pm
Location: Spain


Postby Ryumaster » Mar 11, 2008 @ 2:10pm

Btw, EString worked great for me in many cases. But if I supply it as base for filename ( I used WCHAR filename[25] before), I get heap corruption errors. That is not a problem for me, cause I'm using WCHAR for filenames, but just in case You did not know.
I love postindustrial life.
User avatar
Ryumaster
pm Member
 
Posts: 86
Joined: Sep 17, 2006 @ 11:24am
Location: Lithuania, Kaunas


Postby edge » Mar 14, 2008 @ 2:32pm

Zalo:
The non-const parameter was the cause of an internal issue. The parameter will be constant in the next release.

Ryumaster:
It's odd that the heap corruption issues only occur with files. Could you try the following test (here it works correctly)?

Code: Select all









ClassEFile ef;
if (ef.Open((WCHAR *)(EString(ecd.dat->currentpath) + "test.txt") , EFOF_READ))
{
    char filetext[512];
    ef.Read(filetext, ef.Size());
    filetext[ef.Size()] = 0;
    ClassEConsole::MsgWindow(filetext);
    ef.Close();
}
9 lines; 2 keywds; 2 nums; 47 ops; 1 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby Zalo » Mar 25, 2008 @ 5:19pm

There is also a problem with the operators. It seems that
Code: Select all



EString &operator+(const char *str)
EString &operator+(const WCHAR *str)
EString &operator+(const EString &str)
3 lines; 7 keywds; 0 nums; 15 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  

Are changing the internal value of the object EString when this task in C++ is always delegated to operator+=.
Something like this
Code: Select all

str = str + c;
1 lines; 0 keywds; 0 nums; 3 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  

compiles but thows an exception an instead I have to write
Code: Select all

str + c;
1 lines; 0 keywds; 0 nums; 2 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  

wich looks pretty weird for me
Zalo
pm Member
 
Posts: 25
Joined: Nov 5, 2007 @ 4:23pm
Location: Spain


Postby edge » Mar 26, 2008 @ 10:16am

Hi Zalo,

Can you tell me if the issue still occurs with the latest EDGELIB (version 3.60)?

This test here works without any problems:
Code: Select all









//Callback: Called before the display mode changes
ERESULT ClassMain::OnInit(ENATIVETYPE instance)
{
    EString str = "hello";
    EString c = "world";
    str = str + c;
    ClassEConsole::MsgWindow((WCHAR *)str);
    return(E_OK);
}
9 lines; 1 keywds; 0 nums; 24 ops; 2 strs; 1 coms    Syntactic Coloring v0.4 - Dan East  
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby Zalo » Mar 26, 2008 @ 12:06pm

Hi, Edge.

It is working fine now. But I still think that operator+ shouldn't modify anything. If you write
Code: Select all

str2 = str1 + c;
1 lines; 0 keywds; 0 nums; 3 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  

both str2 and str1 are modified
Zalo
pm Member
 
Posts: 25
Joined: Nov 5, 2007 @ 4:23pm
Location: Spain


Postby Zalo » Mar 26, 2008 @ 12:14pm

Hi, again ^_^

I have a new problem with this class. I have an EString and I am trying to clear it. Something like this:
Code: Select all


EString str1 = "ABCDEF";
str1 = "";
2 lines; 0 keywds; 0 nums; 4 ops; 2 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  

The value for str1 after that is still "ABCDEF". This only happens with "". If I assign " " everything is ok
Zalo
pm Member
 
Posts: 25
Joined: Nov 5, 2007 @ 4:23pm
Location: Spain


Postby edge » Mar 26, 2008 @ 12:55pm

Hi Zalo,

To temporary fix the empty string assignment problem, we recommend using EString::Trunc to make it empty. We will investigate the other issue with operator+.
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby Zalo » Apr 2, 2008 @ 3:05pm

Hello, Edge.

I have just updated to the new version (3.60) There is a bug using Series 60 3rd edition when trying to initilize an EString like this:

Code: Select all

EString str = "Hello world";
1 lines; 0 keywds; 0 nums; 2 ops; 1 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


When I try to compile this with EDGELIB builder I get:

Code: Select all






helloworld.cpp: In member function `virtual long int ClassMain::OnDisplayInit(int, ClassEDisplay*)':
helloworld.cpp:90: error: no matching function for call to `EString::EString(EString)'
C://Develop//Edge//Edge//include/extapi/dataapi.h:70: note: candidates are: EString::EString(EString&)
C://Develop//Edge//Edge//include/extapi/dataapi.h:69: note:                 EString::EString(const short unsigned int*)
C://Develop//Edge//Edge//include/extapi/dataapi.h:68: note:                 EString::EString(const char*)
helloworld.cpp:90: error:   initializing temporary from result of `EString::EString(const char*)'
6 lines; 6 keywds; 2 nums; 29 ops; 0 strs; 3 coms    Syntactic Coloring v0.4 - Dan East  


It is only happening with series 60 3rd edition. I can compile for pocket pc and series 60 1st edition without any problem. For Series 60 3rd edition I have to write the previous code like this:


Code: Select all

EString str("Hello world");
1 lines; 0 keywds; 0 nums; 3 ops; 1 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  
Zalo
pm Member
 
Posts: 25
Joined: Nov 5, 2007 @ 4:23pm
Location: Spain


Postby edge » Apr 3, 2008 @ 3:33pm

Hi Zalo,

We've changed the constructor parameter to a const EString, instead of a normal EString. This will fix the compiler issue on Series 60 third edition. It will be available in the next release.
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby Freddy » Apr 10, 2008 @ 9:55am

I stumbled on these bugs while using EString as well. Any ETA when the modifiying of s2 in s1=s2+"test" and the s1="" will be fixed?

I also noticed Get() does not returns a const like it should. I wanted to store an EString into EFile and figured I had to use GetDataSize(), but for "test" it returns 5 (4+0-terminated, or 1-byte length indicator+4 chars?). This forced me to make a work-around like this:

Code: Select all



unsigned char iSize=(unsigned char)(sStr.Length()*sizeof(WCHAR));
ef.Write(&iSize,sizeof(iSize));
ef.Write(sStr.Get(),iSize);
3 lines; 6 keywds; 0 nums; 28 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


(For strings below 128 chars)


For reading from files I had to use:

Code: Select all









10 
unsigned char iSize=0;
ef.Read(&iSize,sizeof(iSize));
WCHAR chr;
/* bugfix since sStr="" does not work
   http://www.pocketmatrix.com/forums/viewtopic.php?t=28434 :*/

sStr.Trunc(0);
for(unsigned char i=0;i<iSize;i+=sizeof(WCHAR)) {
  ef.Read(&chr,sizeof(WCHAR));
  sStr.CatChr(chr);
}
10 lines; 8 keywds; 3 nums; 39 ops; 0 strs; 1 coms    Syntactic Coloring v0.4 - Dan East  


Alternatives would be appreciated :)
Freddy
pm Member
 
Posts: 2
Joined: Apr 10, 2008 @ 9:43am


Postby edge » Apr 10, 2008 @ 7:37pm

Hi Freddy,

Fixes for EString will probably be added in the EDGELIB 3.70 release.

For reading the EString value from a file we recommend allocating memory temporarily and read in the whole string at once.
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Return to EDGELIB


Sort


Forum Description

Powerful and affordable C++ middleware solution covering true multi-platform 2D, 3D and network features for Apple iPhone, Windows Mobile, Symbian S60, UIQ, Linux and Windows desktop.

Moderator:

edge

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron