Skip to content

Commit

Permalink
namespace all sigmf objects within sigmf
Browse files Browse the repository at this point in the history
this includes the flatbuffers schema files. this change is largely due to best
practices but also to enable proper building on osx which includes 'signal.h'
causing a namespace conflict with a top level `signal` namespace...
  • Loading branch information
Jacob Gilbert committed Feb 26, 2022
1 parent 74a4e4c commit 6feb819
Show file tree
Hide file tree
Showing 26 changed files with 1,248 additions and 1,143 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ fields will be included in the output if and only if they are set.
Other v1.0 changes include: updating to the latest SigMF metadata fields in the included schemas (including
redefining all scalar fields as optional via `=null;`), updating to flatbuffers v2.0.0 syntax, using `shared_ptr`
for generated headers instead of `unique_ptr`, cmake updates, updates to examples to ensure optional fields are
working correctly, update to require c++17 for `std::optional`.
working correctly, update to require c++17 for `std::optional`, and namespacing the entire library and associated
schema files within the `sigmf::` c++ namespace.

To update existing code from flatbuffers v0.1 and earlier to v1.0, accessing a field like this:
To update existing code from libsigmf v0.x to v1.x, some changes are required. Accessing a field like this:

```c++
annotation_sample_start = annotation.sample_start;
```

is no longer valid as the `annotation.sample_start` field is not a `uint64_t`, its a `std::optional` and must now
be checked to see if it has been set, then accessed via a legal means such as:
be checked to see if it has been set, then accessed in a legal way, such as:

