version 1.2, 2001/06/16 15:57:48
|
version 1.3, 2001/06/17 04:20:33
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// copy of this software and associated documentation files (the "Software"), |
// of this software and associated documentation files (the "Software"), to |
// to deal in the Software without restriction, including without limitation |
// deal in the Software without restriction, including without limitation the |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// and/or sell copies of the Software, and to permit persons to whom the |
// sell copies of the Software, and to permit persons to whom the Software is |
// Software is furnished to do so, subject to the following conditions: |
// furnished to do so, subject to the following conditions: |
// | // |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
// DEALINGS IN THE SOFTWARE. |
// 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. |
// | // |
//============================================================================== | //============================================================================== |
// | // |
|
|
#define TO_OBJECT_NAME_INDEX 5 | #define TO_OBJECT_NAME_INDEX 5 |
#define TO_CLASS_NAME_INDEX 6 | #define TO_CLASS_NAME_INDEX 6 |
#define TO_PROPERTY_NAME_INDEX 7 | #define TO_PROPERTY_NAME_INDEX 7 |
|
#define NUM_FIELDS 8 |
| |
static inline Boolean _Match(const String& x, const String& pattern) | static inline Boolean _Match(const String& x, const String& pattern) |
{ | { |
return pattern.size() == 0 || x == pattern; | return pattern.size() == 0 || x == pattern; |
} | } |
| |
static Boolean _GetLine(ifstream& is, Array<String>& fields) |
static String _Escape(const String& str) |
{ | { |
// Get the next line: |
String result; |
| |
|
for (Uint32 i = 0, n = str.size(); i < n; i++) |
|
{ |
|
Char16 c = str[i]; |
|
|
|
switch (c) |
|
{ |
|
case '\n': |
|
result += "\\n"; |
|
break; |
|
|
|
case '\r': |
|
result += "\\r"; |
|
break; |
|
|
|
case '\t': |
|
result += "\\t"; |
|
break; |
|
|
|
case '\f': |
|
result += "\\f"; |
|
break; |
|
|
|
case '\\': |
|
result += "\\\\"; |
|
break; |
|
|
|
default: |
|
result += c; |
|
} |
|
} |
|
|
|
return result; |
|
} |
|
|
|
static String _Unescape(const String& str) |
|
{ |
|
String result; |
|
|
|
for (Uint32 i = 0, n = str.size(); i < n; i++) |
|
{ |
|
Char16 c = str[i]; |
|
|
|
if (c == '\\') |
|
{ |
|
if (i + 1 == n) |
|
break; |
|
|
|
c = str[i + 1]; |
|
|
|
switch (c) |
|
{ |
|
case 'n': |
|
result += "\n"; |
|
break; |
|
|
|
case 'r': |
|
result += "\r"; |
|
break; |
|
|
|
case 't': |
|
result += "\t"; |
|
break; |
|
|
|
case 'f': |
|
result += "\f"; |
|
break; |
|
|
|
default: |
|
result += c; |
|
} |
|
} |
|
else |
|
result += c; |
|
} |
|
|
|
return result; |
|
} |
|
|
|
static Boolean _GetRecord(ifstream& is, Array<String>& fields) |
|
{ |
|
fields.clear(); |
String line; | String line; |
| |
|
for (Uint32 i = 0; i < NUM_FIELDS; i++) |
|
{ |
if (!GetLine(is, line)) | if (!GetLine(is, line)) |
return false; | return false; |
| |
// Split line into fields: |
fields.append(_Unescape(line)); |
|
} |
|
|
|
// Skip the blank line: |
|
|
|
if (!GetLine(is, line)) |
|
return false; |
| |
String::split(line, fields); |
|
return true; | return true; |
} | } |
| |
static void _WriteLine( |
static void _PutRecord(ofstream& os, Array<String>& fields) |
ofstream& os, |
|
Array<String>& fields) |
|
{ | { |
// Insert the entry: |
for (Uint32 i = 0, n = fields.size(); i < n; i++) |
|
os << _Escape(fields[i]) << endl; |
|
os << endl; |
|
} |
| |
String line; |
void AssocTable::append( |
String::join(fields, line); |
PEGASUS_STD(ofstream)& os, |
os << line << endl; |
const String& assocInstanceName, |
|
const String& assocClassName, |
|
const String& fromObjectName, |
|
const String& fromClassName, |
|
const String& fromPropertyName, |
|
const String& toObjectName, |
|
const String& toClassName, |
|
const String& toPropertyName) |
|
{ |
|
Array<String> fields; |
|
fields.reserve(8); |
|
fields.append(assocInstanceName); |
|
fields.append(assocClassName); |
|
fields.append(fromObjectName); |
|
fields.append(fromClassName); |
|
fields.append(fromPropertyName); |
|
fields.append(toObjectName); |
|
fields.append(toClassName); |
|
fields.append(toPropertyName); |
|
|
|
_PutRecord(os, fields); |
} | } |
| |
void AssocTable::append( | void AssocTable::append( |
|
|
fields.append(toClassName); | fields.append(toClassName); |
fields.append(toPropertyName); | fields.append(toPropertyName); |
| |
_WriteLine(os, fields); |
_PutRecord(os, fields); |
} | } |
| |
Boolean AssocTable::containsObject( | Boolean AssocTable::containsObject( |
|
|
| |
Array<String> fields; | Array<String> fields; |
| |
while (_GetLine(is, fields)) |
while (_GetRecord(is, fields)) |
{ | { |
if (fields[TO_OBJECT_NAME_INDEX] == objectName) | if (fields[TO_OBJECT_NAME_INDEX] == objectName) |
return true; | return true; |
|
|
Array<String> fields; | Array<String> fields; |
Boolean found = false; | Boolean found = false; |
| |
while (_GetLine(is, fields)) |
while (_GetRecord(is, fields)) |
{ | { |
if (assocInstanceName != fields[ASSOC_INSTANCE_NAME_INDEX]) | if (assocInstanceName != fields[ASSOC_INSTANCE_NAME_INDEX]) |
{ | { |
_WriteLine(os, fields); |
_PutRecord(os, fields); |
found = true; | found = true; |
} | } |
} | } |
|
|
Array<String> fields; | Array<String> fields; |
Boolean found = false; | Boolean found = false; |
| |
while (_GetLine(is, fields)) |
while (_GetRecord(is, fields)) |
{ | { |
if (objectName == fields[FROM_OBJECT_NAME_INDEX] && | if (objectName == fields[FROM_OBJECT_NAME_INDEX] && |
_Match(fields[ASSOC_CLASS_NAME_INDEX], assocClass) && | _Match(fields[ASSOC_CLASS_NAME_INDEX], assocClass) && |
|
|
Array<String> fields; | Array<String> fields; |
Boolean found = false; | Boolean found = false; |
| |
while (_GetLine(is, fields)) |
while (_GetRecord(is, fields)) |
{ | { |
if (objectName == fields[FROM_OBJECT_NAME_INDEX] && | if (objectName == fields[FROM_OBJECT_NAME_INDEX] && |
_Match(fields[ASSOC_CLASS_NAME_INDEX], resultClass) && | _Match(fields[ASSOC_CLASS_NAME_INDEX], resultClass) && |