You are viewing an older revision! See the latest version

ConfigFile

Overview

Some applications need variable configurations.

For example, The configuration of account information for Twitter...

It's not good for publish if I implemented a program with a account information for Twitter, and it's not secure.

So, in this document we will show you a configuration file helper class for local file system on mbed.

You can use a variable configuration with it.

Basic concept

  • A configuration set consist from a key and a value.

http://mbed.org/media/uploads/shintamainjp/_scaled_keyvalue.png

The simple interfaces

#include "mbed.h"
#include "ConfigFile.h"
LocalFileSystem local("local");
ConfigFile cfg;
void main(void) {
    char *key = "MyKey";
    char value[BUFSIZ];
    if (cfg.read("/local/input.cfg")) {
        if (cfg.getValue(key, &value[0], sizeof(value))) {
            printf("'%s'='%s'\n", key, value);
        }
    }
}

Library API

Import library

Public Member Functions

ConfigFile ()
Create a configuration file class.
~ConfigFile ()
Destroy a configuration file class.
bool getValue (char *key, char *value, size_t siz)
Get a value for a key.
bool setValue (char *key, char *value)
Set a set of a key and value.
bool remove (char *key)
Remove a config.
bool removeAll (void)
Remove all config.
int getCount ()
Get a number of configuration sets.
bool getKeyAndValue (int index, char *key, size_t keybufsiz, char *value, size_t valuebufsiz)
Get a key and a value.
bool read (char *file)
Read from the target file.
bool write (char *file, char *header=NULL, FileFormat ff=UNIX)
Write from the target file.

Example application

Import programConfigFile_TestProgram

A test program for ConfigFile library.

References


All wikipages