Added operator overloads to return_entity and return_entity_vector

This commit is contained in:
tastytea 2019-03-02 20:21:31 +01:00
parent e1b32d13c8
commit 5fa7887fb1
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 28 additions and 0 deletions

View File

@ -36,6 +36,22 @@ return_entity::return_entity(const uint8_t ec, const string &em,
error_message = em;
}
return_entity::operator const Easy::GenericEntity() const
{
return entity;
}
return_entity::operator const string() const
{
return entity.to_string();
}
std::ostream &operator <<(std::ostream &out, const return_entity &ret)
{
out << ret.entity.to_string();
return out;
}
return_entity_vector::return_entity_vector()
: entities()
{}
@ -48,6 +64,11 @@ return_entity_vector::return_entity_vector(const uint8_t ec, const string &em,
error_message = em;
}
return_entity_vector::operator const vector<Easy::GenericEntity>() const
{
return entities;
}
Easy::Easy(const string &instance, const string &access_token)
: API(instance, access_token)
{}

View File

@ -23,6 +23,7 @@
#include <vector>
#include <utility>
#include <functional>
#include <ostream>
#include <jsoncpp/json/json.h>
// If we are compiling mastodon-cpp, use another include path
@ -548,6 +549,10 @@ typedef struct return_entity : return_base
return_entity();
return_entity(const uint8_t ec, const string &em,
const Easy::GenericEntity &ent);
operator const Easy::GenericEntity() const;
operator const string() const;
friend std::ostream &operator <<(std::ostream &out, const return_entity &ret);
} return_entity;
/*!
@ -561,6 +566,8 @@ typedef struct return_entity_vector : return_base
return_entity_vector();
return_entity_vector(const uint8_t ec, const string &em,
const vector<Easy::GenericEntity> &vec);
operator const vector<Easy::GenericEntity>() const;
} return_entity_vector;
}