Coverage Report

Created: 2026-12-03 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/AI/MCP/src/JSONCopy.cpp
Line
Count
Source
1
//
2
// JSONCopy.cpp
3
//
4
// Library: AI/MCP
5
// Package: Core
6
// Module:  JSONCopy
7
//
8
// Copyright (c) 2026, Aleph ONE Software Engineering LLC.
9
// and Contributors.
10
//
11
// SPDX-License-Identifier: BSL-1.0
12
//
13
14
15
#include "JSONCopy.h"
16
#include "Poco/JSON/Array.h"
17
#include <typeinfo>
18
19
20
namespace Poco::AI::MCP {
21
22
23
namespace
24
{
25
  Poco::JSON::Array::Ptr copyArray(const Poco::JSON::Array& array)
26
8.84k
  {
27
8.84k
    Poco::JSON::Array::Ptr pCopy = new Poco::JSON::Array;
28
8.84k
    for (const auto& element: array)
29
109k
    {
30
109k
      pCopy->add(copyValue(element));
31
109k
    }
32
8.84k
    return pCopy;
33
8.84k
  }
34
}
35
36
37
Poco::JSON::Object::Ptr copyObject(const Poco::JSON::Object& object)
38
11.3k
{
39
11.3k
  Poco::JSON::Object::Ptr pCopy = new Poco::JSON::Object(Poco::JSON_PRESERVE_KEY_ORDER);
40
11.3k
  for (const std::string& name: object.getNames())
41
23.6k
  {
42
23.6k
    pCopy->set(name, copyValue(object.get(name)));
43
23.6k
  }
44
11.3k
  return pCopy;
45
11.3k
}
46
47
48
Poco::Dynamic::Var copyValue(const Poco::Dynamic::Var& value)
49
132k
{
50
132k
  if (value.type() == typeid(Poco::JSON::Object::Ptr))
51
10.8k
  {
52
10.8k
    const Poco::JSON::Object::Ptr& pObject = value.extract<Poco::JSON::Object::Ptr>();
53
10.8k
    return pObject.isNull() ? value : Poco::Dynamic::Var(copyObject(*pObject));
54
10.8k
  }
55
121k
  if (value.type() == typeid(Poco::JSON::Array::Ptr))
56
8.84k
  {
57
8.84k
    const Poco::JSON::Array::Ptr& pArray = value.extract<Poco::JSON::Array::Ptr>();
58
8.84k
    return pArray.isNull() ? value : Poco::Dynamic::Var(copyArray(*pArray));
59
8.84k
  }
60
113k
  if (value.type() == typeid(Poco::JSON::Object))
61
0
  {
62
0
    return copyObject(value.extract<Poco::JSON::Object>());
63
0
  }
64
113k
  if (value.type() == typeid(Poco::JSON::Array))
65
0
  {
66
0
    return copyArray(value.extract<Poco::JSON::Array>());
67
0
  }
68
113k
  return value;
69
113k
}
70
71
72
} // namespace Poco::AI::MCP