mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
uORB: factor out ORBMap.hpp into a separate file
The new uORB::ORBMap class was put it its own file with proper copyright. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
parent
05b6bcd168
commit
4df833d25d
@ -37,6 +37,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "ORBMap.hpp"
|
||||
#include "uORBCommon.hpp"
|
||||
|
||||
|
||||
@ -44,93 +45,8 @@ namespace uORB
|
||||
{
|
||||
class DeviceNode;
|
||||
class DeviceMaster;
|
||||
class ORBMap;
|
||||
}
|
||||
|
||||
class uORB::ORBMap
|
||||
{
|
||||
public:
|
||||
struct Node {
|
||||
struct Node *next;
|
||||
const char * node_name;
|
||||
uORB::DeviceNode *node;
|
||||
};
|
||||
|
||||
ORBMap() :
|
||||
_top(nullptr),
|
||||
_end(nullptr)
|
||||
{ }
|
||||
~ORBMap() {
|
||||
while (_top != nullptr) {
|
||||
unlinkNext(_top);
|
||||
if (_top->next == nullptr) {
|
||||
free((void *)_top->node_name);
|
||||
free(_top);
|
||||
_top = nullptr;
|
||||
_end = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
void insert(const char *node_name, uORB::DeviceNode*node)
|
||||
{
|
||||
Node **p;
|
||||
if (_top == nullptr)
|
||||
p = &_top;
|
||||
else
|
||||
p = &_end->next;
|
||||
|
||||
*p = (Node *)malloc(sizeof(Node));
|
||||
if (_end)
|
||||
_end = _end->next;
|
||||
else {
|
||||
_end = _top;
|
||||
}
|
||||
_end->next = nullptr;
|
||||
_end->node_name = strdup(node_name);
|
||||
_end->node = node;
|
||||
}
|
||||
|
||||
bool find(const char *node_name)
|
||||
{
|
||||
Node *p = _top;
|
||||
while (p) {
|
||||
if (strcmp(p->node_name, node_name) == 0) {
|
||||
return true;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uORB::DeviceNode* get(const char *node_name)
|
||||
{
|
||||
Node *p = _top;
|
||||
while (p) {
|
||||
if (strcmp(p->node_name, node_name) == 0) {
|
||||
return p->node;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void unlinkNext(Node *a)
|
||||
{
|
||||
Node *b = a->next;
|
||||
if (b != nullptr) {
|
||||
if (_end == b) {
|
||||
_end = a;
|
||||
}
|
||||
a->next = b->next;
|
||||
free((void *)b->node_name);
|
||||
free(b);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Node *_top;
|
||||
Node *_end;
|
||||
};
|
||||
|
||||
/**
|
||||
* Per-object device instance.
|
||||
*/
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
#include "uORBDevices.hpp"
|
||||
#include <stdint.h>
|
||||
#ifdef __PX4_NUTTX
|
||||
#include "ORBSet.h"
|
||||
#include "ORBSet.hpp"
|
||||
#else
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user