Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab533c3

Browse files
committed
Switched Firebase to std::string and fixed all unit tests
1 parent74a963a commitab533c3

11 files changed

+95
-194
lines changed

‎src/Firebase.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
using std::unique_ptr;
1919

2020
namespace {
21-
StringmakeFirebaseURL(constString& path,constString& auth) {
22-
String url;
21+
std::stringmakeFirebaseURL(conststd::string& path,conststd::string& auth) {
22+
std::string url;
2323
if (path[0] !='/') {
2424
url ="/";
2525
}
@@ -32,71 +32,71 @@ String makeFirebaseURL(const String& path, const String& auth) {
3232

3333
}// namespace
3434

35-
Firebase::Firebase(constString& host,constString& auth) : host_(host), auth_(auth) {
35+
Firebase::Firebase(conststd::string& host,conststd::string& auth) : host_(host), auth_(auth) {
3636
http_.reset(FirebaseHttpClient::create());
3737
http_->setReuseConnection(true);
3838
}
3939

40-
constString&Firebase::auth()const {
40+
conststd::string&Firebase::auth()const {
4141
return auth_;
4242
}
4343

44-
FirebaseGetFirebase::get(constString& path) {
44+
FirebaseGetFirebase::get(conststd::string& path) {
4545
returnFirebaseGet(host_, auth_, path, http_.get());
4646
}
4747

48-
unique_ptr<FirebaseGet>Firebase::getPtr(constString& path) {
48+
unique_ptr<FirebaseGet>Firebase::getPtr(conststd::string& path) {
4949
return unique_ptr<FirebaseGet>(newFirebaseGet(host_, auth_, path, http_.get()));
5050
}
5151

52-
FirebaseSetFirebase::set(constString& path,constString& value) {
52+
FirebaseSetFirebase::set(conststd::string& path,conststd::string& value) {
5353
returnFirebaseSet(host_, auth_, path, value, http_.get());
5454
}
5555

56-
unique_ptr<FirebaseSet>Firebase::setPtr(constString& path,
57-
constString& value) {
56+
unique_ptr<FirebaseSet>Firebase::setPtr(conststd::string& path,
57+
conststd::string& value) {
5858
return unique_ptr<FirebaseSet>(
5959
newFirebaseSet(host_, auth_, path, value, http_.get()));
6060
}
6161

62-
FirebasePushFirebase::push(constString& path,constString& value) {
62+
FirebasePushFirebase::push(conststd::string& path,conststd::string& value) {
6363
returnFirebasePush(host_, auth_, path, value, http_.get());
6464
}
65-
unique_ptr<FirebasePush>Firebase::pushPtr(constString& path,constString& value) {
65+
unique_ptr<FirebasePush>Firebase::pushPtr(conststd::string& path,conststd::string& value) {
6666
return unique_ptr<FirebasePush>(
6767
newFirebasePush(host_, auth_, path, value, http_.get()));
6868
}
6969

70-
FirebaseRemoveFirebase::remove(constString& path) {
70+
FirebaseRemoveFirebase::remove(conststd::string& path) {
7171
returnFirebaseRemove(host_, auth_, path, http_.get());
7272
}
7373

74-
unique_ptr<FirebaseRemove>Firebase::removePtr(constString& path) {
74+
unique_ptr<FirebaseRemove>Firebase::removePtr(conststd::string& path) {
7575
return unique_ptr<FirebaseRemove>(
7676
newFirebaseRemove(host_, auth_, path, http_.get()));
7777
}
7878

79-
FirebaseStreamFirebase::stream(constString& path) {
79+
FirebaseStreamFirebase::stream(conststd::string& path) {
8080
// TODO: create new client dedicated to stream.
8181
returnFirebaseStream(host_, auth_, path, http_.get());
8282
}
8383

84-
unique_ptr<FirebaseStream>Firebase::streamPtr(constString& path) {
84+
unique_ptr<FirebaseStream>Firebase::streamPtr(conststd::string& path) {
8585
// TODO: create new client dedicated to stream.
8686
return unique_ptr<FirebaseStream>(
8787
newFirebaseStream(host_, auth_, path, http_.get()));
8888
}
8989

9090
// FirebaseCall
91-
FirebaseCall::FirebaseCall(constString& host,constString& auth,
92-
constchar* method,constString& path,
93-
constString& data, FirebaseHttpClient* http) : http_(http) {
94-
String path_with_auth =makeFirebaseURL(path, auth);
91+
FirebaseCall::FirebaseCall(conststd::string& host,conststd::string& auth,
92+
constchar* method,conststd::string& path,
93+
conststd::string& data, FirebaseHttpClient* http) : http_(http) {
94+
std::string path_with_auth =makeFirebaseURL(path, auth);
9595
http_->setReuseConnection(true);
9696
http_->begin(host, path_with_auth);
9797

9898
bool followRedirect =false;
99-
if (String(method) =="STREAM") {
99+
if (std::string(method) =="STREAM") {
100100
method ="GET";
101101
http_->addHeader("Accept","text/event-stream");
102102
followRedirect =true;
@@ -112,18 +112,18 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
112112
// TODO: Add a max redirect check
113113
if (followRedirect) {
114114
while (status == HttpStatus::TEMPORARY_REDIRECT) {
115-
String location = http_->header("Location");
115+
std::string location = http_->header("Location");
116116
http_->setReuseConnection(false);
117117
http_->end();
118118
http_->setReuseConnection(true);
119119
http_->begin(location);
120-
status = http_->sendRequest("GET",String());
120+
status = http_->sendRequest("GET",std::string());
121121
}
122122
}
123123

124124
if (status !=200) {
125125
error_ =FirebaseError(status,
126-
String(method) +"" + path_with_auth +
126+
std::string(method) +"" + path_with_auth +
127127
":" + http_->errorToString(status));
128128
}
129129

@@ -141,15 +141,15 @@ const JsonObject& FirebaseCall::json() {
141141
}
142142

143143
// FirebaseGet
144-
FirebaseGet::FirebaseGet(constString& host,constString& auth,
145-
constString& path,
144+
FirebaseGet::FirebaseGet(conststd::string& host,conststd::string& auth,
145+
conststd::string& path,
146146
FirebaseHttpClient* http)
147147
: FirebaseCall(host, auth,"GET", path,"", http) {
148148
}
149149

150150
// FirebaseSet
151-
FirebaseSet::FirebaseSet(constString& host,constString& auth,
152-
constString& path,constString& value,
151+
FirebaseSet::FirebaseSet(conststd::string& host,conststd::string& auth,
152+
conststd::string& path,conststd::string& value,
153153
FirebaseHttpClient* http)
154154
: FirebaseCall(host, auth,"PUT", path, value, http) {
155155
if (!error()) {
@@ -158,8 +158,8 @@ FirebaseSet::FirebaseSet(const String& host, const String& auth,
158158
}
159159
}
160160
// FirebasePush
161-
FirebasePush::FirebasePush(constString& host,constString& auth,
162-
constString& path,constString& value,
161+
FirebasePush::FirebasePush(conststd::string& host,conststd::string& auth,
162+
conststd::string& path,conststd::string& value,
163163
FirebaseHttpClient* http)
164164
: FirebaseCall(host, auth,"POST", path, value, http) {
165165
if (!error()) {
@@ -168,15 +168,15 @@ FirebasePush::FirebasePush(const String& host, const String& auth,
168168
}
169169

170170
// FirebasePush
171-
FirebaseRemove::FirebaseRemove(constString& host,constString& auth,
172-
constString& path,
171+
FirebaseRemove::FirebaseRemove(conststd::string& host,conststd::string& auth,
172+
conststd::string& path,
173173
FirebaseHttpClient* http)
174174
: FirebaseCall(host, auth,"DELETE", path,"", http) {
175175
}
176176

177177
// FirebaseStream
178-
FirebaseStream::FirebaseStream(constString& host,constString& auth,
179-
constString& path,
178+
FirebaseStream::FirebaseStream(conststd::string& host,conststd::string& auth,
179+
conststd::string& path,
180180
FirebaseHttpClient* http)
181181
: FirebaseCall(host, auth,"STREAM", path,"", http) {
182182
}
@@ -185,10 +185,10 @@ bool FirebaseStream::available() {
185185
return http_->getStreamPtr()->available();
186186
}
187187

188-
FirebaseStream::EventFirebaseStream::read(String& event) {
188+
FirebaseStream::EventFirebaseStream::read(std::string& event) {
189189
auto client = http_->getStreamPtr();
190190
Event type;
191-
String typeStr = client->readStringUntil('\n').substring(7);
191+
std::string typeStr = client->readStringUntil('\n').substring(7);
192192
if (typeStr =="put") {
193193
type = Event::PUT;
194194
}elseif (typeStr =="patch") {

‎src/Firebase.h

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,67 +37,67 @@ class FirebaseStream;
3737
// Firebase REST API client.
3838
classFirebase {
3939
public:
40-
Firebase(constString& host,constString& auth ="");
40+
Firebase(conststd::string& host,conststd::string& auth ="");
4141

42-
constString&auth()const;
42+
conststd::string&auth()const;
4343

4444
// Fetch json encoded `value` at `path`.
45-
FirebaseGetget(constString& path);
46-
virtual std::unique_ptr<FirebaseGet>getPtr(constString& path);
45+
FirebaseGetget(conststd::string& path);
46+
virtual std::unique_ptr<FirebaseGet>getPtr(conststd::string& path);
4747

4848
// Set json encoded `value` at `path`.
49-
FirebaseSetset(constString& path,constString& json);
50-
virtual std::unique_ptr<FirebaseSet>setPtr(constString& path,constString& json);
49+
FirebaseSetset(conststd::string& path,conststd::string& json);
50+
virtual std::unique_ptr<FirebaseSet>setPtr(conststd::string& path,conststd::string& json);
5151

5252
// Add new json encoded `value` to list at `path`.
53-
FirebasePushpush(constString& path,constString& json);
54-
virtual std::unique_ptr<FirebasePush>pushPtr(constString& path,constString& json);
53+
FirebasePushpush(conststd::string& path,conststd::string& json);
54+
virtual std::unique_ptr<FirebasePush>pushPtr(conststd::string& path,conststd::string& json);
5555

5656
// Delete value at `path`.
57-
FirebaseRemoveremove(constString& path);
58-
virtual std::unique_ptr<FirebaseRemove>removePtr(constString& path);
57+
FirebaseRemoveremove(conststd::string& path);
58+
virtual std::unique_ptr<FirebaseRemove>removePtr(conststd::string& path);
5959

6060
// Start a stream of events that affect value at `path`.
61-
FirebaseStreamstream(constString& path);
62-
virtual std::unique_ptr<FirebaseStream>streamPtr(constString& path);
61+
FirebaseStreamstream(conststd::string& path);
62+
virtual std::unique_ptr<FirebaseStream>streamPtr(conststd::string& path);
6363

6464
protected:
6565
// Used for testing.
6666
Firebase() {}
6767

6868
private:
6969
std::unique_ptr<FirebaseHttpClient> http_;
70-
String host_;
71-
String auth_;
70+
std::string host_;
71+
std::string auth_;
7272
};
7373

7474
classFirebaseError {
7575
public:
7676
FirebaseError() {}
77-
FirebaseError(int code,constString& message) : code_(code), message_(message) {
77+
FirebaseError(int code,conststd::string& message) : code_(code), message_(message) {
7878
}
7979
operatorbool()const {return code_ !=0; }
8080
intcode()const {return code_; }
81-
constString&message()const {return message_; }
81+
conststd::string&message()const {return message_; }
8282
private:
8383
int code_ =0;
84-
String message_ ="";
84+
std::string message_ ="";
8585
};
8686

8787
classFirebaseCall {
8888
public:
8989
FirebaseCall() {}
90-
FirebaseCall(constString& host,constString& auth,
91-
constchar* method,constString& path,
92-
constString& data ="",
90+
FirebaseCall(conststd::string& host,conststd::string& auth,
91+
constchar* method,conststd::string& path,
92+
conststd::string& data ="",
9393
FirebaseHttpClient* http =NULL);
9494
virtual~FirebaseCall() {}
9595

9696
virtualconst FirebaseError&error()const {
9797
return error_;
9898
}
9999

100-
virtualconstString&response()const {
100+
virtualconststd::string&response()const {
101101
return response_;
102102
}
103103

@@ -106,59 +106,59 @@ class FirebaseCall {
106106
protected:
107107
FirebaseHttpClient* http_;
108108
FirebaseError error_;
109-
String response_;
109+
std::string response_;
110110
DynamicJsonBuffer buffer_;
111111
};
112112

113113
classFirebaseGet :publicFirebaseCall {
114114
public:
115115
FirebaseGet() {}
116-
FirebaseGet(constString& host,constString& auth,
117-
constString& path, FirebaseHttpClient* http =NULL);
116+
FirebaseGet(conststd::string& host,conststd::string& auth,
117+
conststd::string& path, FirebaseHttpClient* http =NULL);
118118

119119
private:
120-
String json_;
120+
std::string json_;
121121
};
122122

123123
classFirebaseSet:publicFirebaseCall {
124124
public:
125125
FirebaseSet() {}
126-
FirebaseSet(constString& host,constString& auth,
127-
constString& path,constString& value, FirebaseHttpClient* http =NULL);
126+
FirebaseSet(conststd::string& host,conststd::string& auth,
127+
conststd::string& path,conststd::string& value, FirebaseHttpClient* http =NULL);
128128

129129

130130
private:
131-
String json_;
131+
std::string json_;
132132
};
133133

134134
classFirebasePush :publicFirebaseCall {
135135
public:
136136
FirebasePush() {}
137-
FirebasePush(constString& host,constString& auth,
138-
constString& path,constString& value, FirebaseHttpClient* http =NULL);
137+
FirebasePush(conststd::string& host,conststd::string& auth,
138+
conststd::string& path,conststd::string& value, FirebaseHttpClient* http =NULL);
139139
virtual~FirebasePush() {}
140140

141-
virtualconstString&name()const {
141+
virtualconststd::string&name()const {
142142
return name_;
143143
}
144144

145145
private:
146-
String name_;
146+
std::string name_;
147147
};
148148

149149
classFirebaseRemove :publicFirebaseCall {
150150
public:
151151
FirebaseRemove() {}
152-
FirebaseRemove(constString& host,constString& auth,
153-
constString& path, FirebaseHttpClient* http =NULL);
152+
FirebaseRemove(conststd::string& host,conststd::string& auth,
153+
conststd::string& path, FirebaseHttpClient* http =NULL);
154154
};
155155

156156

157157
classFirebaseStream :publicFirebaseCall {
158158
public:
159159
FirebaseStream() {}
160-
FirebaseStream(constString& host,constString& auth,
161-
constString& path, FirebaseHttpClient* http =NULL);
160+
FirebaseStream(conststd::string& host,conststd::string& auth,
161+
conststd::string& path, FirebaseHttpClient* http =NULL);
162162
virtual~FirebaseStream() {}
163163

164164
// Return if there is any event available to read.
@@ -171,7 +171,7 @@ class FirebaseStream : public FirebaseCall {
171171
PATCH
172172
};
173173

174-
staticinlineStringEventToName(Event event) {
174+
staticinlinestd::stringEventToName(Event event) {
175175
switch(event) {
176176
case UNKNOWN:
177177
return"UNKNOWN";
@@ -185,7 +185,7 @@ class FirebaseStream : public FirebaseCall {
185185
}
186186

187187
// Read next json encoded `event` from stream.
188-
virtual Eventread(String& event);
188+
virtual Eventread(std::string& event);
189189

190190
const FirebaseError&error()const {
191191
return _error;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp