Skip to content

Instantly share code, notes, and snippets.

@zacharycarter
Created July 6, 2020 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zacharycarter/8e1ab668fa2295089ca49037d0e3ab7a to your computer and use it in GitHub Desktop.
Save zacharycarter/8e1ab668fa2295089ca49037d0e3ab7a to your computer and use it in GitHub Desktop.
class IArchive
{
public:
...
template <typename _Ty>
bool TestTag() {
// Only tagged types can be tested. If compilations fails here, it can
// mean the file containing tag declaration is not included.
static_assert(internal::Tag<const _Ty>::kTagLength != 0,
"Tag unknown for type.");
const int tell = stream_->Tell();
bool valid = internal::Tagger<const _Ty>::Validate(*this);
stream_->Seek(tell, Stream::kSet); // Rewinds before the tag test.
return valid;
}
};
import os
const
ozzIncludePath = currentSourcePath.parentDir().parentDir()/"lib/ozz-animation/include"
type
Archive* {.importcpp: "ozz::io::IArchive", header: ozzIncludePath/"ozz/base/io/archive.h".} = object
Skeleton* {.importcpp: "ozz::animation::Skeleton", header: ozzIncludePath/"ozz/animation/runtime/skeleton.h".} = object
proc constructArchive*(stream: ptr Stream): Archive {.importcpp: "ozz::io::IArchive(@)", header: ozzIncludePath/"ozz/base/io/archive.h".}
proc testTag*[T](a: Archive): bool {.importcpp: "#.TestTag<'*0>()", header: ozzIncludePath/"ozz/base/io/archive.h".}
# error:
# !  ~/d/junkers   *~…  nim cpp -r --gc:arc --passC:-Ilib/ozz-animation/include --passL:lib/ozz-animation/.build/src/base/libozz_base.a src/rig.nim
# Hint: used config file '/Users/zacharycarter/dev/Nim/config/nim.cfg' [Conf]
# Hint: used config file '/Users/zacharycarter/dev/Nim/config/config.nims' [Conf]
# ....................
# /Users/zacharycarter/dev/junkers/src/rig.nim(18, 17) template/generic instantiation of `testTag` from here
# /Users/zacharycarter/dev/junkers/src/ozz.nim(47, 15) Error: cannot instantiate: 'T'
proc rigLoadSkeleton(skeletonFilePath: cstring): bool =
let file = constructFile(skeletonFilePath, "rb")
if not file.opened():
# TODO: Log error
return false
var memStream: MemoryStream
memStream.resize(file.size())
memStream.streamEnd = cint(file.size())
file.read(memStream.buffer, file.size())
let archive = constructArchive(addr memStream)
if not archive.testTag[Skeleton]():
# TODO: Log error
return false
result = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment