Commit 87ab5a94 authored by Ronan's avatar Ronan

feat(src): use now a LINPHONE_{BEGIN,END}_NAMESPACE macro

parent 8891799e
......@@ -21,11 +21,11 @@
#include "cpim-core-headers.h"
// =============================================================================
using namespace std;
using namespace LinphonePrivate;
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
Cpim::CoreHeader::CoreHeader () : Header(*new HeaderPrivate) {}
......@@ -56,7 +56,7 @@ MAKE_CORE_HEADER_IMPL(Require);
// -----------------------------------------------------------------------------
void Cpim::CoreHeader::force (const std::string &value) {
void Cpim::CoreHeader::force (const string &value) {
Header::setValue(value);
}
......@@ -103,3 +103,5 @@ void Cpim::SubjectHeader::force (const string &value, const string &language) {
CoreHeader::force(value);
d->language = language;
}
LINPHONE_END_NAMESPACE
......@@ -23,6 +23,8 @@
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
#define MAKE_CORE_HEADER(CLASS_PREFIX, NAME) \
class LINPHONE_PUBLIC CLASS_PREFIX ## Header : public CoreHeader { \
public: \
......@@ -35,77 +37,77 @@
L_DISABLE_COPY(CLASS_PREFIX ## Header); \
};
namespace LinphonePrivate {
namespace Cpim {
class HeaderNode;
namespace Cpim {
class HeaderNode;
// -------------------------------------------------------------------------
// Generic core header.
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Generic core header.
// -------------------------------------------------------------------------
class LINPHONE_PUBLIC CoreHeader : public Header {
friend class HeaderNode;
class LINPHONE_PUBLIC CoreHeader : public Header {
friend class HeaderNode;
public:
CoreHeader ();
public:
CoreHeader ();
virtual ~CoreHeader () = 0;
virtual ~CoreHeader () = 0;
bool isValid () const override;
bool isValid () const override;
protected:
explicit CoreHeader (HeaderPrivate &p);
protected:
explicit CoreHeader (HeaderPrivate &p);
void force (const std::string &value);
void force (const std::string &value);
private:
L_DISABLE_COPY(CoreHeader);
};
private:
L_DISABLE_COPY(CoreHeader);
};
// -------------------------------------------------------------------------
// Core headers.
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Core headers.
// -------------------------------------------------------------------------
MAKE_CORE_HEADER(From, "From");
MAKE_CORE_HEADER(To, "To");
MAKE_CORE_HEADER(Cc, "cc");
MAKE_CORE_HEADER(DateTime, "DateTime");
MAKE_CORE_HEADER(Ns, "NS");
MAKE_CORE_HEADER(Require, "Require");
MAKE_CORE_HEADER(From, "From");
MAKE_CORE_HEADER(To, "To");
MAKE_CORE_HEADER(Cc, "cc");
MAKE_CORE_HEADER(DateTime, "DateTime");
MAKE_CORE_HEADER(Ns, "NS");
MAKE_CORE_HEADER(Require, "Require");
// -------------------------------------------------------------------------
// Specific Subject declaration.
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Specific Subject declaration.
// -------------------------------------------------------------------------
class SubjectHeaderPrivate;
class SubjectHeaderPrivate;
class LINPHONE_PUBLIC SubjectHeader : public CoreHeader {
friend class HeaderNode;
class LINPHONE_PUBLIC SubjectHeader : public CoreHeader {
friend class HeaderNode;
public:
SubjectHeader ();
public:
SubjectHeader ();
inline std::string getName () const override {
return "Subject";
}
inline std::string getName () const override {
return "Subject";
}
bool setValue (const std::string &value) override;
bool setValue (const std::string &value) override;
std::string getLanguage () const;
bool setLanguage (const std::string &language);
std::string getLanguage () const;
bool setLanguage (const std::string &language);
std::string asString () const override;
std::string asString () const override;
protected:
void force (const std::string &value, const std::string &language);
protected:
void force (const std::string &value, const std::string &language);
private:
L_DECLARE_PRIVATE(SubjectHeader);
L_DISABLE_COPY(SubjectHeader);
};
}
private:
L_DECLARE_PRIVATE(SubjectHeader);
L_DISABLE_COPY(SubjectHeader);
};
}
#undef MAKE_CORE_HEADER
LINPHONE_END_NAMESPACE
#endif // ifndef _CPIM_CORE_HEADERS_H_
......@@ -24,11 +24,11 @@
#include "cpim-generic-header.h"
// =============================================================================
using namespace std;
using namespace LinphonePrivate;
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class Cpim::GenericHeaderPrivate : public HeaderPrivate {
public:
......@@ -117,3 +117,5 @@ void Cpim::GenericHeader::force (const string &name, const string &value, const
d->parameters->push_back(make_pair(parameter.substr(0, equalIndex), parameter.substr(equalIndex + 1)));
}
}
LINPHONE_END_NAMESPACE
......@@ -26,40 +26,42 @@
// =============================================================================
namespace LinphonePrivate {
namespace Cpim {
class GenericHeaderPrivate;
class HeaderNode;
LINPHONE_BEGIN_NAMESPACE
class LINPHONE_PUBLIC GenericHeader : public Header {
friend class HeaderNode;
namespace Cpim {
class GenericHeaderPrivate;
class HeaderNode;
public:
GenericHeader ();
class LINPHONE_PUBLIC GenericHeader : public Header {
friend class HeaderNode;
std::string getName () const override;
bool setName (const std::string &name);
public:
GenericHeader ();
bool setValue (const std::string &value) override;
std::string getName () const override;
bool setName (const std::string &name);
typedef std::shared_ptr<const std::list<std::pair<std::string, std::string> > > ParameterList;
bool setValue (const std::string &value) override;
ParameterList getParameters () const;
bool addParameter (const std::string &key, const std::string &value);
void removeParameter (const std::string &key, const std::string &value);
typedef std::shared_ptr<const std::list<std::pair<std::string, std::string> > > ParameterList;
bool isValid () const override;
ParameterList getParameters () const;
bool addParameter (const std::string &key, const std::string &value);
void removeParameter (const std::string &key, const std::string &value);
std::string asString () const override;
bool isValid () const override;
protected:
void force (const std::string &name, const std::string &value, const std::string &parameters);
std::string asString () const override;
private:
L_DECLARE_PRIVATE(GenericHeader);
L_DISABLE_COPY(GenericHeader);
};
}
protected:
void force (const std::string &name, const std::string &value, const std::string &parameters);
private:
L_DECLARE_PRIVATE(GenericHeader);
L_DISABLE_COPY(GenericHeader);
};
}
LINPHONE_END_NAMESPACE
#endif // ifndef _CPIM_GENERIC_HEADER_H_
......@@ -24,18 +24,20 @@
// =============================================================================
namespace LinphonePrivate {
namespace Cpim {
class HeaderPrivate : public ObjectPrivate {
public:
virtual ~HeaderPrivate () = default;
private:
std::string value;
L_DECLARE_PUBLIC(Header);
};
}
LINPHONE_BEGIN_NAMESPACE
namespace Cpim {
class HeaderPrivate : public ObjectPrivate {
public:
virtual ~HeaderPrivate () = default;
private:
std::string value;
L_DECLARE_PUBLIC(Header);
};
}
LINPHONE_END_NAMESPACE
#endif // ifndef _CPIM_HEADER_P_H_
......@@ -20,11 +20,11 @@
#include "cpim-header.h"
// =============================================================================
using namespace std;
using namespace LinphonePrivate;
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
Cpim::Header::Header (HeaderPrivate &p) : Object(p) {}
......@@ -43,3 +43,5 @@ string Cpim::Header::asString () const {
L_D(const Header);
return getName() + ": " + d->value + "\r\n";
}
LINPHONE_END_NAMESPACE
......@@ -25,31 +25,33 @@
// =============================================================================
namespace LinphonePrivate {
namespace Cpim {
class HeaderPrivate;
LINPHONE_BEGIN_NAMESPACE
class LINPHONE_PUBLIC Header : public Object {
public:
virtual ~Header () = default;
namespace Cpim {
class HeaderPrivate;
virtual std::string getName () const = 0;
class LINPHONE_PUBLIC Header : public Object {
public:
virtual ~Header () = default;
std::string getValue () const;
virtual bool setValue (const std::string &value);
virtual std::string getName () const = 0;
virtual bool isValid () const = 0;
std::string getValue () const;
virtual bool setValue (const std::string &value);
virtual std::string asString () const;
virtual bool isValid () const = 0;
protected:
explicit Header (HeaderPrivate &p);
virtual std::string asString () const;
private:
L_DECLARE_PRIVATE(Header);
L_DISABLE_COPY(Header);
};
}
protected:
explicit Header (HeaderPrivate &p);
private:
L_DECLARE_PRIVATE(Header);
L_DISABLE_COPY(Header);
};
}
LINPHONE_END_NAMESPACE
#endif // ifndef _CPIM_HEADER_H_
......@@ -24,11 +24,11 @@
#include "cpim-message.h"
// =============================================================================
using namespace std;
using namespace LinphonePrivate;
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class Cpim::MessagePrivate : public ObjectPrivate {
public:
......@@ -139,3 +139,5 @@ string Cpim::Message::asString () const {
shared_ptr<const Cpim::Message> Cpim::Message::createFromString (const string &str) {
return Parser::getInstance()->parseMessage(str);
}
LINPHONE_END_NAMESPACE
......@@ -24,38 +24,40 @@
// =============================================================================
namespace LinphonePrivate {
namespace Cpim {
class MessagePrivate;
LINPHONE_BEGIN_NAMESPACE
class LINPHONE_PUBLIC Message : public Object {
public:
Message ();
namespace Cpim {
class MessagePrivate;
typedef std::shared_ptr<std::list<std::shared_ptr<const Cpim::Header> > > HeaderList;
class LINPHONE_PUBLIC Message : public Object {
public:
Message ();
HeaderList getCpimHeaders () const;
bool addCpimHeader (const Header &cpimHeader);
void removeCpimHeader (const Header &cpimHeader);
typedef std::shared_ptr<std::list<std::shared_ptr<const Cpim::Header> > > HeaderList;
HeaderList getMessageHeaders () const;
bool addMessageHeader (const Header &messageHeader);
void removeMessageHeader (const Header &messageHeader);
HeaderList getCpimHeaders () const;
bool addCpimHeader (const Header &cpimHeader);
void removeCpimHeader (const Header &cpimHeader);
std::string getContent () const;
bool setContent (const std::string &content);
HeaderList getMessageHeaders () const;
bool addMessageHeader (const Header &messageHeader);
void removeMessageHeader (const Header &messageHeader);
bool isValid () const;
std::string getContent () const;
bool setContent (const std::string &content);
std::string asString () const;
bool isValid () const;
static std::shared_ptr<const Message> createFromString (const std::string &str);
std::string asString () const;
private:
L_DECLARE_PRIVATE(Message);
L_DISABLE_COPY(Message);
};
}
static std::shared_ptr<const Message> createFromString (const std::string &str);
private:
L_DECLARE_PRIVATE(Message);
L_DISABLE_COPY(Message);
};
}
LINPHONE_END_NAMESPACE
#endif // ifndef _CPIM_MESSAGE_H_
......@@ -20,8 +20,9 @@
// =============================================================================
namespace LinphonePrivate {
static const char *grammar =
LINPHONE_BEGIN_NAMESPACE
static const char *grammar =
// See: https://tools.ietf.org/html/rfc3862
R"==GRAMMAR==(
Message = Headers CRLF Headers CRLF
......@@ -200,8 +201,9 @@ full-time = partial-time time-offset
date-time = full-date "T" full-time
)==GRAMMAR==";
}
const char *LinphonePrivate::Cpim::getGrammar () {
const char *Cpim::getGrammar () {
return grammar;
}
LINPHONE_END_NAMESPACE
......@@ -19,12 +19,16 @@
#ifndef _CPIM_GRAMMAR_H_
#define _CPIM_GRAMMAR_H_
#include "utils/general.h"
// =============================================================================
namespace LinphonePrivate {
namespace Cpim {
const char *getGrammar ();
}
LINPHONE_BEGIN_NAMESPACE
namespace Cpim {
const char *getGrammar ();
}
LINPHONE_END_NAMESPACE
#endif // ifndef _CPIM_GRAMMAR_H_
This diff is collapsed.
......@@ -24,59 +24,61 @@
// =============================================================================
namespace LinphonePrivate {
namespace Cpim {
class ParserPrivate;
LINPHONE_BEGIN_NAMESPACE
class Parser : public Singleton<Parser> {
friend class Singleton<Parser>;
namespace Cpim {
class ParserPrivate;
public:
std::shared_ptr<Message> parseMessage (const std::string &input);
class Parser : public Singleton<Parser> {
friend class Singleton<Parser>;
std::shared_ptr<Header> cloneHeader (const Header &header);
public:
std::shared_ptr<Message> parseMessage (const std::string &input);
bool headerNameIsValid (const std::string &headerName) const;
bool headerValueIsValid (const std::string &headerValue) const;
bool headerParameterIsValid (const std::string &headerParameter) const;
std::shared_ptr<Header> cloneHeader (const Header &header);
template<typename>
bool coreHeaderIsValid (const std::string &headerValue) const {
return false;
}
bool headerNameIsValid (const std::string &headerName) const;
bool headerValueIsValid (const std::string &headerValue) const;
bool headerParameterIsValid (const std::string &headerParameter) const;
bool subjectHeaderLanguageIsValid (const std::string &language) const;
template<typename>
bool coreHeaderIsValid (const std::string &headerValue) const {
return false;
}
private:
Parser ();
bool subjectHeaderLanguageIsValid (const std::string &language) const;
L_DECLARE_PRIVATE(Parser);
L_DISABLE_COPY(Parser);
};
private:
Parser ();
// -------------------------------------------------------------------------
L_DECLARE_PRIVATE(Parser);
L_DISABLE_COPY(Parser);
};
template<>
bool Parser::coreHeaderIsValid<FromHeader>(const std::string &headerValue) const;
// ---------------------------------------------------------------------------
template<>
bool Parser::coreHeaderIsValid<ToHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<FromHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<CcHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<ToHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<DateTimeHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<CcHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<SubjectHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<DateTimeHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<NsHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<SubjectHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<RequireHeader>(const std::string &headerValue) const;
}
template<>
bool Parser::coreHeaderIsValid<NsHeader>(const std::string &headerValue) const;
template<>
bool Parser::coreHeaderIsValid<RequireHeader>(const std::string &headerValue) const;
}
LINPHONE_END_NAMESPACE
#endif // ifndef _CPIM_PARSER_H_
......@@ -22,19 +22,17 @@
#include "logger.h"
using namespace std;
// =============================================================================
using namespace LinphonePrivate;
using namespace std;
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
namespace LinphonePrivate {
class LoggerPrivate : public ObjectPrivate {
public:
Logger::Level level;
ostringstream os;
};
}
class LoggerPrivate : public ObjectPrivate {
public:
Logger::Level level;
ostringstream os;
};
// -----------------------------------------------------------------------------
......@@ -72,3 +70,5 @@ ostringstream &Logger::getOutput () {
L_D(Logger);
return d->os;
}
LINPHONE_END_NAMESPACE
......@@ -25,34 +25,36 @@
// =============================================================================
namespace LinphonePrivate {
class LoggerPrivate;
class LINPHONE_PUBLIC Logger : public Object {
public:
enum Level {
Debug,
Info,
Warning,
Error,
Fatal
};
Logger (Level level);
~Logger ();
std::ostringstream &getOutput ();
private:
L_DECLARE_PRIVATE(Logger);
L_DISABLE_COPY(Logger);
LINPHONE_BEGIN_NAMESPACE
class LoggerPrivate;
class LINPHONE_PUBLIC Logger : public Object {
public:
enum Level {
Debug,
Info,
Warning,
Error,
Fatal
};
}
#define lDebug() LinphonePrivate::Logger(Logger::Debug).getOutput()
#define lInfo() LinphonePrivate::Logger(Logger::Info).getOutput()
#define lWarning() LinphonePrivate::Logger(Logger::Warning).getOutput()
#define lError() LinphonePrivate::Logger(Logger::Error).getOutput()
#define lFatal() LinphonePrivate::Logger(Logger::Fatal).getOutput()
Logger (Level level);
~Logger ();
std::ostringstream &getOutput ();
private:
L_DECLARE_PRIVATE(Logger);
L_DISABLE_COPY(Logger);
};
LINPHONE_END_NAMESPACE
#define lDebug() LINPHONE_NAMESPACE::Logger(Logger::Debug).getOutput()
#define lInfo() LINPHONE_NAMESPACE::Logger(Logger::Info).getOutput()
#define lWarning() LINPHONE_NAMESPACE::Logger(Logger::Warning).getOutput()
#define lError() LINPHONE_NAMESPACE::Logger(Logger::Error).getOutput()
#define lFatal() LINPHONE_NAMESPACE::Logger(Logger::Fatal).getOutput()
#endif // ifndef _LOGGER_H_
......@@ -23,19 +23,21 @@
// =============================================================================
namespace LinphonePrivate {
class Object;
LINPHONE_BEGIN_NAMESPACE
class ObjectPrivate {
public:
virtual ~ObjectPrivate () = default;
class Object;
protected:
Object *mPublic = nullptr;
class ObjectPrivate {
public:
virtual ~ObjectPrivate () = default;
private:
L_DECLARE_PUBLIC(Object);
};
}
protected:
Object *mPublic = nullptr;
private:
L_DECLARE_PUBLIC(Object);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _OBJECT_P_H_
......@@ -20,10 +20,10 @@
#include "object.h"