メインページ | ネームスペース一覧 | クラス階層 | 構成 | Directories | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ

クラス RTC::Properties

#include <Properties.h>

すべてのメンバ一覧

Public メソッド

 Properties (const char *key="", const char *value="")
 コンストラクタ
 Properties (std::map< std::string, std::string > &defaults)
 コンストラクタ
 Properties (const char *defaults[], long num=LONG_MAX)
 コンストラクタ
 Properties (const Properties &prop)
 コピーコンストラクタ
Propertiesoperator= (const Properties &prop)
 代入演算子.
virtual ~Properties ()
 デストラクタ
const char * getName () const
const char * getVlue () const
const char * getDefaultValue () const
const std::vector< Properties * > & getLeaf () const
const PropertiesgetRoot () const
const std::string & getProperty (const std::string &key) const
 指定されたキーを持つプロパティを、プロパティリストから探す
const std::string & getProperty (const std::string &key, const std::string &def) const
 指定されたキーを持つプロパティを、プロパティリストから探す。
const std::string & operator[] (const std::string &key) const
 指定されたキーを持つプロパティを、プロパティリストから探す。
std::string & operator[] (const std::string &key)
 指定されたキーを持つプロパティを、プロパティリストから探す。
const std::string & getDefault (const std::string &key) const
 指定されたキーに対してデフォルト値を設定する
std::string setProperty (const std::string &key, const std::string &value)
 Properties に value を key について登録する.
std::string setDefault (const std::string &key, const std::string &value)
 Properties にデフォルト value を key について登録する.
void setDefaults (const char *defaults[], long num=LONG_MAX)
 Properties にデフォルト値をまとめて登録する.
void list (std::ostream &out)
 指定された出力ストリームに、プロパティリストを出力する
void load (std::istream &inStream)
 入力ストリームからキーと要素が対になったプロパティリストを読み込む.
void save (std::ostream &out, const std::string &header)
 プロパティリストを指定されたストリームに保存する
void store (std::ostream &out, const std::string &header)
 プロパティリストを出力ストリームへ保存する
std::vector< std::string > propertyNames () const
 プロパティのキーのリストを vector で返す
int size () const
 プロパティの数を取得する
PropertiesgetNode (const std::string &key) const
 ノードを取得する
bool createNode (const char *key)
PropertiesremoveNode (const char *leaf_name)
 ノードを切断する
PropertieshasKey (const char *key) const
 子ノードにkeyがあるかどうか
void clear ()
 子ノードを全て削除する
Propertiesoperator<< (const Properties &prop)
 Propertyをマージする.

Static Protected メソッド

static void splitKeyValue (const std::string &str, std::string &key, std::string &value)
static bool split (const std::string &str, const char delim, std::vector< std::string > &value)
static Properties_getNode (std::vector< std::string > &keys, std::vector< Properties * >::size_type index, const Properties *curr)
static void _propertiyNames (std::vector< std::string > &names, std::string curr_name, const Properties *curr)
static void _store (std::ostream &out, std::string curr_name, Properties *curr)
static std::ostream & _dump (std::ostream &out, const Properties &curr, int index)
static std::string indent (int index)

フレンド

std::ostream & operator<< (std::ostream &lhs, const Properties &rhs)


説明

Properties クラスは、不変のプロパティセットを表す。Properties をストリーム に保管したり、ストリームからロードしたりすることができる。 プロパティリストの各キー、およびそれに対応する値は文字列となっている。

プロパティリストには、その「デフォルト値」として別のプロパティリストを持つ ことができる。元のプロパティリストでプロパティキーが見つからないと、この 2番目のプロパティリストが検索される。

プロパティの取得には getProperty、プロパティのセットには setProperty と いったメソッドを使用することが推奨される。

プロパティをストリームに保存するとき、またはストリームからロードするときに、 ISO 8859-1 文字エンコーディングが使用される。このエンコーディングに直接表示 できない文字は、扱うことができない。

このクラスは、Java の Properties クラス (java.util.Properties) とほぼ同様の メソッドを持つ。また、入出力されるファイルは Java の Properties クラスが 出力するものと互換性があるが、Unicode を含むものは扱うことができない。


