File:  [parser3project] / parser3 / src / types / pa_vconsole.h
Revision 1.33: download - view: text, annotated - select for diffs - revision graph
Mon Oct 12 21:59:21 2026 UTC (2 weeks, 3 days ago) by moko
Branches: MAIN
CVS tags: HEAD
MAYBE_GET_SPECIAL_OR_METHOD and MAYBE_GET_SPECIAL added ans used to avoid OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL defines; used in memcached and hashfile to allow keys with method names

/** @file
	Parser: @b console class decl.

	Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
	Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
*/

#ifndef PA_VCONSOLE_H
#define PA_VCONSOLE_H

#define IDENT_PA_VCONSOLE_H "$Id: pa_vconsole.h,v 1.33 2026/10/12 21:59:21 moko Exp $"

// includes

#include "pa_sapi.h"
#include "pa_common.h"
#include "pa_vstateless_class.h"
#include "pa_string.h"

// defines

#define CONSOLE_LINE_NAME "line"

/// console class
class VConsole: public VStateless_class {
public: // Value
	
	const char* type() const { return "console"; }

	/// console: line
	Value* get_element(const String& aname) {
		MAYBE_GET_SPECIAL(VStateless_class::get_element(aname));

		// $line
		if(aname==CONSOLE_LINE_NAME) {
			char local_value[MAX_STRING];
			if(fgets(local_value, sizeof(local_value), stdin))
				return new VString(pa_strdup(local_value));

			return 0; // EOF
		}

		return bark("%s field not found", &aname);
	}

	/// console: $line
	override const VJunction* put_element(const String& aname, Value* avalue) { 
		// $line
		if(aname==CONSOLE_LINE_NAME) {
			fused=true;
			puts(avalue->as_string().cstr());
			fflush(stdout);

			return 0;
		}

		throw Exception(PARSER_RUNTIME, &aname, "writing to invalid field");
	}

	bool was_used(){
		return fused;
	}

public: // usage

	VConsole() {
		fused=false;
	}

private:
	bool fused;
};

#endif

E-mail: