Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef JSSTREAMWRITER_H |
michael@0 | 7 | #define JSSTREAMWRITER_H |
michael@0 | 8 | |
michael@0 | 9 | #include <ostream> |
michael@0 | 10 | #include <stdlib.h> |
michael@0 | 11 | #include "nsDeque.h" |
michael@0 | 12 | |
michael@0 | 13 | class JSStreamWriter |
michael@0 | 14 | { |
michael@0 | 15 | public: |
michael@0 | 16 | JSStreamWriter(std::ostream& aStream); |
michael@0 | 17 | ~JSStreamWriter(); |
michael@0 | 18 | |
michael@0 | 19 | void BeginObject(); |
michael@0 | 20 | void EndObject(); |
michael@0 | 21 | void BeginArray(); |
michael@0 | 22 | void EndArray(); |
michael@0 | 23 | void Name(const char *name); |
michael@0 | 24 | void Value(int value); |
michael@0 | 25 | void Value(double value); |
michael@0 | 26 | void Value(const char *value, size_t valueLength); |
michael@0 | 27 | void Value(const char *value); |
michael@0 | 28 | template <typename T> |
michael@0 | 29 | void NameValue(const char *aName, T aValue) |
michael@0 | 30 | { |
michael@0 | 31 | Name(aName); |
michael@0 | 32 | Value(aValue); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | private: |
michael@0 | 36 | std::ostream& mStream; |
michael@0 | 37 | bool mNeedsComma; |
michael@0 | 38 | bool mNeedsName; |
michael@0 | 39 | |
michael@0 | 40 | nsDeque mStack; |
michael@0 | 41 | |
michael@0 | 42 | // This class can't be copied |
michael@0 | 43 | JSStreamWriter(const JSStreamWriter&); |
michael@0 | 44 | JSStreamWriter& operator=(const JSStreamWriter&); |
michael@0 | 45 | |
michael@0 | 46 | void* operator new(size_t); |
michael@0 | 47 | void* operator new[](size_t); |
michael@0 | 48 | void operator delete(void*) { |
michael@0 | 49 | // Since JSStreamWriter has a virtual destructor the compiler |
michael@0 | 50 | // has to provide a destructor in the object file that will call |
michael@0 | 51 | // operate delete in case there is a derived class since its |
michael@0 | 52 | // destructor won't know how to free this instance. |
michael@0 | 53 | abort(); |
michael@0 | 54 | } |
michael@0 | 55 | void operator delete[](void*); |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | #endif |