foobar2000 SDK  2015-08-03
titleformat.h
Go to the documentation of this file.
1 namespace titleformat_inputtypes {
2  extern const GUID meta, unknown;
3 };
4 
5 class NOVTABLE titleformat_text_out {
6 public:
7  virtual void write(const GUID & p_inputtype,const char * p_data,t_size p_data_length = ~0) = 0;
8  void write_int(const GUID & p_inputtype,t_int64 val);
9  void write_int_padded(const GUID & p_inputtype,t_int64 val,t_int64 maxval);
10 protected:
13 };
14 
15 
16 class NOVTABLE titleformat_text_filter {
17 public:
18  virtual void write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length) = 0;
19 protected:
22 };
23 
25 {
26 public:
27  virtual t_size get_param_count() = 0;
28  virtual void get_param(t_size index,const char * & p_string,t_size & p_string_len) = 0;//warning: not a null-terminated string
29 
30  //helper
31  t_size get_param_uint(t_size index);
32 };
33 
34 class NOVTABLE titleformat_hook
35 {
36 public:
37  virtual bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) = 0;
38  virtual bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) = 0;
39 };
41 class NOVTABLE titleformat_object : public service_base
42 {
43 public:
44  virtual void run(titleformat_hook * p_source,pfc::string_base & p_out,titleformat_text_filter * p_filter)=0;
45 
46  void run_hook(const playable_location & p_location,const file_info * p_source,titleformat_hook * p_hook,pfc::string_base & p_out,titleformat_text_filter * p_filter);
47  void run_simple(const playable_location & p_location,const file_info * p_source,pfc::string_base & p_out);
48 
49  FB2K_MAKE_SERVICE_INTERFACE(titleformat_object,service_base);
50 };
51 
54 class NOVTABLE titleformat_compiler : public service_base
55 {
56 public:
58  virtual bool compile(titleformat_object::ptr & p_out,const char * p_spec) = 0;
60  void run(titleformat_hook * p_source,pfc::string_base & p_out,const char * p_spec);
62  void compile_safe(titleformat_object::ptr & p_out,const char * p_spec);
63 
65  void compile_safe_ex(titleformat_object::ptr & p_out,const char * p_spec,const char * p_fallback = "<ERROR>");
66 
68  void compile_force(titleformat_object::ptr & p_out,const char * p_spec) {if (!compile(p_out,p_spec)) uBugCheck();}
69 
70 
71  static void remove_color_marks(const char * src,pfc::string_base & out);//helper
72  static void remove_forbidden_chars(titleformat_text_out * p_out,const GUID & p_inputtype,const char * p_source,t_size p_source_len,const char * p_forbidden_chars);
73  static void remove_forbidden_chars_string_append(pfc::string_receiver & p_out,const char * p_source,t_size p_source_len,const char * p_forbidden_chars);
74  static void remove_forbidden_chars_string(pfc::string_base & p_out,const char * p_source,t_size p_source_len,const char * p_forbidden_chars);
75 
76  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(titleformat_compiler);
77 };
78 
79 
81 public:
82  titleformat_object_wrapper(const char * p_script) {
83  static_api_ptr_t<titleformat_compiler>()->compile_force(m_script,p_script);
84  }
85 
86  operator const service_ptr_t<titleformat_object> &() const {return m_script;}
87 
88 private:
90 };
91 
92 
93 //helpers
94 
95 
97 {
98 public:
99  inline titleformat_text_out_impl_filter_chars(titleformat_text_out * p_chain,const char * p_restricted_chars)
100  : m_chain(p_chain), m_restricted_chars(p_restricted_chars) {}
101  void write(const GUID & p_inputtype,const char * p_data,t_size p_data_length);
102 private:
104  const char * m_restricted_chars;
105 };
106 
108 public:
109  titleformat_text_out_impl_string(pfc::string_receiver & p_string) : m_string(p_string) {}
110  void write(const GUID & p_inputtype,const char * p_data,t_size p_data_length) {m_string.add_string(p_data,p_data_length);}
111 private:
113 };
114 
116 public:
117  virtual bool process_field(const file_info & p_info,const playable_location & p_location,titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) = 0;
118  virtual bool process_function(const file_info & p_info,const playable_location & p_location,titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) = 0;
119  virtual bool remap_meta(const file_info & p_info,t_size & p_index, const char * p_name, t_size p_name_length) = 0;
120 
121  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(titleformat_common_methods);
122 };
123 
125 {
126 public:
127  titleformat_hook_impl_file_info(const playable_location & p_location,const file_info * p_info) : m_location(p_location), m_info(p_info) {}//caller must ensure that referenced file_info object is alive as long as the titleformat_hook_impl_file_info instance
128  bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag);
129  bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag);
130 protected:
131  bool remap_meta(t_size & p_index, const char * p_name, t_size p_name_length) {return m_api->remap_meta(*m_info,p_index,p_name,p_name_length);}
132  const file_info * m_info;
133 private:
136 };
137 
139 public:
140  inline titleformat_hook_impl_splitter(titleformat_hook * p_hook1,titleformat_hook * p_hook2) : m_hook1(p_hook1), m_hook2(p_hook2) {}
141  bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag);
142  bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag);
143 private:
144  titleformat_hook * m_hook1, * m_hook2;
145 };
146 
148 public:
149  titleformat_text_filter_impl_reserved_chars(const char * p_reserved_chars) : m_reserved_chars(p_reserved_chars) {}
150  virtual void write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length);
151 private:
152  const char * m_reserved_chars;
153 };
154 
156 public:
157  void write(const GUID & p_inputType,pfc::string_receiver & p_out,const char * p_data,t_size p_dataLength);
158 };
159 
161 public:
162  inline static bool isReserved(char c) { return c >= 0 && c < 0x20; }
163  void write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length);
164 };
165 
166 
167 
168 
169 
170 
171 
173 public:
174  titleformat_hook_impl_list(t_size p_index /* zero-based! */,t_size p_total) : m_index(p_index), m_total(p_total) {}
175 
176  bool process_field(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) {
177  if (
178  pfc::stricmp_ascii_ex(p_name,p_name_length,"list_index",~0) == 0
179  ) {
180  p_out->write_int_padded(titleformat_inputtypes::unknown,m_index+1, m_total);
181  p_found_flag = true; return true;
182  } else if (
183  pfc::stricmp_ascii_ex(p_name,p_name_length,"list_total",~0) == 0
184  ) {
186  p_found_flag = true; return true;
187  } else {
188  p_found_flag = false; return false;
189  }
190  }
191 
192  bool process_function(titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) {return false;}
193 
194 private:
195  t_size m_index, m_total;
196 };
197 
199 public:
200  string_formatter_tf(titleformat_text_out * out, const GUID & inputType = titleformat_inputtypes::meta) : m_out(out), m_inputType(inputType) {}
201 
202  const char * get_ptr() const {
203  uBugCheck();
204  }
205  void add_string(const char * p_string,t_size p_length) {
206  m_out->write(m_inputType,p_string,p_length);
207  }
208  void set_string(const char * p_string,t_size p_length) {
209  uBugCheck();
210  }
211  void truncate(t_size len) {
212  uBugCheck();
213  }
214  t_size get_length() const {
215  uBugCheck();
216  }
217  char * lock_buffer(t_size p_requested_length) {
218  uBugCheck();
219  }
220  void unlock_buffer() {
221  uBugCheck();
222  }
223 
224 private:
227 };
const GUID m_inputType
Definition: titleformat.h:226
static_api_ptr_t< titleformat_common_methods > m_api
Definition: titleformat.h:135
Definition: pfc.h:71
Standard service for instantiating titleformat_object. Implemented by the core; do not reimplement...
Definition: titleformat.h:54
t_size get_length() const
Definition: titleformat.h:214
void write_int_padded(const GUID &p_inputtype, t_int64 val, t_int64 maxval)
titleformat_hook_impl_list(t_size p_index, t_size p_total)
Definition: titleformat.h:174
titleformat_hook * m_hook2
Definition: titleformat.h:144
int stricmp_ascii_ex(const char *const s1, t_size const len1, const char *const s2, t_size const len2)
titleformat_text_out_impl_filter_chars(titleformat_text_out *p_chain, const char *p_restricted_chars)
Definition: titleformat.h:99
string_formatter_tf(titleformat_text_out *out, const GUID &inputType=titleformat_inputtypes::meta)
Definition: titleformat.h:200
Main interface class for information about some playable object.
Definition: file_info.h:73
void write(const GUID &p_inputtype, const char *p_data, t_size p_data_length)
Definition: titleformat.h:110
titleformat_text_filter_impl_reserved_chars(const char *p_reserved_chars)
Definition: titleformat.h:149
bool process_function(titleformat_text_out *p_out, const char *p_name, t_size p_name_length, titleformat_hook_function_params *p_params, bool &p_found_flag)
Definition: titleformat.h:192
titleformat_hook_impl_file_info(const playable_location &p_location, const file_info *p_info)
Definition: titleformat.h:127
size_t t_size
Definition: int_types.h:48
void set_string(const char *p_string, t_size p_length)
Definition: titleformat.h:208
const char * get_ptr() const
Definition: titleformat.h:202
This is free and unencumbered software released into the public domain Anyone is free to compile
Definition: pfc-license.txt:3
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
void write(const service_ptr_t< file > &p_file, abort_callback &p_abort, const char *p_string, bool is_utf8)
pfc::string_receiver & m_string
Definition: titleformat.h:112
bool remap_meta(t_size &p_index, const char *p_name, t_size p_name_length)
Definition: titleformat.h:131
titleformat_object_wrapper(const char *p_script)
Definition: titleformat.h:82
titleformat_text_out_impl_string(pfc::string_receiver &p_string)
Definition: titleformat.h:109
bool process_field(titleformat_text_out *p_out, const char *p_name, t_size p_name_length, bool &p_found_flag)
Definition: titleformat.h:176
titleformat_text_out *const m_out
Definition: titleformat.h:225
titleformat_hook_impl_splitter(titleformat_hook *p_hook1, titleformat_hook *p_hook2)
Definition: titleformat.h:140
const playable_location & m_location
Definition: titleformat.h:134
void write_int(const GUID &p_inputtype, t_int64 val)
void add_string(const char *p_string, t_size p_length)
Definition: titleformat.h:205
void compile_force(titleformat_object::ptr &p_out, const char *p_spec)
Throws a bug check exception when script can&#39;t be compiled. For use with hardcoded scripts only...
Definition: titleformat.h:68
void truncate(t_size len)
Definition: titleformat.h:211
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
service_ptr_t< titleformat_object > m_script
Definition: titleformat.h:89
PFC_NORETURN void SHARED_EXPORT uBugCheck()
Represents precompiled executable title-formatting script. Use titleformat_compiler to instantiate; d...
Definition: titleformat.h:41
int64_t t_int64
Definition: int_types.h:2
char * lock_buffer(t_size p_requested_length)
Definition: titleformat.h:217