-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dan Smith
committed
Jan 10, 2022
1 parent
26ba1a9
commit 571ab48
Showing
17 changed files
with
495 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
externals/nitro/modules/c++/nitf/include/nitf/FieldDescriptor.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* ========================================================================= | ||
* This file is part of NITRO | ||
* ========================================================================= | ||
* | ||
* (C) Copyright 2004 - 2014, MDA Information Systems LLC | ||
* (C) Copyright 2022 , Maxar Technologies, Inc. | ||
* | ||
* NITRO is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, If not, | ||
* see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef NITRO_nitf_FieldDescriptor_hpp_INCLUDED_ | ||
#define NITRO_nitf_FieldDescriptor_hpp_INCLUDED_ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <std/span> | ||
#include <stdexcept> | ||
|
||
#include "nitf/FieldDescriptor.h" | ||
#include "nitf/Field.hpp" | ||
#include "nitf/Object.hpp" | ||
|
||
namespace nitf | ||
{ | ||
// wrap nitf_StructFieldDescriptor | ||
class FieldDescriptor final | ||
{ | ||
const nitf_StructFieldDescriptor* pNative = nullptr; | ||
public: | ||
enum class Type | ||
{ | ||
Field = NITF_FieldType_Field, // nitf_Field* | ||
FileSecurity = NITF_FieldType_FileSecurity, // nitf_FileSecurity* | ||
ComponentInfo = NITF_FieldType_ComponentInfo, // nitf_ComponentInfo* | ||
PComponentInfo = NITF_FieldType_PComponentInfo, // nitf_ComponentInfo** aka nitf_PComponentInfo* | ||
Extensions = NITF_FieldType_Extensions, // nitf_Extensions* | ||
}; | ||
FieldDescriptor(const nitf_StructFieldDescriptor& native) noexcept : pNative(&native) {} | ||
~FieldDescriptor() = default; | ||
FieldDescriptor(const FieldDescriptor&) = default; | ||
FieldDescriptor& operator=(const FieldDescriptor&) = default; | ||
FieldDescriptor(FieldDescriptor&&) = default; | ||
FieldDescriptor& operator=(FieldDescriptor&&) = default; | ||
|
||
Type type() const noexcept | ||
{ | ||
return static_cast<Type>(pNative->type); | ||
} | ||
std::string name() const | ||
{ | ||
return pNative->name; | ||
} | ||
size_t offset() const noexcept | ||
{ | ||
return pNative->offset; | ||
} | ||
|
||
template<typename TObject> | ||
Field getField(const TObject& object) const | ||
{ | ||
if (type() != Type::Field) | ||
{ | ||
throw std::logic_error("Descriptor '" + name() + "' is not a 'Field' type."); | ||
} | ||
return fromNativeOffset<Field>(object, offset()); | ||
} | ||
}; | ||
|
||
extern std::vector<FieldDescriptor> getFieldDescriptors(std::span<const nitf_StructFieldDescriptor>); | ||
template<size_t N> | ||
inline std::vector<FieldDescriptor> getFieldDescriptors(const nitf_StructFieldDescriptor(&descriptors)[N]) | ||
{ | ||
// constexpr auto extent = std::extent<decltype(nitf_testing_Test1b_fields)>::value; | ||
const std::span<const nitf_StructFieldDescriptor> s(descriptors, N); | ||
return getFieldDescriptors(s); | ||
} | ||
} | ||
#endif // NITRO_nitf_FieldDescriptor_hpp_INCLUDED_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.