Ecere SDK/eC Forums • View topic - property what?




Ecere SDK/eC Forums

Ecere Developers Community

property what?

General help with the eC language.

property what?

Postby samsam598 » Thu Jan 12, 2012 8:48 pm

Greetings!

From explorer example below,I was completely confused for property char * which has no any identifier here,is it a anoynmous property or something else?

Thanks for your clarification.
Code: Select all
 
struct QuickPathTool
{
   char path[MAX_LOCATION];
 
   property char *   ///------>no identifier here?
   {
      set
      {
         char * unquoted;
         GetWorkingDir(path, MAX_LOCATION);
         if(value[0] == '\"')
            StripQuotes(value, unquoted);
         else
            unquoted = value;
         PathCat(path, unquoted);
         if(!FileExists(path))
         {
            // this incomplete functionality is not quite at it's place in this class
            int len;
            char * original = CopyString(path);
            while((len = strlen(path)))
            {
               StripLastDirectory(path, path);
               if(FileExists(path))
               {
                  // TODO: message location does not exist,
                  //       this higher location exists though
                  //       go there?
                  break;
               }
            }
            if(!len)
            {
               // TODO: message location does not exist,
               //       unable to select alternate location
            }
            path[0] = '\0';
            delete original;
         }
      }
      get { return path[0] ? path : null; }
   }
   property bool { get { return (bool)path[0]; } }
};
 
 
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: property what?

Postby jerome » Thu Jan 12, 2012 10:42 pm

Hi Sam! Welcome back!
We really missed you here!! The forums were so quiet without you :|

I will answer you in more details tomorrow, but just to get you started on this, these are 'conversion properties'. See chapter on page 100 in the Tao :) They are 'somewhat' akin to 'operator String' in C++.

I'll get back to you tomorrow!

Cheers,

Jerome
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Re: property what?

Postby samsam598 » Thu Jan 12, 2012 11:32 pm

jerome wrote:Hi Sam! Welcome back!
We really missed you here!! The forums were so quiet without you :|

I will answer you in more details tomorrow, but just to get you started on this, these are 'conversion properties'. See chapter on page 100 in the Tao :) They are 'somewhat' akin to 'operator String' in C++.

I'll get back to you tomorrow!

Cheers,

Jerome


Thanks Jerome,I am always here actually.But it is crazy busy recently as the Chinese New Year is coming.*_*

Acutally I have tons of stupid questions but shame to ask ..he he.

Regards,
Sam
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: property what?

Postby jerome » Sun Jan 15, 2012 12:30 am

Hi again Sam,

Yes quite crazy here also! We are leaving on Saturday for Vietnam to celebrate the new year with my wife's family as well :)

So, just to clarify, a property with only a type, and no name, is a conversion property. This makes it possible to convert the class (and vice-versa) to the data type whose conversion is being defined by the property. This is particularly useful with units, as it lets you establish a relationship. This relationship is then automatically used for anywhere a conversion is required, and serves the purpose of operator-overloading (on scalar types only. operator overloading would still be useful on things like vectors, matrices!).

So in your example, that property is just to allow to write:

QuickPathTool quickPathTool { };
char * string = quickPathTool;

or

quickPathTool = "whatever a quickpath string representation is";

Please let me know if you have any more question about these :)
The Tao chapter I previously mentioned covers it quite well, and the most interesting use really is for unit conversions, which is not what your example was about.

Regards,

Jerome
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm


Return to eC Language

Who is online

Users browsing this forum: No registered users and 2 guests

cron