// sane_opts.h : include file for options of SANE #pragma once #include #include #include #include #define FIXED_ID_BASE 0x8000 class gb_json; // For: option json to SANE_Option_Descriptor*, and depends logic // // NOTE: re-call method 'from_json_text' if language was changed class sane_opt { int fix_id_; bool enabled_; bool visible_; SANE_Option_Descriptor opt_desc_; void clear(); void set_opt_desc_string_value(char** buf, const char* val); void init_cap(gb_json* jsn); void init_range(gb_json* jsn); public: sane_opt(); ~sane_opt(); public: int get_fix_id(void); SANE_Option_Descriptor* get_descriptor(void); const char* name(void); bool is_enabled(void); bool is_visible(void); bool from_json_text(const char* key, const char* json, void(*err_msg)(const char*) = nullptr); }; class device_opts { std::map opts_; // SANE_Int && fix-id point the same object. SANE_Int is visible and accessible, only accessible by fix-id if without SANE_Int int opt_cnt_; // count for visible options SANE_Option_Descriptor opt_0_; void clear(void); bool add_or_replace_opt(int& sn, const char* name, const char* jsn_text, void(*err_msg)(const char*)); public: device_opts(); ~device_opts(); public: bool init_from(const char* jsn_text/*all options*/, void(*err_msg)(const char*)); SANE_Option_Descriptor* get_opt_descriptor(const void* opt, int* fix_id = nullptr, int ind_base = 0); int get_option_count(void); bool enum_invisible_fix_ids(struct _fix_id_cb* fcb); // return whether the callback stopped the enumeration };