This repository has been archived on 2025-02-01. You can view files and clone it, but cannot push or open issues or pull requests.
reprapfirmware-dc42/StringRef.h
David Crocker 0636efee40 Version 1.09p-alpha2
Fixed issue with rare missing steps at the end of delta moves
Fix minor delta calibration issue
Fix issue with ADC crosstalk on Duet 0.8.5
Refactored RepRap and OutputBuffer classes in preparation for fixing the
OutputBuffer bugs
2016-01-10 22:04:30 +00:00

42 lines
970 B
C++

/*
* StringRef.h
*
* Created on: 10 Jan 2016
* Author: David
*/
#ifndef STRINGREF_H_
#define STRINGREF_H_
#include <cstddef> // for size_t
#include <cstdarg> // for va_args
#undef printf
// Class to describe a string buffer, including its length. This saves passing buffer lengths around everywhere.
class StringRef
{
char *p; // pointer to the storage
size_t len; // number of characters in the storage
public:
StringRef(char *pp, size_t pl) : p(pp), len(pl) { }
size_t Length() const { return len; }
size_t strlen() const;
char *Pointer() { return p; }
const char *Pointer() const { return p; }
char& operator[](size_t index) { return p[index]; }
char operator[](size_t index) const { return p[index]; }
void Clear() { p[0] = 0; }
int printf(const char *fmt, ...);
int vprintf(const char *fmt, va_list vargs);
int catf(const char *fmt, ...);
size_t copy(const char* src);
size_t cat(const char *src);
};
#endif /* STRINGREF_H_ */