name: "Main Area" panel_display_name: "Main Area" panels { name: "INTRO" path: "Panels/General/entry_8" clue: "intro" answer: "intro" } panels { name: "BORNE" path: "Panels/General/entry_12" clue: "borne" answer: "born" symbols: ZERO } panels { name: "DEW" path: "Panels/General/dyk_1" clue: "dew" answer: "do" symbols: ZERO } panels { name: "EWE" path: "Panels/General/dyk_2" clue: "ewe" answer: "you" symbols: ZERO } panels { name: "NO" path: "Panels/General/dyk_3" clue: "no" answer: "know" symbols: ZERO } panels { name: "BROWN RED ORANGE" path: "Panels/General/seeking_1" clue: "" answer: "bro" symbols: LINGO } panels { name: "DO" path: "Panels/General/uc_1" clue: "do" answer: "do" } panels { name: "YOU" path: "Panels/General/uc_2" clue: "you" answer: "you" } panels { name: "SEE" path: "Panels/General/uc_3" clue: "see" answer: "sea" symbols: ZERO } panels { name: "SMILE" path: "Panels/General/entry_1" clue: "smile" answer: "grin" symbols: SUN } panels { name: "WHY" path: "Panels/General/red_1" clue: "why" answer: "why" } panels { name: "IS" path: "Panels/General/red_2" clue: "is" answer: "is" } panels { name: "IT" path: "Panels/General/red_3" clue: "it" answer: "it" } panels { name: "NOT" path: "Panels/General/red_4" clue: "not" answer: "not" } panels { name: "RED" path: "Panels/General/red_5" clue: "red" answer: "red" } panels { name: "COLOR" path: "Panels/General/entry_6" clue: "color" answer: "gray" symbols: EXAMPLE } panels { name: "BYE" path: "Panels/General/entry_7" clue: "bye" answer: "high" symbols: SUN symbols: ZERO } panels { name: "CURT" path: "Panels/Maze/entry_1" clue: "curt" answer: "court" symbols: SPARKLES } ports { name: "ENTRY" path: "Meshes/Blocks/Warps/worldport" orientation: "south" } ports { name: "KEEN" path: "Meshes/Blocks/Warps/worldport6" orientation: "north" } ports { name: "ORB" path: "Meshes/Blocks/Warps/worldport3" orientation: "north" } ports { name: "LINEAR" path: "Meshes/Blocks/Warps/worldport15" orientation: "south" } ports { name: "DIGITAL" path: "Meshes/Blocks/Warps/worldport4" orientation: "down" required_door { name: "Digital Entrance" } } etane/blame/tools?id=ca398f264fe853a086c05f9560f34addbb891238'>tools/sprite_dumper/identifier.h
blob: 4aac943f72ef2de65c943d5b5618a9d04d3022ff (plain) (tree)
1
2
3
4
5
6
7






                             








                                                                 






                       
                                                                                       



                                              
                                                  
 
                                    
   
                                           


                             

                                    













                           
                                               



                       
                             





                        
                                   



                                                        
#ifndef IDENTIFIER_H_D7EE5679
#define IDENTIFIER_H_D7EE5679

#include <map>
#include <vector>

template <typename T>
class DefaultKeyExtract {
public:

  const T& operator()(const T& val) const {
    return val;
  }
};

template <typename T, typename KeyExtract = DefaultKeyExtract<T>>
class identifier {
public:

  using value_type = T;

private:

  using key_type = std::remove_reference_t<std::invoke_result_t<KeyExtract, const T&>>;
  using vector_type = std::vector<value_type>;

public:

  using id_type = typename vector_type::size_type;

  id_type add(const value_type& val)
  {
    auto it = ids_.find(KeyExtract()(val));

    if (it == std::end(ids_))
    {
      id_type ret = ids_.size();
      ids_[KeyExtract()(val)] = ret;

      uniq_.push_back(val);

      return ret;
    } else {
      return it->second;
    }
  }

  void compile()
  {
    ids_.clear();
  }

  inline const value_type& get(id_type i) const
  {
    return uniq_.at(i);
  }

  inline id_type size() const
  {
    return uniq_.size();
  }

private:

  std::map<key_type, id_type> ids_;
  vector_type uniq_;
};

#endif /* end of include guard: IDENTIFIER_H_D7EE5679 */