Beispiel #1
0
	INIFile::INIFile(const String& filename)
		: check_duplicate_keys_(false),
			valid_(false),
			filename_(filename)
	{
    appendSection(HEADER);
	}
		TITANIUM_FUNCTION(ListView, appendSection)
		{
			const auto js_context = this_object.get_context();
			if (arguments.size() >= 1) {
				JSObject animation = js_context.CreateObject();
				std::vector<std::shared_ptr<ListSection>> sections;

				const auto _0 = arguments.at(0);
				TITANIUM_ASSERT(_0.IsObject());
				const auto js_sections = static_cast<JSObject>(_0);

				if (js_sections.IsArray()) {
					sections = static_cast<JSArray>(js_sections).GetPrivateItems<ListSection>();
				} else {
					sections.push_back(js_sections.GetPrivate<ListSection>());
				}

				if (arguments.size() >= 2) {
					const auto _1 = arguments.at(1);
					if (_1.IsObject()) {
						animation = listviewAnimationProperties_ctor__.CallAsConstructor({_1});
					}
				}

				appendSection(sections, animation.GetPrivate<ListViewAnimationProperties>());
			}
			return this_object.get_context().CreateUndefined();
		}
Beispiel #3
0
	// Default constructor
	INIFile::INIFile()
		:	check_duplicate_keys_(false),
			valid_(false),
			filename_("")
	{	
		appendSection(HEADER);
	}
Beispiel #4
0
	void INIFile::clear()
	{
		sections_.clear();
		section_index_.clear();
		valid_ = false;
		check_duplicate_keys_ = false;

    appendSection(HEADER);
	}
Beispiel #5
0
	const INIFile& INIFile::operator = (const INIFile& file)
		
	{
		check_duplicate_keys_ = file.check_duplicate_keys_;
		valid_ = file.valid_;
		filename_ = file.filename_;
		appendSection(HEADER);
		return *this;
	}
Beispiel #6
0
	bool INIFile::appendLine(const String& data)
	{
		if (data[0] == '[')
		{
			return appendSection(data);
		}

		if (sections_.empty()) return false;
		return appendLine((*sections_.rbegin()).name_, data);
	}
		TITANIUM_FUNCTION(TableView, appendSection)
		{
			if (arguments.size() < 1) {
				return get_context().CreateUndefined();
			} else if (arguments.size() >= 2) {
				const auto _0 = arguments.at(0);
				TITANIUM_ASSERT(_0.IsObject());
				const auto _1 = arguments.at(1);
				TITANIUM_ASSERT(_1.IsObject());
				const auto section = static_cast<JSObject>(_0);
				const auto animation = static_cast<JSObject>(_1);
				appendSection(section.GetPrivate<TableViewSection>(), animation.GetPrivate<TableViewAnimationProperties>());
			} else if (arguments.size() >= 1) {
				const auto _0 = arguments.at(0);
				TITANIUM_ASSERT(_0.IsObject());
				const auto section = static_cast<JSObject>(_0);
				const auto animation = get_context().CreateObject();
				appendSection(section.GetPrivate<TableViewSection>(), animation.GetPrivate<TableViewAnimationProperties>());
			}
			return get_context().CreateUndefined();
		}
Beispiel #8
0
	bool INIFile::read()
	{
		// destroy all datastructures - we make a new start
		// we only keep the filename...
		clear();

		// If the filename is empty, there's no point in opening it...
		if (filename_ == "")
		{
			return false;
		}

		// try to open the file
		ifstream infile(filename_.c_str());

		// if we couldn't open the file: abort
		if (!infile)
		{
			return false;
		}

		list<Section>::iterator	section_it(sections_.begin());

		// read all lines from the file
		std::vector<char> buffer(MAX_LINE_LENGTH);
		while (infile.getline(&(buffer[0]), MAX_LINE_LENGTH))
		{
			// remove leading blanks
			String line(&(buffer[0]));
			line.trimLeft();

			// check for comment lines or empty line
			if (line.empty()     || (line[0] == '!') ||
			   (line[0] == ';')  || (line[0] == '#'))
			{
				section_it->lines_.push_back(&(buffer[0]));
				continue;
			}

			// check for start of section
			if (line[0] == '[')
			{	
				if (!appendSection(line))
				{
					return false;
				}

				section_it++;
				
				continue;
			}
			
			// this is neither a comment line nor a section start
			// line still has to be added
			if (!appendLine("", line))
			{
				return false;
			}
		}
		
		// close the file
		infile.close();

		// done.
		valid_ = true;
		return true;
	}