<commit_before>// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TracedValue_h
#define TracedValue_h

#include "platform/EventTracer.h"

#include "wtf/PassRefPtr.h"
#include "wtf/text/WTFString.h"

namespace WebCore {
class JSONArray;
class JSONObject;
class JSONValue;
template<class T> class TracedArray;

class PLATFORM_EXPORT TracedValueBase {
    WTF_MAKE_NONCOPYABLE(TracedValueBase);
protected:
    TracedValueBase();
    ~TracedValueBase();

    void setInteger(const char* name, int value);
    void setDouble(const char* name, double);
    void setBoolean(const char* name, bool value);
    void setString(const char* name, const String& value);
    void beginDictionaryNamed(const char* name);
    void beginArrayNamed(const char* name);
    void endCurrentDictionary();

    void pushInteger(int);
    void pushDouble(double);
    void pushBoolean(bool);
    void pushString(const String&);
    void pushArray();
    void pushDictionary();
    void endCurrentArray();

    JSONObject* currentDictionary() const;
    JSONArray* currentArray() const;

    Vector<RefPtr<JSONValue> > m_stack;
};

template <class OwnerType>
class TracedDictionary : public TracedValueBase {
    WTF_MAKE_NONCOPYABLE(TracedDictionary);
public:
    OwnerType& endDictionary()
    {
        ASSERT(m_stack.size() == nestingLevel);
        endCurrentDictionary();
        return *reinterpret_cast<OwnerType*>(this);
    }

    TracedDictionary<TracedDictionary<OwnerType> >& beginDictionary(const char* name)
    {
        beginDictionaryNamed(name);
        return *reinterpret_cast<TracedDictionary<TracedDictionary<OwnerType> >* >(this);
    }
    TracedArray<TracedDictionary<OwnerType> >& beginArray(const char* name)
    {
        beginArrayNamed(name);
        return *reinterpret_cast<TracedArray<TracedDictionary<OwnerType> >* >(this);
    }
    TracedDictionary<OwnerType>& setInteger(const char* name, int value)
    {
        TracedValueBase::setInteger(name, value);
        return *this;
    }
    TracedDictionary<OwnerType>& setDouble(const char* name, double value)
    {
        TracedValueBase::setDouble(name, value);
        return *this;
    }
    TracedDictionary<OwnerType>& setBoolean(const char* name, bool value)
    {
        TracedValueBase::setBoolean(name, value);
        return *this;
    }
    TracedDictionary<OwnerType>& setString(const char* name, const String& value)
    {
        TracedValueBase::setString(name, value);
        return *this;
    }

    static const size_t nestingLevel = OwnerType::nestingLevel + 1;

private:
    TracedDictionary();
    ~TracedDictionary();
};

template <class OwnerType>
class TracedArray : public TracedValueBase {
    WTF_MAKE_NONCOPYABLE(TracedArray);
public:
    TracedDictionary<TracedArray<OwnerType> >& beginDictionary()
    {
        pushDictionary();
        return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(this);
    }
    TracedDictionary<TracedArray<OwnerType> >& beginArray()
    {
        pushArray();
        return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(this);
    }
    OwnerType& endArray()
    {
        ASSERT(m_stack.size() == nestingLevel);
        endCurrentArray();
        return *reinterpret_cast<OwnerType*>(this);
    }

    TracedArray<OwnerType>& pushInteger(int value)
    {
        TracedValueBase::pushInteger(value);
        return *this;
    }
    TracedArray<OwnerType>& pushDouble(double value)
    {
        TracedValueBase::pushDouble(value);
        return *this;
    }
    TracedArray<OwnerType>& pushBoolean(bool value)
    {
        TracedValueBase::pushBoolean(value);
        return *this;
    }
    TracedArray<OwnerType>& pushString(const String& value)
    {
        TracedValueBase::pushString(value);
        return *this;
    }

    static const size_t nestingLevel = OwnerType::nestingLevel + 1;

private:
    TracedArray();
    ~TracedArray();
};

class PLATFORM_EXPORT TracedValue : public TracedValueBase {
    WTF_MAKE_NONCOPYABLE(TracedValue);
public:
    TracedValue();
    ~TracedValue();

