131 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C
		
	
	
	
		
		
			
		
	
	
			131 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C
		
	
	
	
| 
								 | 
							
								// Copyright (c) 2016-2018 Easy2D - Nomango
							 | 
						|||
| 
								 | 
							
								// 
							 | 
						|||
| 
								 | 
							
								// Permission is hereby granted, free of charge, to any person obtaining a copy
							 | 
						|||
| 
								 | 
							
								// of this software and associated documentation files (the "Software"), to deal
							 | 
						|||
| 
								 | 
							
								// in the Software without restriction, including without limitation the rights
							 | 
						|||
| 
								 | 
							
								// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
							 | 
						|||
| 
								 | 
							
								// copies of the Software, and to permit persons to whom the Software is
							 | 
						|||
| 
								 | 
							
								// furnished to do so, subject to the following conditions:
							 | 
						|||
| 
								 | 
							
								// 
							 | 
						|||
| 
								 | 
							
								// The above copyright notice and this permission notice shall be included in
							 | 
						|||
| 
								 | 
							
								// all copies or substantial portions of the Software.
							 | 
						|||
| 
								 | 
							
								// 
							 | 
						|||
| 
								 | 
							
								// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
							 | 
						|||
| 
								 | 
							
								// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
							 | 
						|||
| 
								 | 
							
								// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
							 | 
						|||
| 
								 | 
							
								// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
							 | 
						|||
| 
								 | 
							
								// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
							 | 
						|||
| 
								 | 
							
								// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
							 | 
						|||
| 
								 | 
							
								// THE SOFTWARE.
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								#pragma once
							 | 
						|||
| 
								 | 
							
								#include "../macros.h"
							 | 
						|||
| 
								 | 
							
								#include "../common/helper.h"
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace easy2d
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
									//
							 | 
						|||
| 
								 | 
							
									// <20><><EFBFBD>ݴ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> (.ini <20><>ʽ)
							 | 
						|||
| 
								 | 
							
									// һ<><D2BB> DataUtil <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾһ<CABE><D2BB><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>ʵ<EFBFBD><CAB5>, <20><><EFBFBD>ڴ<EFBFBD>ȡ<EFBFBD><EFBFBD>ʽ (bool | int | float | double | String) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
							 | 
						|||
| 
								 | 
							
									// <20><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD><EFBFBD><EFBFBD> key-value (<28><>-ֵ) <20>ķ<EFBFBD>ʽ<EFBFBD><CABD>ȡ
							 | 
						|||
| 
								 | 
							
									// <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>߷<EFBFBD>, <20>Ա<EFBFBD><D4B1>´ν<C2B4><CEBD><EFBFBD><EFBFBD><EFBFBD>Ϸʱ<CFB7><CAB1>ȡ:
							 | 
						|||
| 
								 | 
							
									// DataUtil data;                          // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
							 | 
						|||
| 
								 | 
							
									// data.SaveInt(L"best score", 20);        // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD> 20
							 | 
						|||
| 
								 | 
							
									// int best = data.GetInt(L"best score");  // <20><>ȡ֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD>
							 | 
						|||
| 
								 | 
							
									//
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
									class E2D_API DataUtil
							 | 
						|||
| 
								 | 
							
									{
							 | 
						|||
| 
								 | 
							
									public:
							 | 
						|||
| 
								 | 
							
										DataUtil(
							 | 
						|||
| 
								 | 
							
											String const& file_path = L"./data.ini",	// <20>ļ<EFBFBD>·<EFBFBD><C2B7>
							 | 
						|||
| 
								 | 
							
											String const& field = L"defalut"			// <20>ֶ<EFBFBD><D6B6><EFBFBD>
							 | 
						|||
| 
								 | 
							
										);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>·<EFBFBD><C2B7>
							 | 
						|||
| 
								 | 
							
										inline String const& GetFilePath() const { return file_path_; }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>·<EFBFBD><C2B7>
							 | 
						|||
| 
								 | 
							
										void SetFilePath(
							 | 
						|||
| 
								 | 
							
											String const& file_path
							 | 
						|||
| 
								 | 
							
										);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><>ȡ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
							 | 
						|||
| 
								 | 
							
										inline String const& GetFieldName() const { return field_name_; }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
							 | 
						|||
| 
								 | 
							
										void SetFieldName(
							 | 
						|||
| 
								 | 
							
											String const& field
							 | 
						|||
| 
								 | 
							
										);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
							 | 
						|||
| 
								 | 
							
										bool Exists(
							 | 
						|||
| 
								 | 
							
											String const& key
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><><EFBFBD><EFBFBD> int <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										bool SaveInt(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											int val
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><><EFBFBD><EFBFBD> float <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										bool SaveFloat(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											float val
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><><EFBFBD><EFBFBD> double <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										bool SaveDouble(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											double val
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><><EFBFBD><EFBFBD> bool <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										bool SaveBool(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											bool val
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><><EFBFBD><EFBFBD> String <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										bool SaveString(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											String const& val
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><>ȡ int <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										int GetInt(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											int default_value = 0
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><>ȡ float <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										float GetFloat(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											float default_value = 0.0f
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><>ȡ double <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										double GetDouble(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											double default_value = 0.0
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><>ȡ bool <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										bool GetBool(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											bool default_value = false
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
										// <20><>ȡ <20>ַ<EFBFBD><D6B7><EFBFBD> <20><><EFBFBD>͵<EFBFBD>ֵ
							 | 
						|||
| 
								 | 
							
										String GetString(
							 | 
						|||
| 
								 | 
							
											String const& key,
							 | 
						|||
| 
								 | 
							
											String const& default_value = L""
							 | 
						|||
| 
								 | 
							
										) const;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
									protected:
							 | 
						|||
| 
								 | 
							
										String file_path_;
							 | 
						|||
| 
								 | 
							
										String field_name_;
							 | 
						|||
| 
								 | 
							
									};
							 | 
						|||
| 
								 | 
							
								}
							 |