• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / HavokLib / 89

06 Nov 2025 01:09PM UTC coverage: 63.837% (-3.2%) from 67.014%
89

push

github

PredatorCZ
s

3354 of 5254 relevant lines covered (63.84%)

129082.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/python/hk_packfile.cpp
1
#include "hk_packfile.hpp"
2
#include "hk_core.hpp"
3
#include "hklib/hk_packfile.hpp"
4
#include "pugixml.hpp"
5
#include "python/reflected_enum.hpp"
6
#include <sstream>
7
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
8

9
using hkToolsetPy = ReflectedEnumPy<hkToolset>;
10

11
static PyGetSetDef IHavokPyGetSets[] = {
12
    {"version", (getter)IHavokPy::GetVersion, nullptr,
13
     "Get version of loaded resource."},
14
    {NULL} /* Sentinel */
15
};
16

17
static PyMethodDef IHavokPyMethods[] = {
18
    {"classes", (PyCFunction)IHavokPy::GetClasses, METH_VARARGS,
19
     "Find classes by name."},
20
    {"to_xml", (PyCFunction)IHavokPy::ToXML, METH_VARARGS,
21
     "Export to XML format."},
22
    {NULL} /* Sentinel */
23
};
24

25
PyTypeObject *IHavokPy::GetType() {
1✔
26
  static PyTypeObject IHavokPyType{
27
      .tp_name = "hkPackfile",
28
      .tp_basicsize = sizeof(IHavokPy),
29
      .tp_dealloc = (destructor)IHavokPy::Dealloc,
30
      .tp_flags = Py_TPFLAGS_DEFAULT,
31
      .tp_doc = "Havok resource",
32
      .tp_methods = IHavokPyMethods,
33
      .tp_getset = (PyGetSetDef *)IHavokPyGetSets,
34
      .tp_new = IHavokPy::New,
35
  };
36
  return &IHavokPyType;
1✔
37
}
38

39
void IHavokPy::Dealloc(IHavokPy *self) {
1✔
40
  auto t0 = std::move(self->file);
1✔
41
  Py_TYPE(self)->tp_free(self);
1✔
42
}
1✔
43

44
PyObject *IHavokPy::New(PyTypeObject *type, PyObject *args, PyObject *) {
1✔
45
  IHavokPy *self = reinterpret_cast<IHavokPy *>(type->tp_alloc(type, 0));
1✔
46

47
  if (self) {
1✔
48
    const char *fileNameRaw = nullptr;
1✔
49
    if (!PyArg_ParseTuple(args, "s", &fileNameRaw)) {
1✔
50
      return nullptr;
×
51
    }
52

53
    std::string fileName(fileNameRaw);
1✔
54

55
    self->file = std::unique_ptr<IhkPackFile>(IhkPackFile::Create(fileName));
1✔
56
  }
1✔
57

58
  return reinterpret_cast<PyObject *>(self);
1✔
59
}
60

61
PyObject *IHavokPy::GetVersion(IHavokPy *self, void *) {
1✔
62
  return PyLong_FromLong(self->file->GetToolset());
1✔
63
}
64

65
PyObject *IHavokPy::GetClasses(IHavokPy *self, PyObject *args) {
4✔
66
  const char *classNameRaw = nullptr;
4✔
67
  if (!PyArg_ParseTuple(args, "s", &classNameRaw)) {
4✔
68
    return nullptr;
×
69
  }
70

71
  JenHash classHash(classNameRaw);
4✔
72

73
  auto foundItems = self->file->GetClasses(classHash);
4✔
74
  PyObject *rtlist = PyList_New(0);
4✔
75

76
  for (auto &c : foundItems) {
8✔
77
    auto foundCt = hkClasses.find(classHash);
4✔
78

79
    if (foundCt == hkClasses.end()) {
4✔
80
      continue;
×
81
    }
82

83
    PyList_Append(rtlist, foundCt->second(c));
4✔
84
  }
85

86
  return rtlist;
4✔
87
}
4✔
88

89
PyObject *IHavokPy::ToXML(IHavokPy *self, PyObject *args) {
×
90
  const char *fileNameRaw = nullptr;
×
91
  hkToolset toolsetVersion;
92

93
  if (!PyArg_ParseTuple(args, "I|s", &toolsetVersion, &fileNameRaw)) {
×
94
    return nullptr;
×
95
  }
96

97
  if (fileNameRaw) {
×
98
    self->file->ToXML(fileNameRaw, toolsetVersion);
×
99
    Py_RETURN_NONE;
×
100
  } else {
101
    pugi::xml_document doc;
×
102
    self->file->ToXML(doc, toolsetVersion);
×
103
    std::stringstream ss;
×
104
    doc.save(ss);
×
105
    std::string str = ss.str();
×
106

107
    return PyUnicode_FromStringAndSize(str.data(), str.size());
×
108
  }
109
}
110

111
void IHavokPy::InitType(PyObject *module) {
1✔
112
  PyAddTypes<IHavokPy, hkToolsetPy>(module);
1✔
113
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc