diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-28 20:31:34 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-28 20:31:34 -0500 |
| commit | 9758b85c55b005a18d91acb4508f2c6b76dba3e2 (patch) | |
| tree | f2e1f4f4a6eb8cb53b612d2e2d7ecc2c666d8b4d | |
| parent | d7e934156858287cdb7597ad0dced97d4d279f2f (diff) | |
| download | aspartame-9758b85c55b005a18d91acb4508f2c6b76dba3e2.tar.gz aspartame-9758b85c55b005a18d91acb4508f2c6b76dba3e2.tar.bz2 aspartame-9758b85c55b005a18d91acb4508f2c6b76dba3e2.zip | |
librawr provides identifier
| -rw-r--r-- | identifier.h | 59 |
1 files changed, 0 insertions, 59 deletions
| diff --git a/identifier.h b/identifier.h deleted file mode 100644 index 74d83ce..0000000 --- a/identifier.h +++ /dev/null | |||
| @@ -1,59 +0,0 @@ | |||
| 1 | #ifndef IDENTIFIER_H_D7EE5679 | ||
| 2 | #define IDENTIFIER_H_D7EE5679 | ||
| 3 | |||
| 4 | #include <map> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | template <typename T> | ||
| 8 | class identifier { | ||
| 9 | public: | ||
| 10 | |||
| 11 | using value_type = T; | ||
| 12 | |||
| 13 | private: | ||
| 14 | |||
| 15 | using vector_type = std::vector<value_type>; | ||
| 16 | |||
| 17 | public: | ||
| 18 | |||
| 19 | using key_type = typename vector_type::size_type; | ||
| 20 | |||
| 21 | key_type add(const value_type& val) | ||
| 22 | { | ||
| 23 | auto it = ids_.find(val); | ||
| 24 | |||
| 25 | if (it == std::end(ids_)) | ||
| 26 | { | ||
| 27 | key_type ret = ids_.size(); | ||
| 28 | ids_[val] = ret; | ||
| 29 | |||
| 30 | uniq_.push_back(val); | ||
| 31 | |||
| 32 | return ret; | ||
| 33 | } else { | ||
| 34 | return it->second; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | void compile() | ||
| 39 | { | ||
| 40 | ids_.clear(); | ||
| 41 | } | ||
| 42 | |||
| 43 | inline const value_type& get(key_type i) const | ||
| 44 | { | ||
| 45 | return uniq_.at(i); | ||
| 46 | } | ||
| 47 | |||
| 48 | inline key_type size() const | ||
| 49 | { | ||
| 50 | return uniq_.size(); | ||
| 51 | } | ||
| 52 | |||
| 53 | private: | ||
| 54 | |||
| 55 | std::map<value_type, key_type> ids_; | ||
| 56 | vector_type uniq_; | ||
| 57 | }; | ||
| 58 | |||
| 59 | #endif /* end of include guard: IDENTIFIER_H_D7EE5679 */ | ||
