Skip to content

Commit

Permalink
Uri: Added Uri::fromNativePath()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 13, 2012
1 parent 163a950 commit 1363019
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
9 changes: 8 additions & 1 deletion doomsday/engine/api/uri.h
Expand Up @@ -68,6 +68,7 @@

#include <de/Error>
#include <de/Log>
#include <de/NativePath>
#include <de/String>

namespace de
Expand Down Expand Up @@ -165,10 +166,16 @@ namespace de

bool operator != (Uri const& other) const;

/**
* Constructs a Uri instance from a NativePath. The resultant Uri will have
* an empty/zero-length scheme (because file paths do not include one).
*/
static Uri fromNativePath(NativePath const& path);

/**
* Constructs a Uri instance by reading it from @a reader.
*/
static Uri* fromReader(reader_s& reader);
static Uri fromReader(reader_s& reader);

/**
* Convert this URI to a text string.
Expand Down
22 changes: 11 additions & 11 deletions doomsday/engine/src/uri.cpp
Expand Up @@ -23,17 +23,14 @@
* 02110-1301 USA</small>
*/

#include <QDebug>
#include <QDir>

#include "de_base.h"
#include "game.h"
#include "resourcenamespace.h"
#include "sys_reslocator.h"

#include <QDebug>

#include <de/Error>
#include <de/Log>
#include <de/NativePath>
#include <de/String>
#include <de/unittest.h>

#include "uri.h"
Expand Down Expand Up @@ -421,11 +418,14 @@ Uri::Uri(Uri const& other) : LogEntry::Arg::Base()
Str_Copy(&d->path, other.path());
}

Uri* Uri::fromReader(struct reader_s& reader)
Uri Uri::fromNativePath(NativePath const& path)
{
return Uri(QDir::fromNativeSeparators(path), RC_NULL);
}

Uri Uri::fromReader(struct reader_s& reader)
{
Uri* uri = new Uri();
uri->read(reader);
return uri;
return Uri().read(reader);
}

Uri::~Uri()
Expand Down Expand Up @@ -808,7 +808,7 @@ Uri* Uri_Dup(Uri const* other)
Uri* Uri_FromReader(struct reader_s* reader)
{
DENG_ASSERT(reader);
return reinterpret_cast<Uri*>( de::Uri::fromReader(*reader) );
return reinterpret_cast<Uri*>( new de::Uri(de::Uri::fromReader(*reader)) );
}

void Uri_Delete(Uri* uri)
Expand Down

0 comments on commit 1363019

Please sign in to comment.