Click here to Skip to main content
15,881,380 members
Articles / Containers / Virtual Machine

TOOL

Rate me:
Please Sign up or sign in to vote.
4.98/5 (52 votes)
23 Oct 200676 min read 229.9K   5.4K   147  
TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language interpreter. The purpose of this article is to introduce the TOOL interpreter and language from the perspective of a person who has a desire to include a scripting solution as part of his project.
#ifndef XML_FORM_PARSER_H_INCLUDED
#define XML_FORM_PARSER_H_INCLUDED
/*****************************************************************************/
/*                              HEADER FILE                                  */
/*****************************************************************************/
/*
          $Archive:   $

         $Revision:   $

      Last Checkin:
             $Date:   $
                By:
           $Author:   $

 Last Modification:
          $ModTime:   $

       Description:   Declaration of a xml-parser wrapper / observer class that
                      will create a form definition structure from a meta form
                      presented in xml format

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
/*****************************************************************************/


#include <string>
#include <vector>
#include <map>

//using namespace std;

#include "XMLFormCoreStructures.h"


///////////////////////////////////////////////////////////////////////////////
//
// this object defined here implements this interface so pull in the interface
// definition
//
#include "XMLParserObserver.h"

#pragma warning( disable : 4786 )


///////////////////////////////////////////////////////////////////////////////
//
// strings that represent data-object domains in the xml-text
//
const std::string coSheet          = "SHEET";
const std::string coForm           = "PAGE";
const std::string coFormCaption    = "PAGE_CAPTION";
const std::string coFormBackground = "PAGE_BACKGROUND";
const std::string coFrameStyle     = "FRAME_STYLE";
const std::string coTabOrder       = "TAB_ORDER";
const std::string coTabDefn        = "TAB_DEFN";
const std::string coControls       = "CONTROLS";
const std::string coControlStart   = "CONTROL";
const std::string coCtrlType       = "CTRL_TYPE";
const std::string coCtrlName       = "CTRL_NAME";
const std::string coCtrlStyle      = "CTRL_STYLE";
const std::string coCtrlLocation   = "CTRL_LOCATION";
const std::string coCtrlAnchor     = "CTRL_ANCHOR";
const std::string coDataTypes      = "DATA_TYPES";
const std::string coDataType       = "DATA_TYPE";
const std::string coSeedSet        = "SEED_VALUES";
const std::string coSeedEntry      = "SEED";
const std::string coColumnEntry    = "COLUMN";
const std::string coValidations    = "VALIDATIONS";
const std::string coValidate       = "VALIDATE";
const std::string coBuddy          = "CTRL_BUDDY";
const std::string coActions        = "ACTIONS";
const std::string coCtrlAction     = "CTRL_ACTION";
const std::string coFormAction     = "FORM_ACTION";
const std::string coSubForm        = "SUB_FORM";


///////////////////////////////////////////////////////////////////////////////
//
// create a table of fixed values that will map to the tokens listed above
//
enum eMetaFormTags
{ 
  eNotDefined, 
  eSheet,
  eForm,
  eFormCaption,
  eFormBackground,
  eOutputTarget,
  eFrameStyle,
  eTabOrder,
  eTabDefn,
  eControls,
  eControl,
  eBuddy,
  eCtrlType,
  eCtrlName,
  eCtrlStyle,
  eCtrlLocation,
  eCtrlAnchor,
  eDataTypes,
  eDataType,
  eSeedSet,
  eSeedEntry,
  eValidations,
  eValidate,
  eColumnEntry,
  eActions,
  eFormAction,
  eCtrlAction,
  eSubFormCtrl,
  eEnd 
};


