Add FullSkeleton example

This commit is contained in:
flithm 2007-08-29 11:24:39 +00:00
commit c315c3f0d3
75 changed files with 4452 additions and 0 deletions

View file

@ -0,0 +1,70 @@
#################################
# Project
##############
project(libraryA D)
#################################
# Dependencies
##############
# INotify
if (HAVE_INOTIFY_INIT)
set(INOTIFY_SOURCES "io/INotify.d")
set(INOTIFY_DEFINITIONS "${INOTIFY_DEFINITIONS} ${CMAKE_D_VERSION_FLAG}INotify" CACHE BOOLEAN TRUE FORCE)
endif (HAVE_INOTIFY_INIT)
#################################
# Compiler Switches
##############
INCLUDE_DIRECTORIES(
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}
)
link_directories(
)
add_definitions(
${INOTIFY_DEFINITIONS}
)
#################################
# Source Files
##############
add_library(A STATIC
core/Exception.d
${INOTIFY_SOURCES}
io/Output.d
mixins/BladeParse.d
mixins/HandyMixins.d
mixins/HandyMixinHelpers.d
)
#################################
# Linking
##############
target_link_libraries(A
)
#################################
# Clean ddoc's
##############
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_D_DDOC_CLEAN_FILES}")
#################################
# Install Files
##############
file(GLOB sources "${CMAKE_CURRENT_SOURCE_DIR}/*.d")
install(
FILES
${sources}
DESTINATION
include/FullSkeleton/A
)

View file

@ -0,0 +1,40 @@
/**
*
* Exception Class
*
* Authors: Tim Burrell
* Copyright: Copyright (c) 2007
* License: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
*
**/
////////////////////////////////////////////////////////////////////////////
// Module
///////////////////////////////////////
module libraryA.core.Exception;
////////////////////////////////////////////////////////////////////////////
// Imports
///////////////////////////////////////
import tango.core.Exception;
////////////////////////////////////////////////////////////////////////////
// Typedef's / Enums
///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Exception Classes
///////////////////////////////////////
/**
* PathNotFoundException Class
**/
class PathNotFoundException : IOException {
/// Default Constructor
this (char [] Message) {
super(Message);
}
}

View file

@ -0,0 +1,95 @@
/**
*
* INotify Class
*
* Authors: Tim Burrell
* Copyright: Copyright (c) 2007
* License: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
*
**/
////////////////////////////////////////////////////////////////////////////
// Module
///////////////////////////////////////
module libraryA.io.INotify;
////////////////////////////////////////////////////////////////////////////
// Imports
///////////////////////////////////////
import libraryA.core.Exception;
////////////////////////////////////////////////////////////////////////////
// C Bindings
///////////////////////////////////////
extern (C) int inotify_init();
////////////////////////////////////////////////////////////////////////////
// Typedef's / Enums
///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// INotify Definition
///////////////////////////////////////
/**
* INotify Class
**/
class INotify {
////////////////////////////////////////////////////////////////////
// Constants
///////////////////////////////
////////////////////////////////////////////////////////////////////
// Public members
///////////////////////////////
////////////////////////////////////////////////////////////////////
// Construction
///////////////////////////////
/**
* Default Constructor
**/
this () {
// init inotify
if ((mInotifyFD = inotify_init()) < 0)
throw new Exception("Failed to Initialize INotify!");
}
/**
* Destructor
**/
~this () {
//close(mInotifyFD);
}
////////////////////////////////////////////////////////////////////
// Public Functions
///////////////////////////////
/**
* Add a path to be watched by INotify
*
* Params: WatchPatch = Patch to Watch
* Throws:
**/
void addWatch(char [] WatchPatch) {
}
////////////////////////////////////////////////////////////////////
private:
////////////////////////////////////////////////////////////////////
// Private Functions
///////////////////////////////
////////////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////
int mInotifyFD; ///< Inotify File Descriptor
}

View file

