michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef JSSTREAMWRITER_H michael@0: #define JSSTREAMWRITER_H michael@0: michael@0: #include michael@0: #include michael@0: #include "nsDeque.h" michael@0: michael@0: class JSStreamWriter michael@0: { michael@0: public: michael@0: JSStreamWriter(std::ostream& aStream); michael@0: ~JSStreamWriter(); michael@0: michael@0: void BeginObject(); michael@0: void EndObject(); michael@0: void BeginArray(); michael@0: void EndArray(); michael@0: void Name(const char *name); michael@0: void Value(int value); michael@0: void Value(double value); michael@0: void Value(const char *value, size_t valueLength); michael@0: void Value(const char *value); michael@0: template michael@0: void NameValue(const char *aName, T aValue) michael@0: { michael@0: Name(aName); michael@0: Value(aValue); michael@0: } michael@0: michael@0: private: michael@0: std::ostream& mStream; michael@0: bool mNeedsComma; michael@0: bool mNeedsName; michael@0: michael@0: nsDeque mStack; michael@0: michael@0: // This class can't be copied michael@0: JSStreamWriter(const JSStreamWriter&); michael@0: JSStreamWriter& operator=(const JSStreamWriter&); michael@0: michael@0: void* operator new(size_t); michael@0: void* operator new[](size_t); michael@0: void operator delete(void*) { michael@0: // Since JSStreamWriter has a virtual destructor the compiler michael@0: // has to provide a destructor in the object file that will call michael@0: // operate delete in case there is a derived class since its michael@0: // destructor won't know how to free this instance. michael@0: abort(); michael@0: } michael@0: void operator delete[](void*); michael@0: }; michael@0: michael@0: #endif