Wexus2 0.20
wexus::ActiveFile Class Reference

#include <ActiveFile.h>

Inheritance diagram for wexus::ActiveFile:

List of all members.

Classes

struct  DataSpec
struct  DirSpec
struct  IteratorSpec

Public Member Functions

 ActiveFile (const QString &dirname, const QRegExp &regexp)
 just the filename, no directory
virtual QVariant getIDAsVariant (void)
 implementation
void checkFileName (const QString &filename)
void checkFileName (void)
void find (const QVariant &keyVal)
bool exists (const QVariant &keyVal)
QByteArray & asByteArray (void)
void all (bool reverseOrder=false)
bool next (void)

Public Attributes

QString id

Protected Member Functions

virtual bool onLoad (const QString &fullfilename)

Protected Attributes

std::shared_ptr< DirSpecdm_dirspec
std::shared_ptr< DataSpecdm_data
std::shared_ptr< IteratorSpecdm_iterator

Detailed Description

A database-record like representation of a file. Instead of a table, it uses a directory (plus a filtering regexp). Instead of record, it uses an individual file.

This concept is still being fleshed out. Future ideas include:

a) filename->field like decomposition based on regexp (with custom user-made field lists)

b) a query system for a)

c) more file load types, like images and xml.

d) rename this to ActiveFile?

Author:
Aleksander Demko

Constructor & Destructor Documentation

wexus::ActiveFile::ActiveFile ( const QString &  dirname,
const QRegExp &  regexp 
)

just the filename, no directory

Constructor

Author:
Aleksander Demko

Member Function Documentation

void wexus::ActiveFile::all ( bool  reverseOrder = false)

Returns all the records.

Author:
Aleksander Demko
QByteArray& wexus::ActiveFile::asByteArray ( void  )

Demand load the curren file. Throws on errors.

Author:
Aleksander Demko
void wexus::ActiveFile::checkFileName ( void  ) [inline]

Runs checkFileName on id

Author:
Aleksander Demko
void wexus::ActiveFile::checkFileName ( const QString &  filename)

Security routine. throws if the filename:

  • is empty
  • contains bad chars, like / or \
  • starts with a .
  • doesnt pass the reg ex
Author:
Aleksander Demko
bool wexus::ActiveFile::exists ( const QVariant &  keyVal)

Same as find(), except returns false on failure. find() raises an exception.

Author:
Aleksander Demko
void wexus::ActiveFile::find ( const QVariant &  keyVal)

Finds the record that that has the given value as its primary key. Throws an exception on not-found.

Author:
Aleksander Demko
bool wexus::ActiveFile::next ( void  )

Returns the next record in file list, or false if done.

Author:
Aleksander Demko
virtual bool wexus::ActiveFile::onLoad ( const QString &  fullfilename) [protected, virtual]

This is called after loading a record. id (the filename) is already set up entering this function. You can also examine the full filename parameter.

Decendants should be able to work with empty-string ids and can throw exceptions on errors.

TODO in the future, this might be implemented in a more automatic/regex manner using .eh-like files.

The default implementation does nothing but return true;

Returns:
true on success (false causes this record to not be loaded)
Author:
Aleksander Demko

Reimplemented in blogapp::Post.


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Enumerations Enumerator