@ -0,0 +1,106 @@
/**
*
* Output Class
*
* Authors: Tim Burrell
* Copyright: Copyright (c) 2007
* License: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
*
**/
////////////////////////////////////////////////////////////////////////////
// Module
///////////////////////////////////////
module libraryA.io.Output;
////////////////////////////////////////////////////////////////////////////
// Imports
///////////////////////////////////////
version (Tango) {
import tango.io.Stdout;
} else {
import std.stdio;
}
////////////////////////////////////////////////////////////////////////////
// Typedef's / Enums
///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Output Definition
///////////////////////////////////////
/**
* Output Class
**/
class Output {
////////////////////////////////////////////////////////////////////
// Constants
///////////////////////////////
////////////////////////////////////////////////////////////////////
// Public members
///////////////////////////////
public alias output opCall; /// Alias opCall
////////////////////////////////////////////////////////////////////
// Construction
///////////////////////////////
/**
* Default Constructor
**/
this () {
}
/**
* Destructor
**/
~this () {
}
////////////////////////////////////////////////////////////////////
// Public Functions
///////////////////////////////
/**
* Output some text
*
* Params: LogLevel = Level of output
* Returns: Self
**/
final Output output(lazy char [] Output) {
version (Tango) {
Stdout(Output).newline;
} else {
writefln(Output);
}
return this;
}
////////////////////////////////////////////////////////////////////
private:
////////////////////////////////////////////////////////////////////
// Private Functions
///////////////////////////////
////////////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////
}
////////////////////////////////////////////////////////////////////////////
// Globals
///////////////////////////////////////
static this() {
Out = new Output();
}
public static Output Out; /// Global Logout object

View file

@ -0,0 +1,130 @@
/**
*
* BladeParse
*
* Thanks to the <a href="http://www.dsource.org/projects/mathextra/">mathextra</a> project for this!
*
* Original source <a href="http://www.dsource.org/projects/mathextra/browser/trunk/blade/BladeParse.d">here</a>.
**/
module libraryA.mixins.BladeParse;
// General utilities.
char [] itoa(T)(T x)
{
char [] s="";
static if (is(T==byte)||is(T==short)||is(T==int)||is(T==long)) {
if (x<0) {
s = "-";
x = -x;
}
}
do {
s = cast(char)('0' + (x%10)) ~ s;
x/=10;
} while (x>0);
return s;
}
bool isDigit(char c) { return c>='0' && c<='9'; }
bool isHexDigit(char c) { return c>='0' && c<='9' || c>='a' && c<='f' || c>='A' && c<='F'; }
bool isAlpha(char c) {
return (c>='a' && c<='z') || (c>='A' && c<='Z');
}
// Underscores allowed
bool isUnderscoreDigit(char c) { return c=='_' || c>='0' && c<='9'; }
bool isUnderscoreHexDigit(char c) { return c=='_' || c>='0' && c<='9' || c>='a' && c<='f' || c>='A' && c<='F'; }
bool isUnderscoreAlpha(char c) {
return c=='_' || (c>='a' && c<='z') || (c>='A' && c<='Z');
}
unittest {
assert(isHexDigit('9'));
}
// Extract a D identifier. Return the remainder of the string.
char [] parseIdentifier(char [] s, out char [] rest)
{
int i=0;
if (!isUnderscoreAlpha(s[0])) { assert(0, "Identifier expected"); }
while (i<s.length && (isUnderscoreAlpha(s[i])||isDigit(s[i]))) ++i;
char [] ident=s[0..i];
while (i<s.length && s[i]==' ') ++i; // skip trailing spaces
rest = s[i..$];
return ident;
}
char [] parseNumber(char [] s, out char[] rest)
{
int k=0;
while(k<s.length && isDigit(s[k])) ++k;
if (k<s.length-1 && s[k]=='.' && s[k+1]!='.') {
++k;
while(k<s.length && isDigit(s[k])) ++k;
if (k<s.length && s[k]=='e') { ++k;
if (k<s.length && (s[k]=='+' || s[k]=='-')) ++k;
while(k<s.length && isDigit(s[k])) ++k;
}
if (k<s.length && (s[k]=='L' || s[k]=='f')) ++k;
}
char [] ident = s[0..k];
int i=k;
while (i<s.length && s[i]==' ') ++i; // skip trailing spaces
rest = s[i..$];
return ident;
}
char [] parseOperator(char [] s, out char [] rest)
{
int i=1;
if (s[0]=='+' || s[0]=='-' || s[0]=='*') {
if (s.length>1 && s[1]=='=') ++i;
int k=i;
while (k<s.length && s[k]==' ') ++k; // skip trailing spaces
rest = s[k..$];
return s[0..i];
} else {
assert(0, `Operator expected, not "` ~ s~ `"`);
}
}
char [] parseQualifiedName(char [] s, out char[] rest)
{
char [] r;
char [] id = parseIdentifier(s, r);
while (r.length>0 && r[0]=='.') {
int i;
for (i=1; r[i]==' '; ++i) {}
id ~= "." ~ parseIdentifier(r[i..$], r);
}
rest=r;
return id;
}
// Some functions to grab information from the typestring.
// Return the first index in the tuple which is of vector type
int findFirstVector(char [][] typelist)
{
for (int i=0; i< typelist.length;++i) {
if (isVector(typelist[i])) return i;
}
return 0;
}
bool isVector(char [] typestr)
{
return (typestr[0]=='V' || typestr[0]=='Z');
}
// Count the number of vectors in the typestring
int countVectors(char [][] typelist)
{
int numVecs=0;
for (int i=0; i<typelist.length; ++i) {
if (isVector(typelist[i])) ++numVecs;
}
return numVecs;
}