///////////////////////////////////////////////////////////////////////////////
//
// define the set of attribute names and values that are read by this parser
//
const char   cchQuote                 = '"';
const char   cchSingleQuote           = '\'';
const std::string coValue                  = "value";
const std::string coItemData               = "item.data";
const std::string coNone                   = "none";
const std::string coArguments              = "arguments";
const std::string coTipText                = "tool.tip.text";
const std::string coStyle                  = "style";
const std::string coExStyle                = "exstyle";
const std::string coPrevious               = "prev";
const std::string coCurrent                = "ref";
const std::string coNext                   = "next";
const std::string coSizeLeft               = "left";
const std::string coSizeRight              = "right";
const std::string coSizeTop                = "top";
const std::string coSizeBottom             = "bottom";
const std::string coWidth                  = "fix.width";
const std::string coLeft                   = "fix.edge.left";
const std::string coRight                  = "fix.edge.right";
const std::string coWidthLeft              = "fix.width.left";
const std::string coWidthRight             = "fix.width.right";
const std::string coLeftRight              = "fix.left.right";
const std::string coHeight                 = "fix.height";
const std::string coTop                    = "fix.edge.top";
const std::string coBottom                 = "fix.edge.bottom";
const std::string coHeightTop              = "fix.height.top";
const std::string coHeightBottom           = "fix.height.bottom";
const std::string ciTopBottom              = "fix.top.bottom";
const std::string coFixed                  = "fix.all.sides";
const std::string coBuddySide              = "on.side";
const std::string coBuddyRight             = "right.of.buddy";
const std::string coBuddyLeft              = "left.of.buddy";
const std::string coButton                 = "button";
const std::string coRadioButton            = "radio.button";
const std::string coCheckBox               = "check.box";
const std::string coEditCtrl               = "edit.text";
const std::string coCardTrackCtrl          = "card.swipe.ctrl";
const std::string coLabel                  = "label";
const std::string coGroupBox               = "label.box";
const std::string coListBox                = "list.box";
const std::string coHScroll                = "h.scroll";
const std::string coVScroll                = "v.scroll";
const std::string coComboBox               = "combobox";
const std::string coSpinButton             = "spin.button";
const std::string coSlideCtrl              = "slider.ctrl";
const std::string coListCtrl               = "report.list";
const std::string coTreeCtrl               = "tree.ctrl";
const std::string coDateTimePicker         = "date.time";
const std::string coMonthCalender          = "calendar";
const std::string coIPAddress              = "i.p.address";
const std::string coColorPicker            = "color.picker";               // mjs
const std::string coControl                = "control";
const std::string coUsing                  = "using";
const std::string coAsString               = "simple.string";
const std::string coAsLengthCheckedString  = "length.checked.string";
const std::string coAsInteger              = "simple.integer";
const std::string coAsRangeCheckedInteger  = "range.checked.integer";
const std::string coAsDecimal              = "simple.decimal";
const std::string coAsRangeCheckedDecimal  = "range.checked.decimal";
const std::string coAsScript               = "using.script";
const std::string coAsPhoneNumber          = "phone.number";
const std::string coAsEmailAddress         = "email.address";
const std::string coAsCreditCard           = "credit.card";
const std::string coAsCreditCardDate       = "credit.card.date";
const std::string coAsCardTrackData        = "card.track.data";
const std::string coAsNotValidated         = "none";
const std::string coAsStringValue          = "as.string";
const std::string coAsTrackDataValue       = "as.track.data";
const std::string coAsCheckedValue         = "as.boolean";
const std::string coAsSelectedIndexValue   = "as.index";
const std::string coValueAsInteger         = "as.integer";
const std::string coValueAsDouble          = "as.decimal";
const std::string coValueAsItemData        = "as.item.data";
const std::string coMaxPrecision           = "precision";
const std::string coAsIgnoredvalue         = "none";
const std::string coTransferAs             = "as";
const std::string coButtonGroup            = "group";
const std::string coFormName               = "name";
const std::string coBuddyName              = "spinner.for";
const std::string coRangeLower             = "min.value";
const std::string coRangeUpper             = "max.value";
const std::string coImage                  = "image";
const std::string coImageType              = "image.type";
const std::string coBmpType                = "bmp";
const std::string coIconType               = "icon";
const std::string coSource                 = "image.source";
const std::string coNetFile                = "net.file";
const std::string coSysFile                = "sys.file";
const std::string coLocalFile              = "local.file";
const std::string coImageName              = "file.name";
const std::string coLocalResource          = "resource";
const std::string coImageID                = "resource.id";
const std::string coBackColor              = "back.color";
const std::string coTextColor              = "text.color";
const std::string coAltNavKey              = "alt.nav.key";
const std::string coActionOnCtrl           = "on";
const std::string coActionFor              = "for";
const std::string coFormActionEvent        = "when";
const std::string coActionEntry            = "do";
const std::string coForCall                = "for.call";
const std::string coActionScript           = "script";
const std::string coOnLoseFocus            = "OnLoseFocus";
const std::string coOnGainFocus            = "OnGainFocus";
const std::string coOnButtonClick          = "OnButtonClick";
const std::string coOnFormLoad             = "OnFormLoad";
const std::string coOnFormDestroy          = "OnFormDestroy";
const std::string coOnFormDisplayInit      = "OnFormDisplayInit";
const std::string coOnApplicationInvoke    = "OnApplicationInvoke";
const std::string coOnComboSelect          = "OnComboBoxSelChange";
const std::string coOnListBoxSelect        = "OnListBoxSelChange";
const std::string coOnTabChange            = "OnTabSelChange";
const std::string coGridLinesOpt           = "gridlines";
const std::string coRenderEntry            = "render.entry";
const std::string coRenderCode             = "render.code";
const std::string coFormWidth              = "window.width";
const std::string coFormHeight             = "window.height";
const std::string coHtmlControl            = "html.ctrl";
const std::string coFont                   = "font";
const std::string coTabAlias               = "tab.alias";
const std::string coTabEnterToCtrl         = "tab.enter.to.ctrl";
const std::string coTabExitFromCtrl        = "tab.exit.from.ctrl";
const std::string coAnchorType             = "anchor.style";
const std::string coDisplayName            = "display.name";
const std::string coTabControl             = "tab.control"; 
const std::string coOnTopOf                = "on.top.of";
const std::string coMoneyControl           = "money.edit";
const std::string coFloatControl           = "float.edit";
const std::string coIntegerControl         = "integer.edit";
const std::string coNumericControl         = "numeric.edit";
const std::string coAlphaNumericControl    = "alpha.numeric";
const std::string coAlphaControl           = "alpha.edit";
const std::string coEditCombo              = "edit.combo";
const std::string coFilePickerControl      = "file.chooser";
const std::string coDirPickerControl       = "dir.chooser";