コンストラクタとデストラクタ

RTC::Properties::Properties const char *  key = "",
const char *  value = ""
 

コンストラクタ

key と value のみを与えて Property のルートノードを作成する。 値は全てデフォルト値として設定される。

RTC::Properties::Properties std::map< std::string, std::string > &  defaults  ) 
 

コンストラクタ

std::string の std::map をデフォルト値にもつPropertiesを作成する。 値は全てデフォルト値として設定される。

RTC::Properties::Properties const char *  defaults[],
long  num = LONG_MAX
 

コンストラクタ

指定されたデフォルト値を持つ空のプロパティリストを作成する。 値は全てデフォルト値として設定される。 デフォルト値は char* の配列により与えられ、key と value の対になっており、 リストの終端は配列の数を表す引数 num か、空文字の key で与えらられなければ ならない。 以下に例を示す。

const char* defaults = { "key1", "value1", "key2", "value2", "key3", "value3", "key4", "value4", "key5", "value5", "" }; Properties p(defaults); // もしくは Properties p(defaults, 10);

RTC::Properties::Properties const Properties prop  ) 
 

コピーコンストラクタ

引数に与えられた Properties のキー、値およびデフォルト値が 全てそのままコピーされる。

virtual RTC::Properties::~Properties  )  [virtual]
 

デストラクタ


関数

static std::ostream& RTC::Properties::_dump std::ostream &  out,
const Properties curr,
int  index
[static, protected]
 

static Properties* RTC::Properties::_getNode std::vector< std::string > &  keys,
std::vector< Properties * >::size_type  index,
const Properties curr
[static, protected]
 

static void RTC::Properties::_propertiyNames std::vector< std::string > &  names,
std::string  curr_name,
const Properties curr
[static, protected]
 

static void RTC::Properties::_store std::ostream &  out,
std::string  curr_name,
Properties curr
[static, protected]
 

void RTC::Properties::clear  ) 
 

子ノードを全て削除する

bool RTC::Properties::createNode const char *  key  )  [inline]
 

const std::string& RTC::Properties::getDefault const std::string &  key  )  const
 

指定されたキーに対してデフォルト値を設定する

const char* RTC::Properties::getDefaultValue  )  const [inline]
 

const std::vector<Properties*>& RTC::Properties::getLeaf  )  const [inline]
 

const char* RTC::Properties::getName  )  const [inline]
 

Properties* RTC::Properties::getNode const std::string &  key  )  const
 

ノードを取得する

const std::string& RTC::Properties::getProperty const std::string &  key,
const std::string &  def
const
 

指定されたキーを持つプロパティを、プロパティリストから探す。

指定されたキーを持つプロパティを、プロパティリストから探す。 そのキーがプロパティリストにないと、デフォルトのプロパティリスト、 さらにそのデフォルト値が繰り返し調べられる。 そのプロパティが見つからない場合は、デフォルト値の引数が返される。

引数:
key プロパティキー
defaultValue デフォルト値
戻り値:
指定されたキー値を持つこのプロパティリストの値

const std::string& RTC::Properties::getProperty const std::string &  key  )  const
 

指定されたキーを持つプロパティを、プロパティリストから探す

指定されたキーを持つプロパティを、プロパティリストから探す。 そのキーがプロパティリストにないと、デフォルトのプロパティリスト、 さらにそのデフォルト値が繰り返し調べられる。 そのプロパティが見つからない場合は、null が返される。

引数:
key プロパティキー
戻り値:
指定されたキー値を持つこのプロパティリストの値

const Properties* RTC::Properties::getRoot  )  const [inline]
 

const char* RTC::Properties::getVlue  )  const [inline]
 

Properties* RTC::Properties::hasKey const char *  key  )  const
 

子ノードにkeyがあるかどうか

static std::string RTC::Properties::indent int  index  )  [static, protected]
 

void RTC::Properties::list std::ostream &  out  ) 
 

指定された出力ストリームに、プロパティリストを出力する

