Directory: | ./ |
---|---|
File: | src/PString.h |
Date: | 2024-11-07 16:05:26 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 19 | 19 | 100.0% |
Branches: | 7 | 7 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #ifndef __PSTRING_H__ | ||
8 | #define __PSTRING_H__ | ||
9 | |||
10 | #include <string.h> | ||
11 | #include <string> | ||
12 | #include <iostream> | ||
13 | |||
14 | #include "convertToString.h" | ||
15 | |||
16 | ///Extends the std::string | ||
17 | class PString : public std::string{ | ||
18 | public: | ||
19 | PString(); | ||
20 | PString(const std::string & str); | ||
21 | PString(const PString & other); | ||
22 | virtual ~PString(); | ||
23 | PString & operator = (const PString & other); | ||
24 | |||
25 | ///Set type in PString | ||
26 | /** @param other : type to be set in the PString | ||
27 | * @return PString | ||
28 | */ | ||
29 | template<typename T> | ||
30 | 4 | PString & operator = (const T & other){ | |
31 |
1/1✓ Branch 1 taken 2 times.
|
4 | std::string tmp(convertToString(other)); |
32 |
1/1✓ Branch 1 taken 2 times.
|
4 | copyPString(tmp); |
33 | 4 | return *this; | |
34 | 4 | } | |
35 | |||
36 | PString & operator += (const PString & other); | ||
37 | PString & operator += (const std::string & other); | ||
38 | |||
39 | ///Append type in PString | ||
40 | /** @param other : type to be appended | ||
41 | * @return PString | ||
42 | */ | ||
43 | template<typename T> | ||
44 | 12 | PString & operator += (const T & other){ | |
45 |
1/1✓ Branch 1 taken 6 times.
|
12 | std::string tmp(convertToString(other)); |
46 |
1/1✓ Branch 1 taken 6 times.
|
12 | concatenatePString(tmp); |
47 | 12 | return *this; | |
48 | 12 | } | |
49 | |||
50 | ///Append type in PString | ||
51 | /** @param other : type to be appended | ||
52 | * @return PString | ||
53 | */ | ||
54 | template<typename T> | ||
55 | 18 | PString & operator << (const T & other){ | |
56 |
1/1✓ Branch 1 taken 9 times.
|
18 | std::string tmp(convertToString(other)); |
57 |
1/1✓ Branch 1 taken 9 times.
|
18 | concatenatePString(tmp); |
58 | 18 | return *this; | |
59 | 18 | } | |
60 | |||
61 | friend PString operator + (const PString & other1, const PString & other2); | ||
62 | friend PString operator << (const PString & other1, const PString & other2); | ||
63 | |||
64 | ///Add a PString and a type | ||
65 | /** @param other1 : PString | ||
66 | * @param other2 : type to be appended | ||
67 | * @return PString | ||
68 | */ | ||
69 | template<typename T> | ||
70 | 2 | friend PString operator + (const PString & other1, const T & other2){ | |
71 | 2 | PString res(other1); | |
72 |
1/1✓ Branch 1 taken 2 times.
|
2 | res += other2; |
73 | 2 | return res; | |
74 | } | ||
75 | |||
76 | ///Add a PString and a type | ||
77 | /** @param other1 : type to be appended | ||
78 | * @param other2 : PString | ||
79 | * @return PString | ||
80 | */ | ||
81 | template<typename T> | ||
82 | friend PString operator + (const T & other1, const PString & other2){ | ||
83 | PString res; | ||
84 | res += other1; | ||
85 | res += other2; | ||
86 | return res; | ||
87 | } | ||
88 | |||
89 | protected: | ||
90 | void copyPString(const PString & other); | ||
91 | void copyPString(const std::string & other); | ||
92 | |||
93 | void concatenatePString(const PString & other); | ||
94 | void concatenatePString(const std::string & other); | ||
95 | private: | ||
96 | void initialisationPString(); | ||
97 | }; | ||
98 | |||
99 | #endif | ||
100 | |||
101 |