View file

@ -0,0 +1,44 @@
/**
*
* Handy Mixin Helpers
*
* Authors: Tim Burrell
* Copyright: Copyright (c) 2007
* License: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
*
**/
////////////////////////////////////////////////////////////////////////////
// Module
///////////////////////////////////////
module libraryA.mixins.HandyMixinHelpers;
////////////////////////////////////////////////////////////////////////////
// Imports
///////////////////////////////////////
import libraryA.mixins.BladeParse;
////////////////////////////////////////////////////////////////////////////
// Mixin Helpers (like not useful on their own)
///////////////////////////////////////
/// for use with enumConditional
char [] createEnumConditionalLoop(int Size) {
char [] ret = "bool NeedsComma = false;\n";
for (int lp = 1; lp < Size; lp += 2) {
char [] curVal = itoa(lp);
char [] curValMinus1 = itoa(lp - 1);
ret ~= "if ( (T.length > " ~ curVal ~") && (T[" ~ curVal ~ "]) ) {";
if (lp > 1) {
ret ~= " if (NeedsComma) {"
" ret ~= \",\n\";"
" }";
}
ret ~= " ret ~= \"\t\" ~ T[" ~ curValMinus1 ~ "];"
" NeedsComma = true;"
"}";
}
return ret;
}

View file

@ -0,0 +1,103 @@
/**
*
* Handy Mixins
*
* Authors: Tim Burrell
* Copyright: Copyright (c) 2007
* License: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
*
**/
////////////////////////////////////////////////////////////////////////////
// Module
///////////////////////////////////////
module libraryA.mixins.HandyMixins;
////////////////////////////////////////////////////////////////////////////
// Imports
///////////////////////////////////////
import libraryA.mixins.HandyMixinHelpers;
////////////////////////////////////////////////////////////////////////////
// Mixins
///////////////////////////////////////
/**
* Auto build class member
*
* Params: Type = Type of the property
* Name = Name of the property
* Returns: String containing the resulting property
**/
template prop(Type, char [] Name) {
const char [] prop = "private " ~ Type.stringof ~ " " ~ Name ~ ";" ;
}
/**
* Auto build setter
*
* Params: Type = Type of the property
* Name = Name of the property
* Returns: String containing the resulting property
**/
template propWrite(Type, char [] Name) {
const char [] propWrite = "void set" ~ Name ~ "(inout " ~ Type.stringof ~ " The" ~ Name ~ ") { "
~ Name ~ " = The" ~ Name ~ "; }; \n\n"
~ prop!(Type, Name);
}
/**
* Auto build getter
*
* Params: Type = Type of the property
* Name = Name of the property
* Returns: String containing the resulting property
*
* Bugs: Not Implemented!
**/
template propRead(Type, char [] Name) {
const char [] propRead = "void set" ~ Name ~ "(inout " ~ Type.stringof ~ " The" ~ Name ~ ") { "
~ Name ~ " = The" ~ Name ~ "; }; \n\n"
~ prop!(Type, Name);
}
/**
* Conditionally construct an enum
*
* Params: Name = Name of the enum
* T = Enum elements and their conditions
* Returns: String containing the resulting enum
*
* Example:
* -------------------------------------------------------------------------
* const char [] RENDERER_CURSES = "False";
* const char [] RENDERER_VT102 = "True";
* const char [] RENDERER_X11 = "True";
*
* mixin(enumConditional!("RendererClass",
* "RendererCurses", RENDERER_CURSES == "True",
* "RendererVT102", RENDERER_VT102 == "True",
* "RendererX11", RENDERER_X11 == "True"
* ).createEnum());
* -------------------------------------------------------------------------
* Would result in the following enum:
* -------------------------------------------------------------------------
* enum {
* RendererVT102,
* RendererX11
* }
* -------------------------------------------------------------------------
* Obviously, this is all done at compile time.
**/
template enumConditional(char [] Name, T...) {
//alias T tupleof;
char [] createEnum() {
char [] ret = "enum " ~ Name ~ " {\n";
mixin(createEnumConditionalLoop(T.length));
return ret ~ "\n}";
}
}