<commit_before>#include "stdafx.h"

#include "Model.h"
using namespace mvvm::model;

#include "DataBinding.h"
using namespace mvvm::binding;

namespace {

	enum Gender {
		Man, Woman
	};

	class Student {

	public:
		Model<Gender> gender;
		Model<string> name;
		Model<int> age;

		Student() : gender(Gender::Woman)
			, name("lucy")
			, age(23) {
		}
	};

	class StudentView {

	public:
		DependencyObject<Gender> gender;
		DependencyObject<string> name;
		DependencyObject<int> age;

		LambdaObserver observer;

		StudentView() : gender(Gender::Man)
			, name("jack"), age(11) {

			observer.set([this](void* model, int id, void* arg) {
				PrintHelper::Enter();
				PrintHelper::Print(this->toString());
				PrintHelper::Exit();
			});

			gender.addObserver(&observer);
			name.addObserver(&observer);
			age.addObserver(&observer);
		}

	public:
		string toString() const {
			stringstream ss;

			ss << "StudentView2@" << this << ":{";
			ss << "Gender=" << gender.get() << ',';
			ss << "Name=" << name.get() << ',';
			ss << "Age=" << age.get() << '}';

			return ss.str();
		}

	};

}

void test14() {

	Student student;
	StudentView stuView;

	cout << stuView.toString() << endl << endl;

	make_binding(&student.gender, &stuView.gender, BindingType::OneWay);
	cout << endl;

	make_binding(&student.name, &stuView.name, BindingType::OneWay);
	cout << endl;

	make_binding(&student.age, &stuView.age, BindingType::OneWay);
	cout << endl;

	student.age.set(11); cout << endl;
	student.name.set("jack"); cout << endl;
	student.gender.set(Gender::Man); cout << endl;
}<commit_msg>探索MVVM框架；<commit_after>#include "stdafx.h"

#include "Model.h"
using namespace mvvm::model;

#include "DataBinding.h"
using namespace mvvm::binding;

namespace {

	enum Gender {
		Man, Woman
	};

	class Student {

	public:
		Model<Gender> gender;
		Model<string> name;
		Model<int> age;

		Student() : gender(Gender::Woman)
			, name("lucy")
			, age(23) {
		}

	};

	class StudentView {

	public:
		DependencyObject<Gender> gender;
		DependencyObject<string> name;
		DependencyObject<int> age;

		LambdaObserver observer;

		StudentView() : gender(Gender::Man)
			, name("jack"), age(11) {

			observer.set([this](void* model, int id, void* arg) {
				PrintHelper::Enter();
				PrintHelper::Print(this->toString());
				PrintHelper::Exit();
			});

			gender.addObserver(&observer);
			name.addObserver(&observer);
			age.addObserver(&observer);
		}

	public:
		string toString() const {
			stringstream ss;

			PrintHelper::Close();
			{
				ss << "StudentView2@" << this << ":{";
				ss << "Gender=" << gender.get() << ',';
				ss << "Name=" << name.get() << ',';
				ss << "Age=" << age.get() << '}';
			}
			PrintHelper::Open();

			return ss.str();
		}

	};

	/*****************************************************************

	<MainWindow>
		<StudentView id="myStudentView" gender="{student.gender OneWay}"
			name="{student.name OneWay}" age="{student.age OneWay}" />
	</MainWindow>

	*******************************************************************/

	namespace UI {

		template<typename ViewModel> class MainWindow {

		private:
			StudentView* myStudentView;

		public:
			void InitUI(ViewModel* vm) {

				myStudentView = new StudentView();
				cout << myStudentView->toString() << endl << endl;

				make_binding(&vm->student.gender, &myStudentView->gender, BindingType::OneWay);
				cout << endl;

				make_binding(&vm->student.name, &myStudentView->name, BindingType::OneWay);
				cout << endl;

				make_binding(&vm->student.age, &myStudentView->age, BindingType::OneWay);
				cout << endl;
			}

		};

	}

	namespace ViewModel {

		class MainWindow {
			friend class UI::MainWindow<MainWindow>;

		private:
			UI::MainWindow<MainWindow> mainWindow;
			Student student = Student();

		public:
			MainWindow() {
				mainWindow.InitUI(this);
			}

			void onButtonClick() {
				student.age.set(11); cout << endl;
				student.name.set("jack"); cout << endl;
				student.gender.set(Gender::Man); cout << endl;
			}

		};
	}

}

void test14() {
	ViewModel::MainWindow viewModel;
	viewModel.onButtonClick();
}
{'fraction_non_alphanumeric': 0.20248235580433196, 'fraction_numerical': 0.004380627889997567, 'mean_word_length': 3.963768115942029, 'pattern_counts': {'":': 2, '<': 105, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '968519', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1349, 'n_words': 267}