指定された出力ストリームに、プロパティリストを出力する。 このメソッドは主にデバッグに用いられる。

引数:
out 出力ストリーム

void RTC::Properties::load std::istream &  inStream  ) 
 

入力ストリームからキーと要素が対になったプロパティリストを読み込む.

入力ストリームからキーと要素が対になったプロパティリストを読み込む。 ストリームは、ISO 8859-1 文字エンコーディングを使用しているとみなされる。 各プロパティは、入力ストリームに行単位で登録されているものとみなされ、 各行は行区切り文字 (
、、または
) で終わる。 入力ストリームから読み込んだ行は、入力ストリームでファイルの終わりに 達するまで処理される。

空白文字だけの行、または最初の非空白文字が ASCII 文字 # または ! である 行は無視される。つまり、# または ! はコメント行を示す。

空白行またはコメント行以外のすべての行は、テーブルに追加されるプロパティ を記述する。ただし、行の終わりが \ の場合は、次の行があれば継続行として 扱われます (下記を参照)。 キーは、最初の非空白文字から、最初の ASCII 文字 =、:、または空白文字の直前までの、行内のすべての文字から構成される。

キーの終わりを示す文字は、前に \ を付けることによりキーに含めることも できる。キーの後ろの空白はすべてスキップされる。 キーの後ろの最初の非空白文字が = または : である場合は、これらのキーは 無視され、そのあとの空白文字もすべてスキップされる。 行内のそれ以外の文字はすべて、関連した要素文字列の一部となる。 要素文字列内では、ASCII エスケープシーケンス 、
、、\、\"、\'、 \ (円記号とスペース)、および は認識され、単独の文字に変換される。 また、行の最後の文字が \ である場合は、次の行は現在の行の継続として 扱われる。その場合、\ と行区切り文字が破棄され、継続行の先頭に空白が あればそれもすべて破棄され、要素文字列の一部にはならない。

たとえば、次の 4 行はそれぞれキー Truth と、関連した要素値 Beauty を表す。

Truth = Beauty
Truth:Beauty
Truth :Beauty

また、次の 3 行は 1 つのプロパティを表す。

fruits apple, banana, pear, \
cantaloupe, watermelon, \
kiwi, mango
キーは fruits で、次の要素に関連付けれられる。 "apple, banana, pear, cantaloupe, watermelon, kiwi, mango" 最終的な結果でコンマのあとに必ずスペースが表示されるように、 各 \ の前にスペースがある。行の終わりを示す \ と、継続行の先頭にある 空白は破棄され、他の文字に置換されない。 また、次の 3 番目の例では、キーが cheeses で、関連した要素が空の文字列 であることを表す。

cheeses
キーは、cheeses で、関連要素は空の文字列であることを指定している。

引数:
inStream 入力ストリーム

Properties& RTC::Properties::operator<< const Properties prop  ) 
 

Propertyをマージする.

Properties& RTC::Properties::operator= const Properties prop  ) 
 

代入演算子.

左辺値の Properties のキー、値およびデフォルト値は全て削除され、 右辺値の Properties のキー、値およびデフォルト値が全てそのまま コピーされる。

std::string& RTC::Properties::operator[] const std::string &  key  ) 
 

指定されたキーを持つプロパティを、プロパティリストから探す。

指定されたキーを持つプロパティを返す。 そのキーの値がプロパティリストになければデフォルト値を返す。 さらに見つからなければ、空文字を返す。 左辺値になる場合に、同じ値を持つ要素がないときは与えられたキー に対応するプロパティに右辺値を挿入。

引数:
key プロパティキー
戻り値:
指定されたキー値を持つこのプロパティリストの値

const std::string& RTC::Properties::operator[] const std::string &  key  )  const
 

指定されたキーを持つプロパティを、プロパティリストから探す。

指定されたキーを持つプロパティを返す。 そのキーがプロパティリストになければデフォルト値を返す。 さらに見つからなければ、空文字を返す。

引数:
key プロパティキー
戻り値:
指定されたキー値を持つこのプロパティリストの値