    TracedDictionary<TracedValue>& beginDictionary(const char* name);
    TracedArray<TracedValue>& beginArray(const char* name);
    TracedValue& setInteger(const char* name, int value)
    {
        TracedValueBase::setInteger(name, value);
        return *this;
    }
    TracedValue& setDouble(const char* name, double value)
    {
        TracedValueBase::setDouble(name, value);
        return *this;
    }
    TracedValue& setBoolean(const char* name, bool value)
    {
        TracedValueBase::setBoolean(name, value);
        return *this;
    }
    TracedValue& setString(const char* name, const String& value)
    {
        TracedValueBase::setString(name, value);
        return *this;
    }
    PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish();

    static const size_t nestingLevel = 1;
};

} // namespace WebCore

#endif // TracedValue_h<commit_msg>Non-template base classes for TracedArray and TracedDictionary.<commit_after>// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TracedValue_h
#define TracedValue_h

#include "platform/EventTracer.h"

#include "wtf/PassRefPtr.h"
#include "wtf/text/WTFString.h"

namespace WebCore {
class JSONArray;
class JSONObject;
class JSONValue;
class TracedArrayBase;
template<class T> class TracedArray;
template<class T> class TracedDictionary;

class PLATFORM_EXPORT TracedValueBase {
    WTF_MAKE_NONCOPYABLE(TracedValueBase);
protected:
    TracedValueBase();
    ~TracedValueBase();

    void setInteger(const char* name, int value);
    void setDouble(const char* name, double);
    void setBoolean(const char* name, bool value);
    void setString(const char* name, const String& value);
    void beginDictionaryNamed(const char* name);
    void beginArrayNamed(const char* name);
    void endCurrentDictionary();

    void pushInteger(int);
    void pushDouble(double);
    void pushBoolean(bool);
    void pushString(const String&);
    void pushArray();
    void pushDictionary();
    void endCurrentArray();

    JSONObject* currentDictionary() const;
    JSONArray* currentArray() const;

    Vector<RefPtr<JSONValue> > m_stack;
};

class TracedDictionaryBase : public TracedValueBase {
    WTF_MAKE_NONCOPYABLE(TracedDictionaryBase);
private:
    typedef TracedDictionaryBase SelfType;
public:
    TracedDictionary<SelfType>& beginDictionary(const char* name)
    {
        beginDictionaryNamed(name);
        return *reinterpret_cast<TracedDictionary<SelfType>*>(this);
    }
    TracedArray<SelfType>& beginArray(const char* name)
    {
        beginArrayNamed(name);
        return *reinterpret_cast<TracedArray<SelfType>*>(this);
    }
    SelfType& setInteger(const char* name, int value)
    {
        TracedValueBase::setInteger(name, value);
        return *this;
    }
    SelfType& setDouble(const char* name, double value)
    {
        TracedValueBase::setDouble(name, value);
        return *this;
    }
    SelfType& setBoolean(const char* name, bool value)
    {
        TracedValueBase::setBoolean(name, value);
        return *this;
    }
    SelfType& setString(const char* name, const String& value)
    {
        TracedValueBase::setString(name, value);
        return *this;
    }
private:
    TracedDictionaryBase();
    ~TracedDictionaryBase();
};

template <class OwnerType>
class TracedDictionary : public TracedDictionaryBase {
    WTF_MAKE_NONCOPYABLE(TracedDictionary);
private:
    typedef TracedDictionary<OwnerType> SelfType;
public:
    OwnerType& endDictionary()
    {
        TracedValueBase::endCurrentDictionary();
        return *reinterpret_cast<OwnerType*>(this);
    }

    TracedDictionary<SelfType>& beginDictionary(const char* name)
    {
        TracedDictionaryBase::beginDictionary(name);
        return *reinterpret_cast<TracedDictionary<SelfType>*>(this);
    }
    TracedArray<SelfType>& beginArray(const char* name)
    {
        TracedDictionaryBase::beginArray(name);
        return *reinterpret_cast<TracedArray<SelfType>*>(this);
    }
    SelfType& setInteger(const char* name, int value)
    {
        TracedDictionaryBase::setInteger(name, value);
        return *this;
    }
    SelfType& setDouble(const char* name, double value)
    {
        TracedDictionaryBase::setDouble(name, value);
        return *this;
    }
    SelfType& setBoolean(const char* name, bool value)
    {
        TracedDictionaryBase::setBoolean(name, value);
        return *this;
    }
    SelfType& setString(const char* name, const String& value)
    {
        TracedDictionaryBase::setString(name, value);
        return *this;
    }

private:
    TracedDictionary();
    ~TracedDictionary();
};

class TracedArrayBase : public TracedValueBase {
    WTF_MAKE_NONCOPYABLE(TracedArrayBase);
private:
    typedef TracedArrayBase SelfType;
public:
    TracedDictionary<SelfType>& beginDictionary()
    {
        pushDictionary();
        return *reinterpret_cast<TracedDictionary<SelfType>*>(this);
    }
    TracedArray<SelfType>& beginArray()
    {
        pushArray();
        return *reinterpret_cast<TracedArray<SelfType>*>(this);
    }

    SelfType& pushInteger(int value)
    {
        TracedValueBase::pushInteger(value);
        return *this;
    }
    SelfType& pushDouble(double value)
    {
        TracedValueBase::pushDouble(value);
        return *this;
    }
    SelfType& pushBoolean(bool value)
    {
        TracedValueBase::pushBoolean(value);
        return *this;
    }
    SelfType& pushString(const String& value)
    {
        TracedValueBase::pushString(value);
        return *this;
    }

private:
    TracedArrayBase();
    ~TracedArrayBase();
};

template <class OwnerType>
class TracedArray : public TracedArrayBase {
    WTF_MAKE_NONCOPYABLE(TracedArray);
private:
    typedef TracedArray<OwnerType> SelfType;
public:
    OwnerType& endArray()
    {
        TracedValueBase::endCurrentArray();
        return *reinterpret_cast<OwnerType*>(this);
    }

    TracedDictionary<SelfType >& beginDictionary()
    {
        TracedArrayBase::beginDictionary();
        return *reinterpret_cast<TracedDictionary<SelfType>*>(this);
    }
    TracedArray<SelfType >& beginArray()
    {
        TracedArrayBase::beginArray();
        return *reinterpret_cast<TracedArray<SelfType>*>(this);
    }

    SelfType& pushInteger(int value)
    {
        TracedArrayBase::pushInteger(value);
        return *this;
    }
    SelfType& pushDouble(double value)
    {
        TracedArrayBase::pushDouble(value);
        return *this;
    }
    SelfType& pushBoolean(bool value)
    {
        TracedArrayBase::pushBoolean(value);
        return *this;
    }
    SelfType& pushString(const String& value)
    {
        TracedArrayBase::pushString(value);
        return *this;
    }

private:
    TracedArray();
    ~TracedArray();
};

class PLATFORM_EXPORT TracedValue : public TracedValueBase {
    WTF_MAKE_NONCOPYABLE(TracedValue);
private:
    typedef TracedValue SelfType;
public:
    TracedValue();
    ~TracedValue();

    TracedDictionary<SelfType>& beginDictionary(const char* name);
    TracedArray<SelfType>& beginArray(const char* name);

    SelfType& setInteger(const char* name, int value)
    {
        TracedValueBase::setInteger(name, value);
        return *this;
    }
    SelfType& setDouble(const char* name, double value)
    {
        TracedValueBase::setDouble(name, value);
        return *this;
    }
    SelfType& setBoolean(const char* name, bool value)
    {
        TracedValueBase::setBoolean(name, value);
        return *this;
    }
    SelfType& setString(const char* name, const String& value)
    {
        TracedValueBase::setString(name, value);
        return *this;
    }

    PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish();
};

} // namespace WebCore

#endif // TracedValue_h
{'fraction_non_alphanumeric': 0.10485275819162174, 'fraction_numerical': 0.0009124844462878474, 'mean_word_length': 3.4834510970621047, 'pattern_counts': {'":': 0, '<': 78, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4413446', 'n_tokens_mistral': 3635, 'n_tokens_neox': 3559, 'n_words': 768}