xpcom/sample/nsSample.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsSample_h
     7 #define nsSample_h
     9 /**
    10  * A sample of XPConnect. This file is the header of an implementation
    11  * nsSample of the nsISample interface.
    12  *
    13  */
    15 #include "nsISample.h"
    16 #include "mozilla/Attributes.h"
    18 /**
    19  * SampleImpl is an implementation of the nsISample interface.  In XPCOM,
    20  * there can be more than one implementation of an given interface.  Class
    21  * IDs (CIDs) uniquely identify a particular implementation of an interface.
    22  * Interface IDs (IIDs) uniquely identify an interface.
    23  *
    24  * The CID is also a unique number that looks just like an IID
    25  * and uniquely identifies an implementation
    26  * {7CB5B7A0-07D7-11d3-BDE2-000064657374}
    27  */
    29 #define NS_SAMPLE_CID \
    30 { 0x7cb5b7a0, 0x7d7, 0x11d3, { 0xbd, 0xe2, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
    32 #define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
    35 class nsSampleImpl MOZ_FINAL : public nsISample
    36 {
    37 public:
    38     nsSampleImpl();
    40     /**
    41      * This macro expands into a declaration of the nsISupports interface.
    42      * Every XPCOM component needs to implement nsISupports, as it acts
    43      * as the gateway to other interfaces this component implements.  You
    44      * could manually declare QueryInterface, AddRef, and Release instead
    45      * of using this macro, but why?
    46      */
    47     // nsISupports interface
    48     NS_DECL_ISUPPORTS
    50     /**
    51      * This macro is defined in the nsISample.h file, and is generated
    52      * automatically by the xpidl compiler.  It expands to
    53      * declarations of all of the methods required to implement the
    54      * interface.  xpidl will generate a NS_DECL_[INTERFACENAME] macro
    55      * for each interface that it processes.
    56      *
    57      * The methods of nsISample are discussed individually below, but
    58      * commented out (because this macro already defines them.)
    59      */
    60     NS_DECL_NSISAMPLE
    62     /**
    63      * The following is an explanation of how the interface header
    64      * file expands to for a c++ implementation. NS_DELC_NSISAMPLE
    65      * takes care of defining the right c++ implementation.
    66      *
    67      * The following if provided for more understanding.
    68      *
    69      * NS_IMETHOD expands to the standard XPCOM return type.  XPCOM methods
    70      * should never return any other type.  The return value is used
    71      * behind the scenes by the XPConnect runtime to figure out if the call
    72      * failed in any way.
    73      * These methods were generated by "attribute string Value" in 
    74      * nsISample.idl.  When reflected into JavaScript, XPCOM will use these
    75      * calls as Getter/Setter ops, so that they can be called transparently
    76      * as "sample.Value='foo';" and "var val = sample.Value"
    77      */
    78     /* NS_IMETHOD GetValue(char * *aValue); */
    79     /* NS_IMETHOD SetValue(char * aValue); */
    81     /**
    82      * The const came from the "in" specifier in nsISample.idl.  "in"
    83      * specifies that the value of this parameter is used only for input,
    84      * this method is not allowed to modify the contents of the buffer.
    85      */
    86     /* NS_IMETHOD WriteValue(const char *aPrefix); */
    88     /**
    89      * nsISample.idl specifies all of its string types as string, instead
    90      * of wstring (wide string), the Unicode type.  If the world were a
    91      * perfect place, all normal strings in XPCOM interfaces would be unicode.
    92      * If this type had been specified as wstring, it would appear as
    93      * char16_t * in C++, which is the NSPR type for unicode characters.
    94      */
    95     /* NS_IMETHOD Poke(const char* aValue); */
    97 private:
    98     ~nsSampleImpl();
   100     char* mValue;
   101 };
   103 #endif

mercurial