#if !defined(AFX_REGEXEDIT_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_)
|
#define AFX_REGEXEDIT_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_
|
|
#if _MSC_VER >= 1000
|
#pragma once
|
#endif // _MSC_VER >= 1000
|
|
#include <afxwin.h>
|
#include <regex>
|
#include <functional>
|
#include <limits>
|
|
// ö¾ÙÀàÐÍ£ºÕýÔò±í´ïʽÀàÐÍ
|
enum class RegexType
|
{
|
Alphanumeric, // ÔÊÐí×ÖĸºÍÊý×Ö
|
Letters, // Ö»ÔÊÐí×Öĸ
|
Digits, // Ö»ÔÊÐíÊý×Ö
|
Decimal, // ÔÊÐíСÊýºÍÕûÊý
|
Custom // ×Ô¶¨ÒåÕýÔò
|
};
|
|
class CRegexEdit : public CEdit
|
{
|
DECLARE_DYNAMIC(CRegexEdit)
|
|
public:
|
// ¹¹ÔìÓëÎö¹¹
|
CRegexEdit();
|
virtual ~CRegexEdit();
|
|
// ÉèÖÃÕýÔòÀàÐÍ
|
void SetRegexType(RegexType enType);
|
|
// ÉèÖÃ×Ô¶¨ÒåÕýÔò±í´ïʽ
|
void SetCustomRegex(const std::string& strCustomRegex);
|
|
// ÉèÖÃÊýÖµ·¶Î§£¨ÕûÊý»ò¸¡µã£©
|
void SetValueRange(long double dMinValue, long double dMaxValue);
|
|
// ÉèÖÃ×Ô¶¨Òå±È½Ïº¯Êý
|
void SetCustomComparator(std::function<bool(const std::string&)> comparator);
|
|
// ÉèÖÃÊäÈë²»ºÏ·¨º¯Êý
|
void SetInvalidInputCallback(std::function<void()> callback);
|
|
protected:
|
// ¸ù¾Ýö¾ÙÖµ·µ»Ø¶ÔÓ¦µÄÕýÔò±í´ïʽ
|
std::regex GetCurrentRegex() const;
|
|
// УÑéÊäÈëÊÇ·ñÔÚÖ¸¶¨·¶Î§ÄÚ
|
bool IsValueInRange(const std::string& strText);
|
|
protected:
|
RegexType m_enRegexType; // µ±Ç°Ñ¡ÖеÄÕýÔòÀàÐÍ
|
std::string m_strCustomRegex; // ×Ô¶¨ÒåÕýÔò±í´ïʽ
|
long double m_dMinValue; // ×îСֵ
|
long double m_dMaxValue; // ×î´óÖµ
|
|
std::function<bool(const std::string&)> m_customComparator; // ×Ô¶¨Òå±È½Ïº¯Êý
|
std::function<void()> m_invalidInputCallback; // ²»ºÏ·¨ÊäÈëµÄ»Øµ÷º¯Êý
|
|
protected:
|
void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
|
DECLARE_MESSAGE_MAP()
|
};
|
|
#endif // !defined(AFX_REGEXEDIT_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_)
|