@@ -59,7 +59,7 @@ class RomDB : public DB {
5959 QUERY_FILE,
6060 QUERY_GAME_ID,
6161 QUERY_GAME,
62- QUERY_HAS_DISKS ,
62+ QUERY_HAS_FILE_TYPE ,
6363 QUERY_HASH_TYPE_CRC,
6464 QUERY_HASH_TYPE_MD5,
6565 QUERY_HASH_TYPE_SHA1,
@@ -80,6 +80,36 @@ class RomDB : public DB {
8080 enum ParameterizedStatement {
8181 QUERY_FILE_FBH
8282 };
83+
84+ class FileTypeIterator {
85+ public:
86+ using iterator_category = std::forward_iterator_tag;
87+ using value_type = filetype_t ;
88+
89+ FileTypeIterator (const bool * types, int file_type);
90+
91+ FileTypeIterator& operator ++();
92+ FileTypeIterator operator ++(int ) {auto next=*this ; ++*this ; return next;}
93+ filetype_t operator *() const {return static_cast <filetype_t >(file_type);}
94+ bool operator ==(const FileTypeIterator& other) const {return file_type == other.file_type ;}
95+ bool operator !=(const FileTypeIterator& other) const {return file_type != other.file_type ;}
96+
97+ private:
98+ void skip_missing ();
99+ const bool * types;
100+ int file_type;
101+ };
102+
103+ class FileTypes {
104+ public:
105+ FileTypes (const RomDB& db): types{db.has_types } {}
106+
107+ FileTypeIterator begin () {return {types, 0 };}
108+ FileTypeIterator end () {return {types, TYPE_MAX};}
109+
110+ private:
111+ const bool *types;
112+ };
83113
84114 RomDB (const std::string &name, int mode);
85115 ~RomDB () override = default ;
@@ -96,7 +126,8 @@ class RomDB : public DB {
96126 std::vector<std::string> get_clones (const std::string &game_name);
97127 void delete_game (const Game *game) { delete_game (game->name ); }
98128 void delete_game (const std::string &name);
99- bool has_disks ();
129+ bool has_type (filetype_t type) const {return has_types[type];}
130+ bool has_disks () const {return has_type (TYPE_DISK);}
100131
101132 bool has_detector () const { return !detectors.empty (); }
102133 DetectorPtr get_detector (size_t id);
@@ -107,6 +138,7 @@ class RomDB : public DB {
107138 std::vector<RomLocation> read_file_by_hash (filetype_t ft, const Hashes &hashes);
108139 GamePtr read_game (const std::string &name);
109140 int hashtypes (filetype_t );
141+ FileTypes filetypes ();
110142 std::vector<std::string> read_list (enum dbh_list type);
111143 void update_file_location (Game *game);
112144 void update_game_parent (const Game *game);
@@ -115,13 +147,15 @@ class RomDB : public DB {
115147 void write_game (Game *game);
116148 void write_hashtypes (int , int );
117149 int export_db (const std::unordered_set<std::string> &exclude, const DatEntry *dat, OutputContext *out);
118-
150+
151+ bool has_types[TYPE_MAX];
152+
119153protected:
120154 std::string get_query (int name, bool parameterized) const override ;
121155
122156private:
123157 int hashtypes_[TYPE_MAX];
124-
158+
125159 static const std::string init2_sql;
126160 static const Statement query_hash_type[];
127161 static std::unordered_map<int , std::string> queries;
@@ -130,6 +164,7 @@ class RomDB : public DB {
130164 DBStatement *get_statement (Statement name) { return get_statement_internal (name); }
131165 DBStatement *get_statement (ParameterizedStatement name, const Hashes &hashes, bool have_size) { return get_statement_internal (name, hashes, have_size); }
132166
167+ bool get_has_type (int type);
133168 DetectorPtr read_detector ();
134169 void read_files (Game *game, filetype_t ft);
135170 void read_hashtypes (filetype_t type);
0 commit comments