<commit_before>// Copyright (c) 2016, <NAME>,  Object Computing, Inc.
// All rights reserved.
//
// This file is part of mFAST.
// See the file license.txt for licensing information.
#include "../mfast_coder_export.h"
#include "../../field_visitor.h"
#include "../../sequence_ref.h"
#include "../../malloc_allocator.h"
#include "../fast_encoder.h"
#include "../common/template_repo.h"
#include "../common/exceptions.h"
#include "../../output.h"
#include "encoder_presence_map.h"
#include "encoder_field_operator.h"
#include "fast_ostream.h"
#include "resizable_fast_ostreambuf.h"

namespace mfast {
struct fast_encoder_impl;

struct fast_encoder_impl : simple_template_repo_t {
  fast_ostream strm_;

  int64_t active_message_id_;
  encoder_presence_map *current_;

  fast_encoder_impl(allocator *alloc);
  ~fast_encoder_impl();
  encoder_presence_map &current_pmap();

  struct pmap_state {
    encoder_presence_map pmap_;
    encoder_presence_map *prev_pmap_;

    pmap_state() : prev_pmap_(nullptr) {}
  };

  void setup_pmap(pmap_state &state, std::size_t sz) {
    state.prev_pmap_ = this->current_;
    this->current_ = &state.pmap_;
    state.pmap_.init(&this->strm_, sz);
  }

  void commit_pmap(pmap_state &state) {
    if (state.prev_pmap_) {
      state.pmap_.commit();
      this->current_ = state.prev_pmap_;
    }
  }

  void visit(enum_cref cref) {
    this->visit(reinterpret_cast<uint64_cref &>(cref));
  }

  template <typename SimpleCRef> void visit(SimpleCRef cref);

  template <typename IntType> void visit(int_vector_cref<IntType> cref);

  void visit(group_cref cref, int);
  void visit(sequence_cref, int);
  void visit(sequence_element_cref cref, int);
  void visit(nested_message_cref, int);

  void visit(message_cref cref, bool force_reset);
};

inline fast_encoder_impl::fast_encoder_impl(allocator *alloc)
    : simple_template_repo_t(alloc), strm_(alloc), active_message_id_(-1) {}

fast_encoder_impl::~fast_encoder_impl() {}

inline encoder_presence_map &fast_encoder_impl::current_pmap() {
  return *current_;
}

template <typename SimpleCRef><commit_msg>fix g++ 4.9 strict alias warning<commit_after>// Copyright (c) 2016, <NAME>,  Object Computing, Inc.
// All rights reserved.
//
// This file is part of mFAST.
// See the file license.txt for licensing information.
#include "../mfast_coder_export.h"
#include "../../field_visitor.h"
#include "../../sequence_ref.h"
#include "../../malloc_allocator.h"
#include "../fast_encoder.h"
#include "../common/template_repo.h"
#include "../common/exceptions.h"
#include "../../output.h"
#include "encoder_presence_map.h"
#include "encoder_field_operator.h"
#include "fast_ostream.h"
#include "resizable_fast_ostreambuf.h"

namespace mfast {
struct fast_encoder_impl;

struct fast_encoder_impl : simple_template_repo_t {
  fast_ostream strm_;

  int64_t active_message_id_;
  encoder_presence_map *current_;

  fast_encoder_impl(allocator *alloc);
  ~fast_encoder_impl();
  encoder_presence_map &current_pmap();

  struct pmap_state {
    encoder_presence_map pmap_;
    encoder_presence_map *prev_pmap_;

    pmap_state() : prev_pmap_(nullptr) {}
  };

  void setup_pmap(pmap_state &state, std::size_t sz) {
    state.prev_pmap_ = this->current_;
    this->current_ = &state.pmap_;
    state.pmap_.init(&this->strm_, sz);
  }

  void commit_pmap(pmap_state &state) {
    if (state.prev_pmap_) {
      state.pmap_.commit();
      this->current_ = state.prev_pmap_;
    }
  }

  void visit(enum_cref cref) {
    uint64_cref tmp;
    std::memcpy(&tmp, &cref, sizeof(cref));
    this->visit(tmp);
  }

  template <typename SimpleCRef> void visit(SimpleCRef cref);

  template <typename IntType> void visit(int_vector_cref<IntType> cref);

  void visit(group_cref cref, int);
  void visit(sequence_cref, int);
  void visit(sequence_element_cref cref, int);
  void visit(nested_message_cref, int);

  void visit(message_cref cref, bool force_reset);
};

inline fast_encoder_impl::fast_encoder_impl(allocator *alloc)
    : simple_template_repo_t(alloc), strm_(alloc), active_message_id_(-1) {}

fast_encoder_impl::~fast_encoder_impl() {}

inline encoder_presence_map &fast_encoder_impl::current_pmap() {
  return *current_;
}

template <typename SimpleCRef>
{'fraction_non_alphanumeric': 0.13245033112582782, 'fraction_numerical': 0.004730368968779565, 'mean_word_length': 4.661311914323963, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 24, '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': '3857011', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1470, 'n_words': 296}