1 //this file is part of notepad++
2 //Copyright (C)2003 Don HO <donho@altern.org>
3 //
4 //This program is free software; you can redistribute it and/or
5 //modify it under the terms of the GNU General Public License
6 //as published by the Free Software Foundation; either
7 //version 2 of the License, or (at your option) any later version.
8 //
9 //This program is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //GNU General Public License for more details.
13 //
14 //You should have received a copy of the GNU General Public License
15 //along with this program; if not, write to the Free Software
16 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 /**
18  * 
19  *
20  * Author: dokutoku, https://twitter.com/dokutoku3
21  * License: GPL-2.0 or later
22  */
23 module npp_api.pluginfunc.config_file;
24 
25 
26 version (Windows):
27 version (Not_betterC):
28 
29 private static import std.traits;
30 private static import npp_api.pluginfunc.path;
31 private static import npp_api.pluginfunc.string;
32 
33 enum setting_name_length = 64;
34 enum string_max_lengt = npp_api.pluginfunc.path.OS_MAX_PATH;
35 
36 enum config_type_t
37 {
38 	none,
39 	ini,
40 	json,
41 	registry,
42 }
43 
44 enum value_type : ubyte
45 {
46 	none = 0,
47 
48 	//basic types
49 	string_type = 1,
50 	bool_type = 2,
51 	int_type = 3,
52 	uint_type = 4,
53 	float_type = 5,
54 
55 	//other types
56 	path_type = 6,
57 }
58 
59 union value_data
60 {
61 	string string_value;
62 	wstring wstring_value;
63 	bool bool_value;
64 	int int_value;
65 	uint uint_value;
66 	float float_value;
67 }
68 
69 union value_buf
70 {
71 	char[string_max_lengt] string_value;
72 	wchar[string_max_lengt] wstring_value;
73 	bool bool_value;
74 	int int_value;
75 	uint uint_value;
76 	float float_value;
77 	wchar[npp_api.pluginfunc.path.OS_MAX_PATH] path_value;
78 }
79 
80 alias value_filter_func_t = pure nothrow @safe @nogc bool function(const ref value_buf);
81 
82 mixin template setting_item_internal(C)
83 	if (std.traits.isSomeChar!(C))
84 {
85 	private static import npp_api.pluginfunc.config_file;
86 	private static import npp_api.pluginfunc.string;
87 
88 	C[npp_api.pluginfunc.config_file.setting_name_length] name;
89 	npp_api.pluginfunc.config_file.value_type type = npp_api.pluginfunc.config_file.value_type.none;
90 	npp_api.pluginfunc.config_file.value_data value;
91 
92 	/**
93 	 * 追加のフィルター
94 	 */
95 	npp_api.pluginfunc.config_file.value_filter_func_t extra_filter = null;
96 
97 	invariant
98 	{
99 		assert((this.name[0] != '\0') && (this.name[0] != '\xFF'));
100 		assert((npp_api.pluginfunc.config_file.setting_name_length - 1) >= npp_api.pluginfunc..string.count_string(this.name));
101 	}
102 }
103 
104 struct setting_item
105 {
106 	mixin setting_item_internal!(char);
107 }
108 
109 struct plugin_config_info
110 {
111 	.config_type_t type = npp_api.pluginfunc.config_file.config_type_t.none;
112 
113 	/**
114 	 * config directory name
115 	 */
116 	string directory_name = null;
117 
118 	/**
119 	 * config file name
120 	 */
121 	string file_name = null;
122 
123 	/**
124 	 * ini config section name
125 	 */
126 	string ini_section_name = null;
127 
128 	/**
129 	 * 自動的に設定する設定名と値
130 	 */
131 	.setting_item[] settings = null;
132 }