2023-09-08 09:42:40 +00:00
// sane_opts.h : include file for options of SANE
# pragma once
# include <string>
# include <vector>
# include <map>
# include <sane/sane_ex.h>
# 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_ ;
2023-09-23 08:07:23 +00:00
bool visible_ ;
2023-09-08 09:42:40 +00:00
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 ) ;
2023-09-23 08:07:23 +00:00
bool is_visible ( void ) ;
2023-09-08 09:42:40 +00:00
2023-09-23 08:07:23 +00:00
bool from_json_text ( const char * key , const char * json , void ( * err_msg ) ( const char * ) = nullptr ) ;
2023-09-08 09:42:40 +00:00
} ;
2023-11-01 07:12:11 +00:00
class sane_options
2023-09-08 09:42:40 +00:00
{
2023-09-23 08:07:23 +00:00
std : : map < int , sane_opt * > 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
2023-09-08 09:42:40 +00:00
SANE_Option_Descriptor opt_0_ ;
void clear ( void ) ;
2023-09-23 08:07:23 +00:00
bool add_or_replace_opt ( int & sn , const char * name , const char * jsn_text , void ( * err_msg ) ( const char * ) ) ;
2023-09-08 09:42:40 +00:00
public :
2023-11-01 07:12:11 +00:00
sane_options ( ) ;
~ sane_options ( ) ;
2023-09-08 09:42:40 +00:00
public :
bool init_from ( const char * jsn_text /*all options*/ , void ( * err_msg ) ( const char * ) ) ;
2023-09-18 03:21:14 +00:00
SANE_Option_Descriptor * get_opt_descriptor ( const void * opt , int * fix_id = nullptr , int ind_base = 0 ) ;
2023-09-08 09:42:40 +00:00
int get_option_count ( void ) ;
2023-09-23 08:07:23 +00:00
bool enum_invisible_fix_ids ( struct _fix_id_cb * fcb ) ; // return whether the callback stopped the enumeration
2023-09-08 09:42:40 +00:00
} ;