@@ -170,7 +170,8 @@ void json::object::erase(const std::string key) {
170170 this ->_map .erase (key);
171171 return ;
172172}
173- std::map<std::string, json::object>::iterator json::object::find (const std::string key){
173+ std::map<std::string, json::object>::iterator
174+ json::object::find (const std::string key) {
174175 this ->assertIsMap ();
175176 return this ->_map .find (key);
176177}
@@ -350,4 +351,44 @@ std::ostream &operator<<(std::ostream &os, object &obj) {
350351 return os;
351352}
352353
354+ object::operator std::nullptr_t () const {
355+ if (this ->_type .get () != type::null) {
356+ logger::error (" This object is not a null" ,
357+ " json::object::operator std::nullptr_t()" );
358+ }
359+
360+ return nullptr ;
361+ }
362+ // object::operator bool() const {
363+ // if (this->_type.get() != type::boolean) {
364+ // logger::error("This object is not a boolean",
365+ // "json::object::operator bool()");
366+ // }
367+
368+ // return std::get<bool>(this->_value);
369+ // }
370+ object::operator double () const {
371+ std::cout << this ->_type .get () << std::endl;
372+ if (this ->_type .get () != type::number && this ->_type .get () != type::integer &&
373+ this ->_type .get () != type::boolean) {
374+ logger::error (" This object is not a number" ,
375+ " json::object::operator double()" );
376+ }
377+
378+ if (this ->_type .get () == type::integer)
379+ return static_cast <double >(std::get<long long int >(this ->_value ));
380+ else if (this ->_type .get () == type::boolean)
381+ return static_cast <double >(std::get<bool >(this ->_value ));
382+ else
383+ return std::get<double >(this ->_value );
384+ }
385+ object::operator std::string () const {
386+ if (this ->_type .get () != type::string) {
387+ logger::error (" This object is not a string" ,
388+ " json::object::operator std::string()" );
389+ }
390+
391+ return std::get<std::string>(this ->_value );
392+ }
393+
353394} // namespace json
0 commit comments