```c++
if (annotation.sample_start.has_value()) {
Expand Down
11 changes: 5 additions & 6 deletions examples/example_reading_sigmf_file.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019, 2021 DeepSig Inc.
* Copyright 2019, 2021, 2022 DeepSig Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,8 @@

#include "sigmf_core_generated.h"
#include "sigmf_antenna_generated.h"
#include "sigmf_capture_details_generated.h"
#include "sigmf_signal_generated.h"
#include "sigmf.h"
#include "sigmf_helpers.h"
#include <iostream>
Expand All @@ -29,9 +31,6 @@ int main(int argc, char* argv[]) {
std::cout << "The record we read is: \n" <<
record->to_json().dump(2) << std::endl;


assert(true); // this is just a smoke test

std::cout << "example_reading_sigmf_file passed" << std::endl;
std::cout << "example_reading_sigmf_file passed (just a smoke test, no field validation)" << std::endl;
return 0; // assert passed, we're good :+1:
}
}
5 changes: 4 additions & 1 deletion examples/example_record_with_multiple_namespaces.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019, 2021 DeepSig Inc.
* Copyright 2019, 2021, 2022 DeepSig Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,8 @@
#include "sigmf.h"
#include "testing_protocols_generated.h"

using namespace sigmf;

int main() {

/*
Expand Down Expand Up @@ -164,3 +166,4 @@ int main() {
std::cout << "example_record_with_multiple_namespaces passed" << std::endl;
return 0; // assert passed, we're good :+1:
}

4 changes: 3 additions & 1 deletion examples/example_record_with_variadic_dataclass.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019, 2021 DeepSig Inc.
* Copyright 2019, 2021, 2022 DeepSig Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,8 @@
#include "sigmf.h"
#include <iostream>

using namespace sigmf;

int main() {
/*
* Create a record with core namespace using the VariadicDataClass as an example. This is kind of
Expand Down
4 changes: 3 additions & 1 deletion examples/example_sigmf_json_roundtrip.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019, 2021 DeepSig Inc.
* Copyright 2019, 2021, 2022 DeepSig Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,8 @@
#include "sigmf.h"
#include <nlohmann/json.hpp>

using namespace sigmf;

int main() {


Expand Down
4 changes: 3 additions & 1 deletion examples/flatbuffer_patterns.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 DeepSig Inc.
* Copyright 2019, 2022 DeepSig Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,8 @@
#include <iostream>
#include <stdint.h>

using namespace sigmf;

int main() {
//
// The standard way of dealing with flatbuffers...
Expand Down
2 changes: 1 addition & 1 deletion sigmf_protocols/sigmf_adsb.fbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

namespace adsb;
namespace sigmf.adsb;

table Global { /*`adsb` does not extend `global`*/ }

Expand Down
60 changes: 31 additions & 29 deletions sigmf_protocols/sigmf_adsb_generated.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// automatically generated by the FlatBuffers compiler, do not modify


#ifndef FLATBUFFERS_GENERATED_SIGMFADSB_ADSB_H_
#define FLATBUFFERS_GENERATED_SIGMFADSB_ADSB_H_
#ifndef FLATBUFFERS_GENERATED_SIGMFADSB_SIGMF_ADSB_H_
#define FLATBUFFERS_GENERATED_SIGMFADSB_SIGMF_ADSB_H_

#include "flatbuffers/flatbuffers.h"

namespace sigmf {
namespace adsb {

struct Global;
Expand Down Expand Up @@ -368,7 +369,7 @@ inline flatbuffers::Offset<Annotation> CreateAnnotationDirect(
auto manufacturer_ta__ = manufacturer_ta ? _fbb.CreateString(manufacturer_ta) : 0;
auto MAC_frame__ = MAC_frame ? _fbb.CreateString(MAC_frame) : 0;
auto CRC__ = CRC ? _fbb.CreateString(CRC) : 0;
return adsb::CreateAnnotation(
return sigmf::adsb::CreateAnnotation(
_fbb,
standard__,
frame_type_phy__,
Expand All @@ -392,9 +393,9 @@ flatbuffers::Offset<Annotation> CreateAnnotation(flatbuffers::FlatBufferBuilder

struct DescrT : public flatbuffers::NativeTable {
typedef Descr TableType;
std::shared_ptr<adsb::GlobalT> global{};
std::shared_ptr<adsb::AnnotationT> annotation{};
std::shared_ptr<adsb::CaptureT> capture{};
std::shared_ptr<sigmf::adsb::GlobalT> global{};
std::shared_ptr<sigmf::adsb::AnnotationT> annotation{};
std::shared_ptr<sigmf::adsb::CaptureT> capture{};
};

struct Descr FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
Expand All @@ -408,14 +409,14 @@ struct Descr FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_ANNOTATION = 6,
VT_CAPTURE = 8
};
const adsb::Global *global() const {
return GetPointer<const adsb::Global *>(VT_GLOBAL);
const sigmf::adsb::Global *global() const {
return GetPointer<const sigmf::adsb::Global *>(VT_GLOBAL);
}
const adsb::Annotation *annotation() const {
return GetPointer<const adsb::Annotation *>(VT_ANNOTATION);
const sigmf::adsb::Annotation *annotation() const {
return GetPointer<const sigmf::adsb::Annotation *>(VT_ANNOTATION);
}
const adsb::Capture *capture() const {
return GetPointer<const adsb::Capture *>(VT_CAPTURE);
const sigmf::adsb::Capture *capture() const {
return GetPointer<const sigmf::adsb::Capture *>(VT_CAPTURE);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
Expand All @@ -436,13 +437,13 @@ struct DescrBuilder {
typedef Descr Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_global(flatbuffers::Offset<adsb::Global> global) {
void add_global(flatbuffers::Offset<sigmf::adsb::Global> global) {
fbb_.AddOffset(Descr::VT_GLOBAL, global);
}
void add_annotation(flatbuffers::Offset<adsb::Annotation> annotation) {
void add_annotation(flatbuffers::Offset<sigmf::adsb::Annotation> annotation) {
fbb_.AddOffset(Descr::VT_ANNOTATION, annotation);
}
void add_capture(flatbuffers::Offset<adsb::Capture> capture) {
void add_capture(flatbuffers::Offset<sigmf::adsb::Capture> capture) {
fbb_.AddOffset(Descr::VT_CAPTURE, capture);
}
explicit DescrBuilder(flatbuffers::FlatBufferBuilder &_fbb)
Expand All @@ -458,9 +459,9 @@ struct DescrBuilder {

inline flatbuffers::Offset<Descr> CreateDescr(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<adsb::Global> global = 0,
flatbuffers::Offset<adsb::Annotation> annotation = 0,
flatbuffers::Offset<adsb::Capture> capture = 0) {
flatbuffers::Offset<sigmf::adsb::Global> global = 0,
flatbuffers::Offset<sigmf::adsb::Annotation> annotation = 0,
flatbuffers::Offset<sigmf::adsb::Capture> capture = 0) {
DescrBuilder builder_(_fbb);
builder_.add_capture(capture);
builder_.add_annotation(annotation);
Expand Down Expand Up @@ -489,7 +490,7 @@ inline flatbuffers::Offset<Global> CreateGlobal(flatbuffers::FlatBufferBuilder &
(void)_rehasher;
(void)_o;
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const GlobalT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
return adsb::CreateGlobal(
return sigmf::adsb::CreateGlobal(
_fbb);
}

Expand All @@ -512,7 +513,7 @@ inline flatbuffers::Offset<Capture> CreateCapture(flatbuffers::FlatBufferBuilder
(void)_rehasher;
(void)_o;
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const CaptureT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
return adsb::CreateCapture(
return sigmf::adsb::CreateCapture(
_fbb);
}

Expand Down Expand Up @@ -567,7 +568,7 @@ inline flatbuffers::Offset<Annotation> CreateAnnotation(flatbuffers::FlatBufferB
auto _start_of_packet = _o->start_of_packet;
auto _stop_of_packet = _o->stop_of_packet;
auto _number_of_samples_in_packet = _o->number_of_samples_in_packet;
return adsb::CreateAnnotation(
return sigmf::adsb::CreateAnnotation(
_fbb,
_standard,
_frame_type_phy,
Expand Down Expand Up @@ -596,9 +597,9 @@ inline DescrT *Descr::UnPack(const flatbuffers::resolver_function_t *_resolver)
inline void Descr::UnPackTo(DescrT *_o, const flatbuffers::resolver_function_t *_resolver) const {
(void)_o;
(void)_resolver;
{ auto _e = global(); if (_e) _o->global = std::shared_ptr<adsb::GlobalT>(_e->UnPack(_resolver)); }
{ auto _e = annotation(); if (_e) _o->annotation = std::shared_ptr<adsb::AnnotationT>(_e->UnPack(_resolver)); }
{ auto _e = capture(); if (_e) _o->capture = std::shared_ptr<adsb::CaptureT>(_e->UnPack(_resolver)); }
{ auto _e = global(); if (_e) _o->global = std::shared_ptr<sigmf::adsb::GlobalT>(_e->UnPack(_resolver)); }
{ auto _e = annotation(); if (_e) _o->annotation = std::shared_ptr<sigmf::adsb::AnnotationT>(_e->UnPack(_resolver)); }
{ auto _e = capture(); if (_e) _o->capture = std::shared_ptr<sigmf::adsb::CaptureT>(_e->UnPack(_resolver)); }
}

inline flatbuffers::Offset<Descr> Descr::Pack(flatbuffers::FlatBufferBuilder &_fbb, const DescrT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
Expand All @@ -612,7 +613,7 @@ inline flatbuffers::Offset<Descr> CreateDescr(flatbuffers::FlatBufferBuilder &_f
auto _global = _o->global ? CreateGlobal(_fbb, _o->global.get(), _rehasher) : 0;
auto _annotation = _o->annotation ? CreateAnnotation(_fbb, _o->annotation.get(), _rehasher) : 0;
auto _capture = _o->capture ? CreateCapture(_fbb, _o->capture.get(), _rehasher) : 0;
return adsb::CreateDescr(
return sigmf::adsb::CreateDescr(
_fbb,
_global,
_annotation,
Expand Down Expand Up @@ -683,9 +684,9 @@ inline const flatbuffers::TypeTable *DescrTypeTable() {
{ flatbuffers::ET_SEQUENCE, 0, 2 }
};
static const flatbuffers::TypeFunction type_refs[] = {
adsb::GlobalTypeTable,
adsb::AnnotationTypeTable,
adsb::CaptureTypeTable
sigmf::adsb::GlobalTypeTable,
sigmf::adsb::AnnotationTypeTable,
sigmf::adsb::CaptureTypeTable
};
static const char * const names[] = {
"global",
Expand All @@ -699,5 +700,6 @@ inline const flatbuffers::TypeTable *DescrTypeTable() {
}

} // namespace adsb
} // namespace sigmf

#endif // FLATBUFFERS_GENERATED_SIGMFADSB_ADSB_H_
#endif // FLATBUFFERS_GENERATED_SIGMFADSB_SIGMF_ADSB_H_
2 changes: 1 addition & 1 deletion sigmf_protocols/sigmf_antenna.fbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

namespace antenna;
namespace sigmf.antenna;

table Global {
model:string;
Expand Down
Loading

0 comments on commit 6feb819

Please sign in to comment.