| 132 | } |
| 133 | |
| 134 | String ConfigObjectUtility::CreateObjectConfig(const Type::Ptr& type, const String& fullName, |
| 135 | bool ignoreOnError, const Array::Ptr& templates, const Dictionary::Ptr& attrs) |
| 136 | { |
| 137 | auto *nc = dynamic_cast<NameComposer *>(type.get()); |
| 138 | Dictionary::Ptr nameParts; |
| 139 | String name; |
| 140 | |
| 141 | if (nc) { |
| 142 | nameParts = nc->ParseName(fullName); |
| 143 | name = nameParts->Get("name"); |
| 144 | } else |
| 145 | name = fullName; |
| 146 | |
| 147 | Dictionary::Ptr allAttrs = new Dictionary(); |
| 148 | |
| 149 | if (attrs) { |
| 150 | attrs->CopyTo(allAttrs); |
| 151 | |
| 152 | ObjectLock olock(attrs); |
| 153 | for (const Dictionary::Pair& kv : attrs) { |
| 154 | int fid = type->GetFieldId(kv.first.SubStr(0, kv.first.FindFirstOf("."))); |
| 155 | |
| 156 | if (fid < 0) |
| 157 | BOOST_THROW_EXCEPTION(ScriptError("Invalid attribute specified: " + kv.first)); |
| 158 | |
| 159 | Field field = type->GetFieldInfo(fid); |
| 160 | |
| 161 | if (!(field.Attributes & FAConfig) || kv.first == "name") |
| 162 | BOOST_THROW_EXCEPTION(ScriptError("Attribute is marked for internal use only and may not be set: " + kv.first)); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if (nameParts) |
| 167 | nameParts->CopyTo(allAttrs); |
| 168 | |
| 169 | allAttrs->Remove("name"); |
| 170 | |
| 171 | /* update the version for config sync */ |
| 172 | allAttrs->Set("version", Utility::GetTime()); |
| 173 | |
| 174 | std::ostringstream config; |
| 175 | ConfigWriter::EmitConfigItem(config, type->GetName(), name, false, ignoreOnError, templates, allAttrs); |
| 176 | ConfigWriter::EmitRaw(config, "\n"); |
| 177 | |
| 178 | return config.str(); |
| 179 | } |
| 180 | |
| 181 | bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& fullName, |
| 182 | const String& config, const Array::Ptr& errors, const Array::Ptr& diagnosticInformation, const Value& cookie) |
nothing calls this directly
no test coverage detected