AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzDataFile Class Reference

A XOML data file. More...

#include <CzFile.h>

Inheritance diagram for CzDataFile:
IzXomlResource

List of all members.

Public Types

enum  eDataFile_State { State_Invalid, State_Loaded }
enum  eDataFile_Converter { Converter_None, Converter_FromHTML, Converter_FromHex, Converter_FromURLEncoded }

Public Member Functions

eDataFile_State getState () const
CzStringgetFilename ()
CzDataInputgetDataInput ()
void setFileType (const char *type)
CzStringgetFileType ()
void setTargetVariable (const char *var)
CzXomlVariablegetTargetVariable ()
void setConverter (eDataFile_Converter method)
eDataFile_Converter getConverter () const
CzEventManagergetEventsManager ()
 CzDataFile ()
virtual ~CzDataFile ()
bool Init (const char *filename, bool preload, bool blocking)
 Initialises the XOML file holder.
bool Load (bool blocking=true)
 Loads the file specified by this XOML file holder.
int LoadFromXoml (IzXomlResource *parent, bool load_children, CzXmlNode *node)
 Creates an instance of this class from XOML.
virtual void ProcessEventActions (unsigned int event_name)
 Process the event actions described by event_name.
virtual void NotifyLoaded ()
 Handles the file loaded event.
virtual void NotifyError ()
 Handles the file error event.
void FinishLoad ()
 Called internally when the file has been downloaded and is available.

Protected Attributes

eDataFile_State State
 State of file.
CzString Filename
 Name of file.
CzString FileType
 Type of file (has not affect on how file is loaded)
CzXomlVariableTargetVariable
 The file will be loaded into this variable if it is set.
CzScriptTargetScript
 The file will be loaded into this script if it is set.
CzDataInputDataInput
 Input stream.
eDataFile_Converter Converter
 Conversion method used on input data.
CzEventManagerEventsManager
 List of events that the file handles.
CzFileFile

Detailed Description

A XOML data file.

CzDataFile is the XOML representation of a file (a file holder) and enables files to be created and loaded using the File XOML tag.

Its often useful to be able to load files into an app and do something with the data that they contain. Files in XOML are just like any other resource and can be declared inside a scene in which case they become local to the scene or declared outside a scene in which case they become global. They can also be loaded from local storage or from a web server, Files can also convert their data after loading from an number of different formats. We will begin by taking a look at the properties that are available for the Files tag:

  • Name (string) - Name of this file resource
  • Tag (string) - Resource tag (used to group resources together) (optional)
  • Location (filename) - Name of the file including extension (can include web addresses)
  • Preload (boolean) - If set to true then the file will be loaded immediately. By setting to false the file will be loaded when it is first used or can be loaded by an action later (default is true).
  • Blocking (boolean) - Web based files take time to download from the web so its useful to allow execution of the app to continue whilst it downloads. To prevent the file download from blocking the app set Blocking="false" (default is to block).
  • Condition (variable) - A condition variable that must evaluate to true for this resource to be loaded (this is an optional feature and can be used to conditionally load resources based on certain conditions such as screen size or device type etc..) (optional)
  • FileType (string) – Type of file (does not affect how the file is loaded) (optional)
  • Variable (variable) – Name of the variable that the contents of the file should be written into once loaded (optional)
  • Script (script) - Name of the script that the contents of the file should be written into once loaded. This is used only to load a script resource with script (optional)
  • Converter (type) – How to convert the loaded data to text (html, hex, urlencoded). This is useful if you have data in a common web format such as url-encoded. Passing urlencoded will cause the data to be converted from url-encoded to plain text format (optional)
  • OnLoaded (actions list) - Actions list to call when the file is loaded
  • OnError (actions list) - Actions list to call when an error occurs

The Files example has been provided to show how to load a file and reload its contents. Lets take a look at the XOML for this example:

<!-- Create a variable to load a file into -->
<Variable Name="FileContents" Type="string" />

<!-- Declare a file -->
<File Name="File1" Location="file1.txt" FileType="txt" Variable="FileContents"
Preload="true" />

