Skip to content

Commit 593c272

Browse files
committed
Fix templates for g++ on Unix
1 parent 9720e5a commit 593c272

File tree

2 files changed

+195
-223
lines changed

2 files changed

+195
-223
lines changed

GraphQLResponse.cpp

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,195 @@ const Value& Value::operator[](size_t index) const
275275
return _list->at(index);
276276
}
277277

278+
template <>
279+
void Value::set<Value::StringType>(StringType&& value)
280+
{
281+
if (_type != Type::String
282+
&& _type != Type::EnumValue)
283+
{
284+
throw std::logic_error("Invalid call to Value::set for StringType");
285+
}
286+
287+
*_string = std::move(value);
288+
}
289+
290+
template <>
291+
void Value::set<Value::BooleanType>(BooleanType&& value)
292+
{
293+
if (_type != Type::Boolean)
294+
{
295+
throw std::logic_error("Invalid call to Value::set for BooleanType");
296+
}
297+
298+
_boolean = value;
299+
}
300+
301+
template <>
302+
void Value::set<Value::IntType>(IntType&& value)
303+
{
304+
if (_type != Type::Int)
305+
{
306+
throw std::logic_error("Invalid call to Value::set for IntType");
307+
}
308+
309+
_int = value;
310+
}
311+
312+
template <>
313+
void Value::set<Value::FloatType>(FloatType&& value)
314+
{
315+
if (_type != Type::Float)
316+
{
317+
throw std::logic_error("Invalid call to Value::set for FloatType");
318+
}
319+
320+
_float = value;
321+
}
322+
323+
template <>
324+
void Value::set<Value::ScalarType>(ScalarType&& value)
325+
{
326+
if (_type != Type::Scalar)
327+
{
328+
throw std::logic_error("Invalid call to Value::set for ScalarType");
329+
}
330+
331+
*_scalar = std::move(value);
332+
}
333+
334+
template <>
335+
const Value::MapType& Value::get<const Value::MapType&>() const
336+
{
337+
if (_type != Type::Map)
338+
{
339+
throw std::logic_error("Invalid call to Value::get for MapType");
340+
}
341+
342+
return *_map;
343+
}
344+
345+
template <>
346+
const Value::ListType& Value::get<const Value::ListType&>() const
347+
{
348+
if (_type != Type::List)
349+
{
350+
throw std::logic_error("Invalid call to Value::get for ListType");
351+
}
352+
353+
return *_list;
354+
}
355+
356+
template <>
357+
const Value::StringType& Value::get<const Value::StringType&>() const
358+
{
359+
if (_type != Type::String
360+
&& _type != Type::EnumValue)
361+
{
362+
throw std::logic_error("Invalid call to Value::get for StringType");
363+
}
364+
365+
return *_string;
366+
}
367+
368+
template <>
369+
Value::BooleanType Value::get<Value::BooleanType>() const
370+
{
371+
if (_type != Type::Boolean)
372+
{
373+
throw std::logic_error("Invalid call to Value::get for BooleanType");
374+
}
375+
376+
return _boolean;
377+
}
378+
379+
template <>
380+
Value::IntType Value::get<Value::IntType>() const
381+
{
382+
if (_type != Type::Int)
383+
{
384+
throw std::logic_error("Invalid call to Value::get for IntType");
385+
}
386+
387+
return _int;
388+
}
389+
390+
template <>
391+
Value::FloatType Value::get<Value::FloatType>() const
392+
{
393+
if (_type != Type::Float)
394+
{
395+
throw std::logic_error("Invalid call to Value::get for FloatType");
396+
}
397+
398+
return _float;
399+
}
400+
401+
template <>
402+
const Value::ScalarType& Value::get<const Value::ScalarType&>() const
403+
{
404+
if (_type != Type::Scalar)
405+
{
406+
throw std::logic_error("Invalid call to Value::get for ScalarType");
407+
}
408+
409+
return *_scalar;
410+
}
411+
412+
template <>
413+
Value::MapType Value::release<Value::MapType>()
414+
{
415+
if (_type != Type::Map)
416+
{
417+
throw std::logic_error("Invalid call to Value::release for MapType");
418+
}
419+
420+
MapType result = std::move(*_map);
421+
422+
_members->clear();
423+
424+
return result;
425+
}
426+
427+
template <>
428+
Value::ListType Value::release<Value::ListType>()
429+
{
430+
if (_type != Type::List)
431+
{
432+
throw std::logic_error("Invalid call to Value::release for ListType");
433+
}
434+
435+
ListType result = std::move(*_list);
436+
437+
return result;
438+
}
439+
440+
template <>
441+
Value::StringType Value::release<Value::StringType>()
442+
{
443+
if (_type != Type::String
444+
&& _type != Type::EnumValue)
445+
{
446+
throw std::logic_error("Invalid call to Value::release for StringType");
447+
}
448+
449+
StringType result = std::move(*_string);
450+
451+
return result;
452+
}
453+
454+
template <>
455+
Value::ScalarType Value::release<Value::ScalarType>()
456+
{
457+
if (_type != Type::Scalar)
458+
{
459+
throw std::logic_error("Invalid call to Value::release for ScalarType");
460+
}
461+
462+
ScalarType result = std::move(*_scalar);
463+
464+
return result;
465+
}
466+
278467
} /* namespace response */
279468
} /* namespace graphql */
280469
} /* namespace facebook */

0 commit comments

Comments
 (0)