<commit_before>/*
    RawSpeed - RAW file decoder.

    Copyright (C) 2009-2014 <NAME>
    Copyright (C) 2017 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#include "common/Common.h"               // for uint32, getHostEndianness
#include "io/Buffer.h"                   // for Buffer (ptr only), DataBuffer
#include "io/ByteStream.h"               // for ByteStream
#include "io/FileMap.h"                  // for FileMap
#include "parsers/TiffParserException.h" // for ThrowTPE
#include "tiff/TiffTag.h"                // for TiffTag
#include <map>                           // for map, _Rb_tree_const_iterator
#include <memory>                        // for unique_ptr
#include <vector>                        // for vector

namespace RawSpeed {

class TiffEntry;

class TiffIFD;

class TiffRootIFD;

using TiffIFDOwner = std::unique_ptr<TiffIFD>;
using TiffRootIFDOwner = std::unique_ptr<TiffRootIFD>;
using TiffEntryOwner = std::unique_ptr<TiffEntry>;

class TiffIFD
{
  uint32 nextIFD = 0;
  TiffIFD* parent = nullptr;
  std::vector<TiffIFDOwner> subIFDs;
  std::map<TiffTag, TiffEntryOwner> entries;

  friend class TiffEntry;
  friend class RawParser;
  friend TiffRootIFDOwner parseTiff(const Buffer& data);

  // make sure we never copy-constuct/assign a TiffIFD to keep the owning subcontainers contents save
  TiffIFD(const TiffIFD&) = delete;
  TiffIFD& operator=(const TiffIFD&) = delete;

  void add(TiffIFDOwner subIFD);
  void add(TiffEntryOwner entry);
  TiffRootIFDOwner parseDngPrivateData(TiffEntry *t);
  TiffRootIFDOwner parseMakerNote(TiffEntry *t);

public:
  TiffIFD() = default;
  TiffIFD(const DataBuffer& data, uint32 offset, TiffIFD* parent);
  virtual ~TiffIFD() = default;
  uint32 getNextIFD() const {return nextIFD;}
  //TODO: make public api totally const
  std::vector<TiffIFD*> getIFDsWithTag(TiffTag tag);
  TiffEntry* getEntry(TiffTag tag) const;
  TiffEntry* getEntryRecursive(TiffTag tag) const;
  bool hasEntry(TiffTag tag) const { return entries.find(tag) != entries.end(); }
  bool hasEntryRecursive(TiffTag tag) const { return getEntryRecursive(tag) != nullptr; }

  const std::vector<TiffIFDOwner>& getSubIFDs() const { return subIFDs; }
//  const std::map<TiffTag, TiffEntry*>& getEntries() const { return entries; }
};

class TiffRootIFD : public TiffIFD
{
public:<commit_msg>TiffIFD: nolint the deleted "copy-constuct/assign a TiffIFD"<commit_after>/*
    RawSpeed - RAW file decoder.

    Copyright (C) 2009-2014 <NAME>
    Copyright (C) 2017 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#include "common/Common.h"               // for uint32, getHostEndianness
#include "io/Buffer.h"                   // for Buffer (ptr only), DataBuffer
#include "io/ByteStream.h"               // for ByteStream
#include "io/FileMap.h"                  // for FileMap
#include "parsers/TiffParserException.h" // for ThrowTPE
#include "tiff/TiffTag.h"                // for TiffTag
#include <map>                           // for map, _Rb_tree_const_iterator
#include <memory>                        // for unique_ptr
#include <vector>                        // for vector

namespace RawSpeed {

class TiffEntry;

class TiffIFD;

class TiffRootIFD;

using TiffIFDOwner = std::unique_ptr<TiffIFD>;
using TiffRootIFDOwner = std::unique_ptr<TiffRootIFD>;
using TiffEntryOwner = std::unique_ptr<TiffEntry>;

class TiffIFD
{
  uint32 nextIFD = 0;
  TiffIFD* parent = nullptr;
  std::vector<TiffIFDOwner> subIFDs;
  std::map<TiffTag, TiffEntryOwner> entries;

  friend class TiffEntry;
  friend class RawParser;
  friend TiffRootIFDOwner parseTiff(const Buffer& data);

  // make sure we never copy-constuct/assign a TiffIFD to keep the owning subcontainers contents save
  TiffIFD(const TiffIFD &) = delete;            // NOLINT
  TiffIFD &operator=(const TiffIFD &) = delete; // NOLINT

  void add(TiffIFDOwner subIFD);
  void add(TiffEntryOwner entry);
  TiffRootIFDOwner parseDngPrivateData(TiffEntry *t);
  TiffRootIFDOwner parseMakerNote(TiffEntry *t);

public:
  TiffIFD() = default;
  TiffIFD(const DataBuffer& data, uint32 offset, TiffIFD* parent);
  virtual ~TiffIFD() = default;
  uint32 getNextIFD() const {return nextIFD;}
  //TODO: make public api totally const
  std::vector<TiffIFD*> getIFDsWithTag(TiffTag tag);
  TiffEntry* getEntry(TiffTag tag) const;
  TiffEntry* getEntryRecursive(TiffTag tag) const;
  bool hasEntry(TiffTag tag) const { return entries.find(tag) != entries.end(); }
  bool hasEntryRecursive(TiffTag tag) const { return getEntryRecursive(tag) != nullptr; }

  const std::vector<TiffIFDOwner>& getSubIFDs() const { return subIFDs; }
//  const std::map<TiffTag, TiffEntry*>& getEntries() const { return entries; }
};

class TiffRootIFD : public TiffIFD
{
public:
{'fraction_non_alphanumeric': 0.08824481865284974, 'fraction_numerical': 0.010686528497409326, 'mean_word_length': 3.4696092619392185, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1759657', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1923, 'n_words': 633}