<!-- Create a scene -->
<Scene Name="Scene1" Current="true" >

    <!-- Create a label to display our files contents -->
    <Label Font="serif" Size="200, 200" TextColour="255, 255, 128, 255"
    Background="Button1Brush" BackgroundColour="255, 80, 80, 255"
    Binding="[Text]FileContents" />

    <!-- Create a group of buttons to load 3 different files -->
    <Label Font="serif" Size="80, 50" Position="-100, 100" Text="Load File1"
    Background="Button1Brush" BackgroundColour="80, 80, 255, 255" OnTapped="Load">
        <Actions Name="Load">
            <Action Method="LoadFile" Param1="File1" Param2="true" Param3="file1.txt" />
        </Actions>
    </Label>
    <Label Font="serif" Size="80, 50" Position="0, 100" Text="Load File2"
    Background="Button1Brush" BackgroundColour="80, 80, 255, 255" OnTapped="Load">
        <Actions Name="Load">
            <Action Method="LoadFile" Param1="File1" Param2="true" Param3="file2.txt" />
        </Actions>
    </Label>
    <Label Font="serif" Size="80, 50" Position="100, 100" Text="Load File3"
    Background="Button1Brush" BackgroundColour="80, 80, 255, 255" OnTapped="Load">
        <Actions Name="Load">
            <Action Method="LoadFile" Param1="File1" Param2="true" Param3="file3.txt" />
        </Actions>
    </Label>

</Scene>

We begin this example by creating a variable called FileContents that we will later load our files contents into. Next we create a File that loads the contents of file1.txt and writes it to the FileContents variable. Next we create a label that will sho the files contents due to the binding to the FileContents variable. Lastly we create 3 label buttons that each call the LoadFile action when tapped. Each of the LoadFile actions load different files into the FileContents variable.


Member Enumeration Documentation

Enumerator:
Converter_None 
Converter_FromHTML 
Converter_FromHex 
Converter_FromURLEncoded 
Enumerator:
State_Invalid 
State_Loaded 

Constructor & Destructor Documentation

CzDataFile::CzDataFile ( ) [inline]
CzDataFile::~CzDataFile ( ) [virtual]

Member Function Documentation

Called internally when the file has been downloaded and is available.

bool CzDataFile::Init ( const char *  filename,
bool  preload,
bool  blocking 
)

Initialises the XOML file holder.

Parameters:
filenameFilename of the file.
preloadtrue to preload.
blockingtrue to use blocking.
Returns:
true if it succeeds, false if it fails.
bool CzDataFile::Load ( bool  blocking = true)

Loads the file specified by this XOML file holder.

Parameters:
blockingtrue if file load should block main thread.
Returns:
true if it succeeds, false if it fails.
int CzDataFile::LoadFromXoml ( IzXomlResource parent,
bool  load_children,
CzXmlNode node 
) [virtual]

Creates an instance of this class from XOML.

LoadFromXoml is the main method used by all classes that can be instantiated from XOML mark-up. This method creates an instance of this class from the supplied XML node structure specified by node. if parent is not NULL then the created instance will utilise the supplied parent to determine where it should live within the app. For example, if the parent is a scene then the file will be placed in that scene. if the parent is the app then the file will be available globally to all scenes. nodes contained within the actor will also be loaded.

Parameters:
[in]parentIf non-null, the parent.
load_childrentrue to load child nodes.
[in]nodeIf non-null, the XOML markup node that defines this object
Returns:
nergative value for error. if 0 then processing of further XOML will stop.

Implements IzXomlResource.

void CzDataFile::NotifyError ( ) [virtual]

Handles the file error event.

void CzDataFile::NotifyLoaded ( ) [virtual]

Handles the file loaded event.

void CzDataFile::ProcessEventActions ( unsigned int  event_name) [virtual]

Process the event actions described by event_name.

Processes the actions list that is associated with the event named event_name (event_name is a hash of the actual event name to speed up searches)

Parameters:
event_nameName of the event as a string hash
void CzDataFile::setConverter ( eDataFile_Converter  method) [inline]
void CzDataFile::setFileType ( const char *  type) [inline]
void CzDataFile::setTargetVariable ( const char *  var)

Member Data Documentation

Conversion method used on input data.

Input stream.

List of events that the file handles.

CzFile* CzDataFile::File [protected]

Name of file.

Type of file (has not affect on how file is loaded)

State of file.

The file will be loaded into this script if it is set.

The file will be loaded into this variable if it is set.


The documentation for this class was generated from the following files: