Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed to work with Arduino, added a class to subscribe for paths
- Loading branch information
1 parent
85ed7fd
commit fbd6f7d
Showing
5 changed files
with
128 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* PathConstructor.cpp | ||
* | ||
* Created on: 04.01.2017 | ||
* Author: caladan | ||
*/ | ||
|
||
#include "PathConstructor.h" | ||
#include <string.h> | ||
|
||
PathConstructor::PathConstructor(uint32_t reserve, char separator): size(0), separator(separator) | ||
{ | ||
buffer.reserve(reserve); | ||
sizes.reserve(reserve / 8); | ||
} | ||
|
||
PathConstructor::~PathConstructor() | ||
{ | ||
} | ||
|
||
void PathConstructor::push(const std::string& s) | ||
{ | ||
sizes.push_back(s.size()+1); //this part + separator | ||
size += s.size() + 1; | ||
|
||
buffer += separator; | ||
buffer.append(s); | ||
|
||
} | ||
|
||
void PathConstructor::push(const char* s) | ||
{ | ||
int len = strlen(s) + 1; | ||
sizes.push_back(len); | ||
size += len; | ||
|
||
buffer += separator; | ||
buffer.append(s); | ||
} | ||
|
||
void PathConstructor::pop() | ||
{ | ||
if (sizes.size() == 0) | ||
return; //nothing to pop | ||
|
||
int sizeToRemove = sizes.back(); | ||
sizes.pop_back(); | ||
int startPos = buffer.size() - sizeToRemove; | ||
buffer.erase(startPos, sizeToRemove); | ||
size -= sizeToRemove; | ||
} | ||
|
||
void PathConstructor::clear() | ||
{ | ||
sizes.clear(); | ||
buffer.clear(); | ||
} |
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,34 @@ | ||
/* | ||
* PathConstructor.h | ||
* | ||
* Created on: 04.01.2017 | ||
* Author: caladan | ||
*/ | ||
|
||
#ifndef PATHCONSTRUCTOR_H_ | ||
#define PATHCONSTRUCTOR_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class PathConstructor { | ||
public: | ||
PathConstructor(uint32_t reserve = 64, char separator = '/'); | ||
virtual ~PathConstructor(); | ||
|
||
void push(const std::string& s); | ||
void push(const char* s); | ||
|
||
void pop(); | ||
|
||
void clear(); | ||
|
||
const std::string& getPath() {return buffer;} | ||
private: | ||
std::string buffer; | ||
size_t size; | ||
std::vector<uint16_t> sizes; | ||
char separator; | ||
}; | ||
|
||
#endif /* PATHCONSTRUCTOR_H_ */ |
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