/usr/include/camp-xml/common.inl is in libcamp-dev 0.8.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | /****************************************************************************
**
** Copyright (C) 2009-2014 TEGESO/TEGESOFT and/or its subsidiary(-ies) and mother company.
** Contact: Tegesoft Information (contact@tegesoft.com)
**
** This file is part of the CAMP library.
**
** The MIT License (MIT)
**
** Copyright (C) 2009-2014 TEGESO/TEGESOFT and/or its subsidiary(-ies) and mother company.
**
** 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.
**
****************************************************************************/
namespace camp
{
namespace xml
{
namespace detail
{
//-------------------------------------------------------------------------------------------------
template <typename Proxy>
void serialize(const UserObject& object, typename Proxy::NodeType node, const Value& exclude)
{
// Iterate over the object's properties using its metaclass
const Class& metaclass = object.getClass();
for (std::size_t i = 0; i < metaclass.propertyCount(); ++i)
{
const Property& property = metaclass.property(i);
// If the property has the exclude tag, ignore it
if ((exclude != Value::nothing) && property.hasTag(exclude))
continue;
// Create a child node for the new property
typename Proxy::NodeType child = Proxy::addChild(node, property.name());
if (!Proxy::isValid(child))
continue;
if (property.type() == userType)
{
// The current property is a composed type: serialize it recursively
serialize<Proxy>(property.get(object).to<UserObject>(), child, exclude);
}
else if (property.type() == arrayType)
{
// The current property is an array
const ArrayProperty& arrayProperty = static_cast<const ArrayProperty&>(property);
// Iterate over the array elements
std::size_t count = arrayProperty.size(object);
for (std::size_t j = 0; j < count; ++j)
{
// Add a new XML node for each array element
typename Proxy::NodeType item = Proxy::addChild(child, "item");
if (Proxy::isValid(item))
{
if (arrayProperty.elementType() == userType)
{
// The array elements are composed objects: serialize them recursively
serialize<Proxy>(arrayProperty.get(object, j).to<UserObject>(), item, exclude);
}
else
{
// The array elements are simple properties: write them as the text of their XML node
Proxy::setText(item, arrayProperty.get(object, j));
}
}
}
}
else
{
// The current property is a simple property: write its value as the node's text
Proxy::setText(child, property.get(object));
}
}
}
//-------------------------------------------------------------------------------------------------
template <typename Proxy>
void deserialize(const UserObject& object, typename Proxy::NodeType node, const Value& exclude)
{
// Iterate over the object's properties using its metaclass
const Class& metaclass = object.getClass();
for (std::size_t i = 0; i < metaclass.propertyCount(); ++i)
{
const Property& property = metaclass.property(i);
// If the property has the exclude tag, ignore it
if ((exclude != Value::nothing) && property.hasTag(exclude))
continue;
// Find the child node corresponding to the new property
typename Proxy::NodeType child = Proxy::findFirstChild(node, property.name());
if (!Proxy::isValid(child))
continue;
if (property.type() == userType)
{
// The current property is a composed type: deserialize it recursively
deserialize<Proxy>(property.get(object).to<UserObject>(), child, exclude);
}
else if (property.type() == arrayType)
{
// The current property is an array
const ArrayProperty& arrayProperty = static_cast<const ArrayProperty&>(property);
// Iterate over the child XML node and extract all the array elements
std::size_t index = 0;
for (typename Proxy::NodeType item = Proxy::findFirstChild(child, "item")
; Proxy::isValid(item)
; item = Proxy::findNextSibling(item, "item"))
{
// Make sure that there are enough elements in the array
std::size_t count = arrayProperty.size(object);
if (index >= count)
{
if (arrayProperty.dynamic())
arrayProperty.resize(object, index + 1);
else
break;
}
if (arrayProperty.elementType() == userType)
{
// The array elements are composed objects: deserialize them recursively
deserialize<Proxy>(arrayProperty.get(object, index).to<UserObject>(), item, exclude);
}
else
{
// The array elements are simple properties: read their value from the text of their XML node
arrayProperty.set(object, index, Proxy::getText(item));
}
index++;
}
}
else
{
// The current property is a simple property: read its value from the node's text
property.set(object, Proxy::getText(child));
}
}
}
} // namespace detail
} // namespace xml
} // namespace camp
|