vffinputstream.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 864 行 · 第 1/2 页

CPP
864
字号
//VFFInputStream.cpp/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*/#include "vcf/ApplicationKit/ApplicationKit.h"#include "vcf/ApplicationKit/VFFInputStream.h"using namespace VCF;VFFInputStream::VFFInputStream( InputStream* stream ):	componentInputLevel_(-1),	parser_(NULL),	stream_(stream),	atTopLevel_(true),	topLevelComponent_(NULL),	topLevelControlVisibility_(false),	setDesignMode_(false){	parser_ = new VCF::Parser( this );}VFFInputStream::~VFFInputStream(){	delete parser_;	parser_ = NULL;}void VFFInputStream::getOuterClassNameAndUUID( String& className, String& UUID, String& fallbackClassName ){	className = "";	UUID = "";	parser_->resetStream();	if ( true == parser_->tokenSymbolIs( "object" ) ) {		String currentSymbol;		while ( (TO_EOF != parser_->getToken()) && (false == parser_->tokenSymbolIs( "end" )) ) {			currentSymbol = parser_->tokenString();			try {				// do object				VCFChar token = parser_->nextToken();				switch ( token ) {					case ':' : {						parser_->nextToken();						className = parser_->tokenString();						parser_->nextToken();						parser_->checkToken( ',' );						parser_->nextToken();						UUID = parser_->tokenString();						parser_->nextToken();						if ( parser_->getToken() == ',' ) {							parser_->nextToken();							fallbackClassName = parser_->tokenString();						}					}					break;				}			}			catch ( BasicException& e ) {				StringUtils::trace( e.getMessage() + "\n" );				break;			}		}	}	parser_->resetStream();}void VFFInputStream::readDelegates( VCF::Component* component, VCF::Class* clazz ){		if ( parser_->tokenSymbolIs( "delegates" ) ) {			while ( (TO_EOF != parser_->getToken()) && (!parser_->tokenSymbolIs( "end" )) ) {			String currentSymbol = parser_->tokenString();			VCFChar token = parser_->nextToken();			//do delegate			switch ( token ) {				case '=' :  {					processDelegateAsignment( token, currentSymbol, clazz );				}				break;							}		}		parser_->nextToken();	}	}void VFFInputStream::processDelegateAsignment( const VCF::VCFChar& token, const VCF::String& currentSymbol, VCF::Class* clazz ){	VCFChar assignmentToken = parser_->nextToken();	String value = parser_->tokenString();	switch ( assignmentToken ) {		case '[': {			EventProperty* eventProperty = clazz->getEvent ( currentSymbol );			if ( NULL != eventProperty ) {				parser_->nextToken();				while ( ']' != parser_->getToken() ) {					value = "";					while ( (',' != parser_->getToken()) && (']' != parser_->getToken()) ) {						value += parser_->tokenString();						parser_->nextToken();					}					if ( parser_->getToken() == ',' ) {						parser_->nextToken();					}					int pos = value.find( "@" );					String functionSrcID = value.substr(0,pos);					String functionPtr = value.substr(pos+1,value.size()-(pos+1));				}			}		}		break;		default : {			//throw exception			throw RuntimeException( MAKE_ERROR_MSG_2("Invalid delegate assignment syntax") );		}		break;	}}void VFFInputStream::processAsignmentTokens( const VCFChar& token, const String& currentSymbol, Class* clazz ){	switch ( token ) {		case '=' : {			VCFChar assignmentToken = parser_->nextToken();			String value = parser_->tokenString();			switch ( assignmentToken ) {				default : {					Property* prop = clazz->getProperty( currentSymbol );					if ( NULL != prop ) {						//need to be a bit smarter here						//look at the proeprty type. If the type is						//is pdObject, then first assume that value						//is actually a string that represents the name of						//variable. Search for the value, if something is						//found then pass this into the prop->set() call.						//If nothing is found then go for it and pass						//in the value as is.						if ( (pdObject == prop->getType()) && ('@' == value[0]) ) {							//OK our value is actually a component name so we are							//going to store it in a list for later, because we may not							//have an existing instance of the component yet. To store							//this successfully we need the name of the property to set,							//the actualy object instance that we are going to set the							//property on, and the name of the component to try and retreive							//once we get to that point.														value.erase( 0, 1 );							if ( !value.empty() ) {								deferredProperties_.push_back( new DeferredPropertySetter( value, prop->getName(), prop->getSource() ) );							}						}						else {							prop->set( value );							if ( 0 == componentInputLevel_ ) {								if ( (prop->getName() == "visible") ||									(prop->getDisplayName() == "visible") ) {									topLevelControlVisibility_ = *prop->get();								}							}						}					}				}				break;				case '[': {					Property* prop = clazz->getProperty( currentSymbol );					if ( NULL != prop ) {						String value;						while ( ']' != parser_->nextToken() ) {							value += parser_->tokenString();						}						prop->set( value );					}				}				break;				case '{': {					//parser_->nextToken();					String binValue = parser_->binHexToString();					parser_->nextToken();					parser_->checkToken( '}' );					Property* prop = clazz->getProperty( currentSymbol );					if ( NULL != prop ) {						VariantData* value = prop->get();						if ( value->type == pdObject ) {							Object* obj = *value;							if ( NULL != obj ) {								Persistable* persistable = dynamic_cast<Persistable*>(obj);								if ( NULL != persistable ) {									hexToBin( binValue, persistable );								}							}						}					}				}				break;			}			parser_->nextToken();		}		break;		case '.' : {			//we are at the property name so currentSymbol			//will be the name of the proeprty we are examining			//calling nextToken will take us to the			parser_->nextToken();			String objPropName = parser_->tokenString();			VCFChar newToken = parser_->nextToken();			Property* prop = clazz->getProperty( currentSymbol );			VariantData* value = prop->get();			if ( value->type == pdObject ) {				Object* object = *value;				if ( NULL != object ) {					clazz = object->getClass();					processAsignmentTokens( newToken, objPropName, clazz );				}			}			else {				processAsignmentTokens( newToken, objPropName, clazz );			}		}		break;		case '[' : {		}		break;		default : {			parser_->errorStr( "Object type expected" );		}		break;	}}void VFFInputStream::readNewComponentInstance( VCF::Component* component ){	componentInputLevel_ = -1;	if ( NULL == topLevelComponent_ ) {		topLevelComponent_ = component;		Control* control = dynamic_cast<Control*>(component);		if ( NULL != control ) {			control->setVisible( false );		}				component->loading();	}	readObject( component, VFFInputStream::ufCreateChildren );// | VFFInputStream::ufCreateChildrenIfNoInstance );	assignDeferredProperties(component);		componentInputLevel_ = -1;	component->loaded();	Control* control = dynamic_cast<Control*>(component);	if ( NULL != control ) {		control->setVisible( topLevelControlVisibility_ );	}}void VFFInputStream::assignDeferredProperties( Component* component ){	if ( -1 == componentInputLevel_ ) {		std::vector<DeferredPropertySetter*>::iterator it = deferredProperties_.begin();		while ( it != deferredProperties_.end() ) {			DeferredPropertySetter* dps = *it;			Class* clazz = dps->source_->getClass();			Property* prop = clazz->getProperty( dps->propertyName_ );			if ( NULL != prop ) {				Component* foundComponent = NULL;				if ( true == component->bindVariable( &foundComponent, dps->propertyVal_ ) ) {					VariantData data;					data = foundComponent;					prop->set( &data );				}			}			delete dps;			dps = NULL;			it ++;		}		deferredProperties_.clear();	}}Object* VFFInputStream::createClassInstance( const String& className, const String& classID, const String& fallbackClassName ){	Object* result = NULL;	try {		result = ClassRegistry::createNewInstance( className );	}	catch (BasicException&) {		result = ClassRegistry::createNewInstance( fallbackClassName );	}	return result;}VCF::Component* VFFInputStream::readObject( VCF::Component* componentInstance, int flags ){	VCF::Component* result = NULL;		componentInputLevel_ ++;	String s;	Control* control = NULL;	Class* clazz = NULL;	Container* controlContainer = NULL;	Component* childComponent = NULL;		if ( parser_->tokenSymbolIs( "object" ) ) {		String currentSymbol;		String objectName;		//read in object info		try {			//go to object name			parser_->nextToken();			currentSymbol = parser_->tokenString();			VCFChar token;			if ( currentSymbol == ":" ) {				currentSymbol = "";				token = parser_->getToken();			}			else {				//skip to ':' 				token = parser_->nextToken();							}									parser_->checkToken( ':' );			parser_->nextToken();			if ( objectName.empty() ) {				objectName = currentSymbol;			}									String className = parser_->tokenString();			parser_->nextToken();			parser_->checkToken( ',' );			parser_->nextToken();			String classID = parser_->tokenString();			String fallbackClassName;						bool skipNextToken = false;			parser_->nextToken();			if ( parser_->getToken() == ',' ) {				parser_->nextToken();				fallbackClassName = parser_->tokenString();			}			else {				skipNextToken = true;			}			if ( flags & VFFInputStream::ufCreateComponent ) {				result = (Component*)createClassInstance( className, classID, fallbackClassName );				if ( NULL == topLevelComponent_ ) {					topLevelComponent_ = result;				}								if ( NULL != result ) {					if ( setDesignMode_ ) {						result->setDesigning( true );					}					result->loading();										clazz = result->getClass();					control = dynamic_cast<Control*>(result);					if ( NULL != control ) {						controlContainer = control->getContainer();					}				}				else {					parser_->error( "Unable to instantiate an object of type \"" + className + "\"" );				}			}			else if ( (flags & VFFInputStream::ufCreateChildrenIfNoInstance) && (NULL != componentInstance) ) {								if ( componentInstance != topLevelComponent_ ) {										Control* control = dynamic_cast<Control*>( componentInstance );					if ( NULL != control ) {						controlContainer = control->getContainer();					}															if ( NULL != controlContainer ) {						childComponent = controlContainer->findControl( currentSymbol );					}					if ( childComponent == NULL ) {						childComponent = componentInstance->findComponent( currentSymbol );					}					result = childComponent;					controlContainer = NULL;				}				else {					result = componentInstance;				}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?