Beamlib 3.1.1
This is the Beam C++ class library.
Loading...
Searching...
No Matches
BStringLocked.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BStringLocked.h Threaded BString Handling
3 * T.Barnaby, BEAM Ltd, 2008-06-17
4 * Copyright (c) 2022 All Right Reserved, Beam Ltd, https://www.beam.ltd.uk
5 * For license see LICENSE.txt at the root of the beamlib source tree.
6 *******************************************************************************
7 */
8#ifndef BStringLocked_H
9#define BStringLocked_H 1
10
11#include <BString.h>
12#include <BMutex.h>
13
15class BStringMutex : public BMutex {
16public:
18};
19
22public:
24 BStringLocked(const BStringLocked& s) : ostr(s.ostr){}
25 BStringLocked(const BString& s) : ostr(s){}
26
27 int len() const { BMutexLock l(olock); return ostr.len(); }
28
29public:
30 operator BString() const { BMutexLock l(olock); return ostr; }
31
32 BStringLocked operator+(const BStringLocked& s) const { BMutexLock l(olock); BMutexLock l1(s.olock); ostr.append(s.ostr); return *this; }
33 BStringLocked& operator=(const BStringLocked& s) { BMutexLock l(olock); BMutexLock l1(s.olock); ostr = s.ostr; return *this; }
34
35private:
36 mutable BStringMutex olock;
37 BString ostr;
38};
39
40#endif
Mutex class that removes the lock on deletion and so is useful to lock data in a function call.
Definition: BMutex.h:33
Mutex class. Note these are recursive Mutexes and so you need to make sure the number of unlocks equa...
Definition: BMutex.h:14
@ Recursive
Definition: BMutex.h:16
Provides a basic thread locked string.
Definition: BStringLocked.h:21
BStringLocked operator+(const BStringLocked &s) const
Definition: BStringLocked.h:32
int len() const
Length of string.
Definition: BStringLocked.h:27
BStringLocked(const BString &s)
Definition: BStringLocked.h:25
BStringLocked(const BStringLocked &s)
Definition: BStringLocked.h:24
BStringLocked & operator=(const BStringLocked &s)
Definition: BStringLocked.h:33
BStringLocked()
Definition: BStringLocked.h:23
Thread locked string internal mutex.
Definition: BStringLocked.h:15
BStringMutex()
Definition: BStringLocked.h:17
This class stores and manipulates ASCII strings.
Definition: BString.h:20
int append(const BString &str)
Append a string.
Definition: BString.cpp:1061
int len() const
Length of string.
Definition: BString.cpp:306