Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ConfigFile by
ConfigFile.h
00001 /** 00002 * Configuration file interface class (Version 0.0.1) 00003 * 00004 * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) 00005 * http://shinta.main.jp/ 00006 */ 00007 #include "mbed.h" 00008 00009 #ifndef _CONFIG_FILE_H_ 00010 #define _CONFIG_FILE_H_ 00011 00012 /** 00013 * Configuration File class. 00014 */ 00015 class ConfigFile { 00016 public: 00017 00018 /** 00019 * Create a configuration file class. 00020 */ 00021 ConfigFile(); 00022 00023 /** 00024 * Destroy a configuration file class. 00025 */ 00026 ~ConfigFile(); 00027 00028 /** 00029 * Get a value for a key. 00030 * 00031 * @param key A target key name. 00032 * @param value A pointer to a value storage. 00033 * @param siz A size of a value storage. 00034 * @return A value or NULL. 00035 */ 00036 bool getValue(char *key, char *value, size_t siz); 00037 00038 /** 00039 * Set a set of a key and value. 00040 * 00041 * @param key A key. 00042 * @param value A value. 00043 * 00044 * @return True if it succeed. 00045 */ 00046 bool setValue(char *key, char *value); 00047 00048 /** 00049 * Remove a config. 00050 * 00051 * @param key A key. 00052 * 00053 * @return True if it succeed. 00054 */ 00055 bool remove(char *key); 00056 00057 /** 00058 * Remove all config. 00059 * 00060 * @return True if it succeed. 00061 */ 00062 bool removeAll(void); 00063 00064 /** 00065 * Get a number of configuration sets. 00066 * 00067 * @return number of configuration sets. 00068 */ 00069 int getCount(); 00070 00071 /** 00072 * Get a key and a value. 00073 * 00074 * @param index Index number of this list. 00075 * @param key A pointer to a buffer for key. 00076 * @param keybufsiz A size of the key buffer. 00077 * @param value A pointer to a buffer for value. 00078 * @param valuebufsiz A size of the value buffer. 00079 * 00080 * @return true if it succeed. 00081 */ 00082 bool getKeyAndValue(int index, char *key, size_t keybufsiz, char *value, size_t valuebufsiz); 00083 00084 /** 00085 * Read from the target file. 00086 * 00087 * @param file A target file name. 00088 */ 00089 bool read(char *file); 00090 00091 typedef enum { 00092 UNIX, 00093 MAC, 00094 DOS 00095 } FileFormat; 00096 00097 /** 00098 * Write from the target file. 00099 * 00100 * @param file A pointer to a file name. 00101 * @param header A pointer to a header. 00102 * @param ff File format. 00103 */ 00104 bool write(char *file, char *header = NULL, FileFormat ff = UNIX); 00105 00106 private: 00107 typedef struct { 00108 char *key; 00109 char *value; 00110 } config_t; 00111 config_t **configlist; 00112 static const int MAXCONFIG = 1024; 00113 static const int MAXLEN_KEY = 64; 00114 static const int MAXLEN_VALUE = 128; 00115 static const char SEPARATOR = '='; 00116 00117 config_t *search(char *key); 00118 bool add(config_t *cfg); 00119 }; 00120 00121 #endif
Generated on Wed Jul 13 2022 05:40:03 by