std::vector<std::string> RTC::Properties::propertyNames  )  const
 

プロパティのキーのリストを vector で返す

メインプロパティリストに同じ名前のキーが見つからない場合は、デフォルトの プロパティリストにある個別のキーを含む、このプロパティリストにあるすべて のキーのリストを返します。

戻り値:
プロパティリストにあるすべてのキーのリスト。 デフォルトのプロパティリストにあるキーを含む

Properties* RTC::Properties::removeNode const char *  leaf_name  ) 
 

ノードを切断する

void RTC::Properties::save std::ostream &  out,
const std::string &  header
 

プロパティリストを指定されたストリームに保存する

推奨されていません。プロパティリストの保存方法としては、 store(ostream out, string header) メソッドの使用が推奨される。 このメソッドは Java Properties との互換性のために定義されている。

引数:
out 出力ストリーム
header プロパティリストの記述

std::string RTC::Properties::setDefault const std::string &  key,
const std::string &  value
 

Properties にデフォルト value を key について登録する.

void RTC::Properties::setDefaults const char *  defaults[],
long  num = LONG_MAX
 

Properties にデフォルト値をまとめて登録する.

std::string RTC::Properties::setProperty const std::string &  key,
const std::string &  value
 

Properties に value を key について登録する.

Properties に value を key について登録する。 すでに key に対する値を持っている場合、戻り値に古い値を返す。

引数:
key プロパティリストに配置されるキー
value key に対応する値
戻り値:
プロパティリストの指定されたキーの前の値。それがない場合は null

int RTC::Properties::size  )  const
 

プロパティの数を取得する

static bool RTC::Properties::split const std::string &  str,
const char  delim,
std::vector< std::string > &  value
[static, protected]
 

static void RTC::Properties::splitKeyValue const std::string &  str,
std::string &  key,
std::string &  value
[static, protected]
 

void RTC::Properties::store std::ostream &  out,
const std::string &  header
 

プロパティリストを出力ストリームへ保存する

Properties テーブル内のプロパティリスト (キーと要素のペア) を、load メソッドを使って Properties テーブルにロードするのに適切なフォーマットで 出力ストリームに書き込みます。

Properties テーブル内のプロパティリスト (キーと要素のペア) を、load メソッドを使って Properties テーブルにロードするのに適切なフォーマットで 出力ストリームに書き込みます。ストリームは、ISO 8859-1 文字 エンコーディングを使用して書き込まれます。 Properties テーブル (存在する場合) のデフォルトテーブルからの プロパティは、このメソッドによっては書き込まれません。

header 引数が null でない場合は、ASCII 文字の #、header の文字列、 および行区切り文字が最初に出力ストリームに書き込まれます。このため、 header は識別コメントとして使うことができます。

次に、ASCII 文字の #、現在の日時 (Date の toString メソッドによって 現在時刻が生成されるのと同様)、および Writer によって生成される行区切り からなるコメント行が書き込まれます。

続いて、Properties テーブル内のすべてのエントリが 1 行ずつ書き出されます。 各エントリのキー文字列、ASCII 文字の =、関連した要素文字列が書き込まれま す。要素文字列の各文字は、エスケープシーケンスとして描画する必要があるか どうか確認されます。ASCII 文字の \、タブ、改行、および復帰はそれぞれ \、 、
、および として書き込まれます。 より小さい文字および より大きい文字は、対応する 16 進値 xxxx を使って として書き 込まれます。埋め込み空白文字でも後書き空白文字でもない先行空白文字は、 前に \ を付けて書き込まれます。キーと値の文字 #、!、=、および : は、 必ず正しくロードされるように、前にスラッシュを付けて書き込まれます。

エントリが書き込まれたあとで、出力ストリームがフラッシュされます。 出力ストリームはこのメソッドから復帰したあとも開いたままです。


フレンドと関連する関数

std::ostream& operator<< std::ostream &  lhs,
const Properties rhs
[friend]
 


このクラスの説明は次のファイルから生成されました:
OpenRTMに対してFri Oct 5 05:15:04 2007に生成されました。  doxygen 1.4.1