1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/profiler/JSStreamWriter.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 JSSTREAMWRITER_H 1.10 +#define JSSTREAMWRITER_H 1.11 + 1.12 +#include <ostream> 1.13 +#include <stdlib.h> 1.14 +#include "nsDeque.h" 1.15 + 1.16 +class JSStreamWriter 1.17 +{ 1.18 +public: 1.19 + JSStreamWriter(std::ostream& aStream); 1.20 + ~JSStreamWriter(); 1.21 + 1.22 + void BeginObject(); 1.23 + void EndObject(); 1.24 + void BeginArray(); 1.25 + void EndArray(); 1.26 + void Name(const char *name); 1.27 + void Value(int value); 1.28 + void Value(double value); 1.29 + void Value(const char *value, size_t valueLength); 1.30 + void Value(const char *value); 1.31 + template <typename T> 1.32 + void NameValue(const char *aName, T aValue) 1.33 + { 1.34 + Name(aName); 1.35 + Value(aValue); 1.36 + } 1.37 + 1.38 +private: 1.39 + std::ostream& mStream; 1.40 + bool mNeedsComma; 1.41 + bool mNeedsName; 1.42 + 1.43 + nsDeque mStack; 1.44 + 1.45 + // This class can't be copied 1.46 + JSStreamWriter(const JSStreamWriter&); 1.47 + JSStreamWriter& operator=(const JSStreamWriter&); 1.48 + 1.49 + void* operator new(size_t); 1.50 + void* operator new[](size_t); 1.51 + void operator delete(void*) { 1.52 + // Since JSStreamWriter has a virtual destructor the compiler 1.53 + // has to provide a destructor in the object file that will call 1.54 + // operate delete in case there is a derived class since its 1.55 + // destructor won't know how to free this instance. 1.56 + abort(); 1.57 + } 1.58 + void operator delete[](void*); 1.59 +}; 1.60 + 1.61 +#endif