embedding/components/commandhandler/src/nsCommandParams.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     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/. */
     7 #ifndef nsCommandParams_h__
     8 #define nsCommandParams_h__
    10 #include "nsString.h"
    11 #include "nsICommandParams.h"
    12 #include "nsCOMPtr.h"
    13 #include "pldhash.h"
    17 class nsCommandParams : public nsICommandParams
    18 {
    19 public:
    21                       nsCommandParams();
    22   virtual             ~nsCommandParams();
    25   NS_DECL_ISUPPORTS
    26   NS_DECL_NSICOMMANDPARAMS
    28   nsresult            Init();
    30 protected:
    32   struct HashEntry : public PLDHashEntryHdr
    33   {
    34     nsCString      mEntryName;
    36     uint8_t       mEntryType;
    37     union {
    39       bool                    mBoolean;
    40       int32_t                 mLong;
    41       double                  mDouble;
    42       nsString*               mString;
    43       nsCString*              mCString;
    44     } mData;
    46     nsCOMPtr<nsISupports>   mISupports;    
    48     HashEntry(uint8_t inType, const char * inEntryName)
    49     : mEntryName(inEntryName)
    50     , mEntryType(inType)
    51     {
    52       memset(&mData, 0, sizeof(mData));
    53       Reset(mEntryType);
    54     }
    56     HashEntry(const HashEntry& inRHS)
    57     : mEntryType(inRHS.mEntryType)
    58     {
    59       Reset(mEntryType);
    60       switch (mEntryType)
    61       {
    62         case eBooleanType:      mData.mBoolean = inRHS.mData.mBoolean;  break;
    63         case eLongType:         mData.mLong    = inRHS.mData.mLong;     break;
    64         case eDoubleType:       mData.mDouble  = inRHS.mData.mDouble;   break;
    65         case eWStringType:
    66           NS_ASSERTION(inRHS.mData.mString, "Source entry has no string");
    67           mData.mString = new nsString(*inRHS.mData.mString);
    68           break;      
    69         case eStringType:
    70           NS_ASSERTION(inRHS.mData.mCString, "Source entry has no string");
    71           mData.mCString = new nsCString(*inRHS.mData.mCString);
    72           break;      
    73         case eISupportsType:
    74           mISupports = inRHS.mISupports.get();    // additional addref
    75           break;
    76         default:
    77           NS_ERROR("Unknown type");
    78       }
    79     }
    81     ~HashEntry()
    82     {
    83       if (mEntryType == eWStringType)
    84         delete mData.mString;
    85       else if (mEntryType == eStringType)
    86         delete mData.mCString;
    87     }
    89     void Reset(uint8_t inNewType)
    90     {
    91       switch (mEntryType)
    92       {
    93         case eNoType:                                       break;
    94         case eBooleanType:      mData.mBoolean = false;  break;
    95         case eLongType:         mData.mLong = 0;            break;
    96         case eDoubleType:       mData.mDouble = 0.0;        break;
    97         case eWStringType:      delete mData.mString; mData.mString = nullptr;     break;
    98         case eISupportsType:    mISupports = nullptr;        break;    // clear the nsCOMPtr
    99         case eStringType:       delete mData.mCString; mData.mCString = nullptr;   break;
   100         default:
   101           NS_ERROR("Unknown type");
   102       }
   104       mEntryType = inNewType;
   105     }
   107   };
   110   HashEntry*          GetNamedEntry(const char * name);
   111   HashEntry*          GetIndexedEntry(int32_t index);
   112   uint32_t            GetNumEntries();
   114   nsresult            GetOrMakeEntry(const char * name, uint8_t entryType, HashEntry*& outEntry);
   116 protected:
   118   static PLDHashNumber HashKey(PLDHashTable *table, const void *key);
   120   static bool          HashMatchEntry(PLDHashTable *table,
   121                                       const PLDHashEntryHdr *entry, const void *key);
   123   static void          HashMoveEntry(PLDHashTable *table, const PLDHashEntryHdr *from,
   124                                      PLDHashEntryHdr *to);
   126   static void          HashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry);
   129 protected:
   131   enum {
   132     eNumEntriesUnknown      = -1
   133   };
   135   // this is going to have to use a pldhash, because we need to
   136   // be able to iterate through entries, passing names back
   137   // to the caller, which means that we need to store the names
   138   // internally.
   140   PLDHashTable    mValuesHash;
   142   // enumerator data
   143   int32_t         mCurEntry;
   144   int32_t         mNumEntries;      // number of entries at start of enumeration (-1 indicates not known)
   146   static const PLDHashTableOps    sHashOps;
   147 };
   150 #endif // nsCommandParams_h__

mercurial