void ofxTweakbarSimpleStorage::store() {

	std::map<std::string, ofxTweakbarType*> vars = getBar()->getVariables();
	std::map<std::string, ofxTweakbarType*>::iterator it = vars.begin();
	ofxTweakbarType* type = NULL;
	OFX_TW_TYPE tw_type;

	// get file
	std::string section = getBar()->getName();
	std::ofstream ofs;
	std::string file = getPath(); 
	ofs.open(file.c_str());
	if (ofs.fail()) {
		std::cout << "Error: could not open: " << file << std::endl;
		return;
	}
	
	// Store all values.
	while(it != vars.end()) {
		type = it->second;
		tw_type = type->getType();
		if(tw_type == OFX_TW_TYPE_INT32) {
			ofxTweakbarInt* type_impl = static_cast<ofxTweakbarInt*>(it->second);
			ofs << type_impl->getName() << "\t" << type_impl->getValue() << std::endl;
		}
		else if (tw_type == OFX_TW_TYPE_FLOAT) {
			ofxTweakbarFloat* type_impl = static_cast<ofxTweakbarFloat*>(it->second);
			ofs << type_impl->getName() << "\t" << type_impl->getValue() << std::endl;
			
		}
		else if (tw_type == OFX_TW_TYPE_BOOL) {
			ofxTweakbarBool* type_impl = static_cast<ofxTweakbarBool*>(it->second);
			ofs << type_impl->getName() << "\t" << type_impl->getValue() << std::endl;	
		}
		else if (tw_type == OFX_TW_TYPE_COLOR3F) {
			ofxTweakbarColor3f* type_impl = static_cast<ofxTweakbarColor3f*>(it->second);
			ofs << type_impl->getName() << "\t"
				<< type_impl->getX()	<< "\t" 
				<< type_impl->getY()	<< "\t" 
				<< type_impl->getZ()	<< std::endl;		
		}
		else if (tw_type == OFX_TW_TYPE_QUAT4F) {
			ofxTweakbarQuat4f* type_impl = static_cast<ofxTweakbarQuat4f*>(it->second);
			ofs << type_impl->getName() << "\t"
				<< type_impl->getX()	<< "\t" 
				<< type_impl->getY()	<< "\t" 
				<< type_impl->getZ()	<< "\t"
				<< type_impl->getS()	<< "\t"
				<< type_impl->isOpened() << std::endl;		
		}
		else if (tw_type == OFX_TW_TYPE_VEC3F) {
			ofxTweakbarVec3f* type_impl = static_cast<ofxTweakbarVec3f*>(it->second);
			ofs << type_impl->getName() << "\t"
				<< type_impl->getX()	<< "\t" 
				<< type_impl->getY()	<< "\t" 
				<< type_impl->getZ()	<< std::endl;		
		}
		else if (tw_type == OFX_TW_TYPE_BAR_POSITION) {
			ofxTweakbarBarData* type_impl = static_cast<ofxTweakbarBarData*>(it->second);
			ofs << type_impl->getName()	<< "\t"
				<< type_impl->getX()	<< "\t"
				<< type_impl->getY()	<< std::endl;
		}
		else if (tw_type == OFX_TW_TYPE_BAR_SIZE) {
			ofxTweakbarBarData* type_impl = static_cast<ofxTweakbarBarData*>(it->second);
			ofs << type_impl->getName()	<< "\t"
				<< type_impl->getX()	<< "\t"
				<< type_impl->getY()	<< std::endl;
		}
		else if (tw_type == OFX_TW_TYPE_BAR_OPENED) {
			ofxTweakbarBarData* type_impl = static_cast<ofxTweakbarBarData*>(it->second);
			ofs << type_impl->getName()	<< "\t"
				<< type_impl->getBool() << std::endl;
		}
		else if (tw_type == OFX_TW_TYPE_BAR_VALUES_WIDTH) {
			ofxTweakbarBarData* type_impl = static_cast<ofxTweakbarBarData*>(it->second);
			ofs << type_impl->getName()	<< "\t"
				<< type_impl->getValuesWidth() << std::endl;
		}
		else if(tw_type == OFX_TW_TYPE_LIST) {
			ofxTweakbarList* type_impl = static_cast<ofxTweakbarList*>(it->second);
			ofs << type_impl->getName() << "\t"
				<< type_impl->getSelectedIndex() << std::endl;
		}
		else if(tw_type == OFX_TW_TYPE_STRING) {
			ofxTweakbarString* type_impl = static_cast<ofxTweakbarString*>(it->second);
			ofs << type_impl->getName() << "\t"
				<< type_impl->getValue() << std::endl;
		}
		++it;
	}
	ofs.close();

}
ofxTweakbar* ofxTweakbar::refresh() {
	TwRefreshBar(getBar());
	return this;
}