Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there kind of "attribute" keyword in C++?

Tags:

c++

attributes

maybe I missed something, but I'm wondering about the following:

At the Mozilla Developer Pages about Coding Guidelines, I read the following:

Whenever you are retrieving or setting a single value without any context, you should use attributes. Don't use two methods when you could use one attribute. Using attributes logically connects the getting and setting of a value, and makes scripted code look cleaner.

This example has too many methods:

 interface nsIFoo : nsISupports {
     long getLength();
     void setLength(in long length);
     long getColor(); 
 };

The code below will generate the exact same C++ signature, but is more script-friendly.

interface nsIFoo : nsISupports {
    attribute long length;
    readonly attribute long color; 
};

What I'm thinking about is the attribute long length. I assume that this syntax aucomatically creates getter/setter methods.

  • But is that standard-C++ in any way?
  • Is this some mozilla specific stuff?
  • Where is this defined?
like image 500
phimuemue Avatar asked Feb 13 '11 11:02

phimuemue


2 Answers

Mozilla uses a language called IDL (interface definition language) to define interfaces for objects that are used in multilanguage contexts, such as both C++ and JavaScript. It compiles down into code in these two languages and therefore allows developers working on the project to have a single definition for their interfaces in as many languages as they'd like. So no, this isn't standard C++ code; it's something entirely different.

On a related note, interface and readonly aren't C++ keywords either. :-)

like image 106
templatetypedef Avatar answered Oct 08 '22 09:10

templatetypedef


This coding guideline applies to IDL, not C++, so no, attribute is not part of C++. The guidelines is taking about the C++ signatures that the IDL generates.

like image 43
CB Bailey Avatar answered Oct 08 '22 10:10

CB Bailey