xpcom/sample/nsSample.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/sample/nsSample.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsSample_h
    1.10 +#define nsSample_h
    1.11 +
    1.12 +/**
    1.13 + * A sample of XPConnect. This file is the header of an implementation
    1.14 + * nsSample of the nsISample interface.
    1.15 + *
    1.16 + */
    1.17 +
    1.18 +#include "nsISample.h"
    1.19 +#include "mozilla/Attributes.h"
    1.20 +
    1.21 +/**
    1.22 + * SampleImpl is an implementation of the nsISample interface.  In XPCOM,
    1.23 + * there can be more than one implementation of an given interface.  Class
    1.24 + * IDs (CIDs) uniquely identify a particular implementation of an interface.
    1.25 + * Interface IDs (IIDs) uniquely identify an interface.
    1.26 + *
    1.27 + * The CID is also a unique number that looks just like an IID
    1.28 + * and uniquely identifies an implementation
    1.29 + * {7CB5B7A0-07D7-11d3-BDE2-000064657374}
    1.30 + */
    1.31 +
    1.32 +#define NS_SAMPLE_CID \
    1.33 +{ 0x7cb5b7a0, 0x7d7, 0x11d3, { 0xbd, 0xe2, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
    1.34 +
    1.35 +#define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
    1.36 +
    1.37 +
    1.38 +class nsSampleImpl MOZ_FINAL : public nsISample
    1.39 +{
    1.40 +public:
    1.41 +    nsSampleImpl();
    1.42 +
    1.43 +    /**
    1.44 +     * This macro expands into a declaration of the nsISupports interface.
    1.45 +     * Every XPCOM component needs to implement nsISupports, as it acts
    1.46 +     * as the gateway to other interfaces this component implements.  You
    1.47 +     * could manually declare QueryInterface, AddRef, and Release instead
    1.48 +     * of using this macro, but why?
    1.49 +     */
    1.50 +    // nsISupports interface
    1.51 +    NS_DECL_ISUPPORTS
    1.52 +
    1.53 +    /**
    1.54 +     * This macro is defined in the nsISample.h file, and is generated
    1.55 +     * automatically by the xpidl compiler.  It expands to
    1.56 +     * declarations of all of the methods required to implement the
    1.57 +     * interface.  xpidl will generate a NS_DECL_[INTERFACENAME] macro
    1.58 +     * for each interface that it processes.
    1.59 +     *
    1.60 +     * The methods of nsISample are discussed individually below, but
    1.61 +     * commented out (because this macro already defines them.)
    1.62 +     */
    1.63 +    NS_DECL_NSISAMPLE
    1.64 +
    1.65 +    /**
    1.66 +     * The following is an explanation of how the interface header
    1.67 +     * file expands to for a c++ implementation. NS_DELC_NSISAMPLE
    1.68 +     * takes care of defining the right c++ implementation.
    1.69 +     *
    1.70 +     * The following if provided for more understanding.
    1.71 +     *
    1.72 +     * NS_IMETHOD expands to the standard XPCOM return type.  XPCOM methods
    1.73 +     * should never return any other type.  The return value is used
    1.74 +     * behind the scenes by the XPConnect runtime to figure out if the call
    1.75 +     * failed in any way.
    1.76 +     * These methods were generated by "attribute string Value" in 
    1.77 +     * nsISample.idl.  When reflected into JavaScript, XPCOM will use these
    1.78 +     * calls as Getter/Setter ops, so that they can be called transparently
    1.79 +     * as "sample.Value='foo';" and "var val = sample.Value"
    1.80 +     */
    1.81 +    /* NS_IMETHOD GetValue(char * *aValue); */
    1.82 +    /* NS_IMETHOD SetValue(char * aValue); */
    1.83 +
    1.84 +    /**
    1.85 +     * The const came from the "in" specifier in nsISample.idl.  "in"
    1.86 +     * specifies that the value of this parameter is used only for input,
    1.87 +     * this method is not allowed to modify the contents of the buffer.
    1.88 +     */
    1.89 +    /* NS_IMETHOD WriteValue(const char *aPrefix); */
    1.90 +
    1.91 +    /**
    1.92 +     * nsISample.idl specifies all of its string types as string, instead
    1.93 +     * of wstring (wide string), the Unicode type.  If the world were a
    1.94 +     * perfect place, all normal strings in XPCOM interfaces would be unicode.
    1.95 +     * If this type had been specified as wstring, it would appear as
    1.96 +     * char16_t * in C++, which is the NSPR type for unicode characters.
    1.97 +     */
    1.98 +    /* NS_IMETHOD Poke(const char* aValue); */
    1.99 +
   1.100 +private:
   1.101 +    ~nsSampleImpl();
   1.102 +
   1.103 +    char* mValue;
   1.104 +};
   1.105 +
   1.106 +#endif

mercurial