///////////////////////////////////////////////////////////////////////////////
//
// this map will contain a mapping of the supported xml tags and the table of
// tags shown above
//
typedef std::map< std::string, eMetaFormTags > XML_TAGS_MAP;	
typedef XML_TAGS_MAP::iterator                 XML_TAGS_MAP_ITER;

typedef std::map< std::string, P_FORM_DEFINITION > PAGE_DEFINITION_SET;
typedef PAGE_DEFINITION_SET::iterator              PAGE_DEFINITION_SET_ITER;

typedef std::map< int, P_FORM_DEFINITION > PROP_PAGE_LIST;
typedef PROP_PAGE_LIST::iterator           PROP_PAGE_LIST_ITER;


///////////////////////////////////////////////////////////////////////////////
//
// finally, the class which will act as a FORM_DEFINITION factory when
// provided with meta-form-data in xml format
//
class CXMLFormParser : public CXMLParserObserver
{
friend  class CXMLFormWindow;
friend  class CXMLFormFacade;

public:
  CXMLFormParser( void );
  ~CXMLFormParser( void );

  PAGE_DEFINITION_SET& XmlStringToFormDefinition( std::string& roToParse );

  bool HasMultiplePages( void );
  PROP_PAGE_LIST&      GetPropPages( void );

  virtual void FoundNode    ( std::string& roName, std::string& roAttributes );
  virtual void FoundElement ( std::string& roName, std::string& roValue, std::string& roAttributes );
  virtual void StartElement ( std::string& roName, std::string& roValue, std::string& roAttributes );
  virtual void EndElement   ( std::string& roName, std::string& roValue, std::string& roAttributes );

private:
  std::string GetValueFromAttribute( std::string& roAttributes, const std::string& roAttribName );
  void        DestroyForm( void );

private:
  PAGE_DEFINITION_SET  m_oFormSetData;
  PROP_PAGE_LIST       m_oPropPages;
  XML_TAGS_MAP         m_oTagsMap;
  UINT                 m_iNextCtrlID;
  UINT                 m_iNextFormID;
  std::string          m_oCurrentFormName;
  bool                 m_bInSubForm;
};


#endif


/*****************************************************************************/
/* Check-in history 
   $WorkFile:   $
    $Archive:   $

 *$Log:   $
*/
/*****************************************************************************/


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions