text: /*!
   * @copyright
   * Copyright (c) 2015, Tymoteusz Blazejczyk
   *
   * @copyright
   * All rights reserved.
   *
   * @copyright
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met:
   *
   * @copyright
   * * Redistributions of source code must retain the above copyright notice, this
   *   list of conditions and the following disclaimer.
   *
   * @copyright
   * * Redistributions in binary form must reproduce the above copyright notice,
   *   this list of conditions and the following disclaimer in the documentation
   *   and/or other materials provided with the distribution.
   *
   * @copyright
   * * Neither the name of json-cxx nor the names of its
   *   contributors may be used to endorse or promote products derived from
   *   this software without specific prior written permission.
   *
   * @copyright
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   * POSSIBILITY OF SUCH DAMAGE.
   *
   * @file serializer.cpp
   *
   * @brief JSON serializer implementation
   * */
  
  #include "json/serializer.hpp"
  
  #include "json/formatter/compact.hpp"
  #include "json/writter/counter.hpp"
  #include "json/writter/string.hpp"
  
  using namespace json;
  
  Serializer& Serializer::operator<<(const Value& value) {
      formatter::Compact compact {};
      Formatter* fmt = m_formatter;
  
      if (nullptr == fmt) { fmt = &compact; }
  
      writter::Counter counter {};
      fmt->set_writter(&counter);
      fmt->execute(value);
  
      writter::String str {counter.get_count()};
      fmt->set_writter(&str);
      fmt->execute(value);
  
      m_serialized = str.move_string();
  
      return *this;
  }
  
  String& json::operator<<(String& str, Serializer& serializer) {
      str += serializer.m_serialized;
      serializer.clear();
      return str;
  }
  
  std::ostream& json::operator<<(std::ostream& os, Serializer& serializer) {
      os << serializer.m_serialized;
      serializer.clear();
      return os;
  }
  
  String& json::operator<<(String& str, Serializer&& serializer) {
      str += std::move(serializer.m_serialized);
      serializer.clear();
      return str;
  }
  
  std::ostream& json::operator<<(std::ostream& os, Serializer&& serializer) {
      os << std::move(serializer.m_serialized);
      serializer.clear();
      return os;
  }
  