property what?

General help with the eC language.
Post Reply
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

property what?

Post by samsam598 »

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]; } }
};
 
 
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: property what?

Post by jerome »

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
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: property what?

Post by samsam598 »

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
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: property what?

Post by jerome »

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
Post Reply