⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tdc_base.h

📁 是一个手机功能的模拟程序
💻 H
📖 第 1 页 / 共 5 页
字号:
{
	TDC_RW_MODE_READ,
	TDC_RW_MODE_WRITE
};

struct T_TDC_HANDLE_BASE
{
  friend struct T_TDC_COPY;
protected:
  T_TDC_ACTION_ENUM implement_get_action () const;
  void implement_set_action (T_TDC_ACTION_ENUM action_);
  T_TDC_DESCRIPTOR_BASE* implement_get_descriptor () const;
  void implement_set_descriptor (T_TDC_DESCRIPTOR_BASE* descriptor_);
  long implement_get_value () const;
  void implement_set_value (long value_);
  friend void add_name_info (T_TDC_HANDLE_BASE* descriptor_ref, int level, int parent, int index);
  T_TDC_PATH_TEXT path_text();
  virtual T_TDC_DESCRIPTOR_BASE* implement_new_descriptor () const;
public:
  T_TDC_DESCRIPTOR_BASE* make_descriptor ();
  T_TDC_DESCRIPTOR_BASE* make_array_descriptor (T_TDC_NEW_HANDLE new_element_handle);
  virtual char* get_name () const
  TDC_PURE_BODY({
    //TDC_ERROR();
    return 0;
  })
  virtual long get_sizeof () = 0
  {
    return sizeof *this;
  }
  T_TDC_HANDLE_BASE ();
  ~T_TDC_HANDLE_BASE ();
  T_TDC_HANDLE_BASE* get_element (int index)const;
  T_TDC_HANDLE_BASE* get_union_element ();
  void destroy ();
  T_TDC_DESCRIPTOR_BASE* get_descriptor()const;
  T_TDC_ACTION_ENUM get_action()const;
  long get_value()const;
  int get_ctrl()const;
  void clear();
  void set_descriptor_value(long value_);
  virtual unsigned get_sizeof_target ()
  {
    TBD;
    return 1;
  }
  virtual T_TDC_IS_ENUM is ()
  {
    //TODO: TDC_ERROR here and mov is function to distinct base classes;
    return TDC_IS_UNKNOWN;
  }
};

#ifdef TDC_USE_ALLOC_DEBUG_COUNTER
struct T_TDC_ALLOC_DEBUG_COUNTER 
{
	int count;
	int max_count;
	int alloc_count;
	int free_count;
	bool alloc[1000];
	T_TDC_ALLOC_DEBUG_COUNTER ()
	{
    /* nothing here should allways be static allocated and there for cleared, 
      futher more it is used before construction so intializing here will be fatal */
	}
	~T_TDC_ALLOC_DEBUG_COUNTER ()
	{
		for (int first_not_freed = 0; !alloc[first_not_freed]; first_not_freed++)
			assert (first_not_freed < sizeof alloc);
		assert (count==0); // some where we have a leak
	}
};

template<class T>
struct T_TDC_ALLOC_DEBUG 
{
	static T_TDC_ALLOC_DEBUG_COUNTER counter;
	int alloc_count;
	T_TDC_ALLOC_DEBUG_COUNTER& counter_;
	T_TDC_ALLOC_DEBUG ():
		counter_ (counter)
	{
	  counter.count++;
	  alloc_count = counter.alloc_count++;
    if (alloc_count < sizeof counter.alloc)
	    counter.alloc[alloc_count]=true;
	  if (counter.max_count < counter.count)
		  counter.max_count = counter.count;
	}
	~T_TDC_ALLOC_DEBUG ()
	{
    if (alloc_count < sizeof counter.alloc)
		  counter.alloc[alloc_count]=false;
		assert (counter.count > 0); // deallocating more than ever allocated
		counter.free_count++;
		counter.count--;
	}
};

template<class T>T_TDC_ALLOC_DEBUG_COUNTER T_TDC_ALLOC_DEBUG<T>::counter;
#endif

enum { 
	TDC_CTRL_DEFAULT = 0,
	TDC_CTRL_NO_DESCRIPTOR = -1,
	TDC_CTRL_NOT_AN_UNION = -2,
	TDC_REF_COUNT_ELEMENTS_DESTROYED = -2,
	TDC_DESCRIPTOR_DESTROYED_VALUE = -4,
	TDC_DUMMY_TAP_HANDLE = -16
};

#define TDC_DESCRIPTOR_DESTROYED ((T_TDC_DESCRIPTOR_BASE*)TDC_DESCRIPTOR_DESTROYED_VALUE)

struct T_TDC_DESCRIPTOR_BASE
#ifdef TDC_USE_ALLOC_DEBUG_COUNTER
	:T_TDC_ALLOC_DEBUG<T_TDC_DESCRIPTOR_BASE>
#endif
{
private:
  friend struct T_TDC_COPY;
	friend void unsubscribe (T_TDC_DESCRIPTOR_BASE* descriptor);
	int ref_count;
	virtual long get_sizeof () 
	TDC_PURE_BODY(
		return 0;
	)

	void destroy_elements ();
protected:
	T_TDC_HANDLE_BASE* implement_get_element (unsigned index, char *first_element);
	T_TDC_HANDLE_BASE* implement_get_union_element (unsigned index, int& ctrl);
public:
	void *operator new (size_t size);//TODO: operator new (size_t size); + eliminate T_TDC_HANDLE_BASE::T_TDC_HANDLE_BASE i.e. todo T_TDC_HANDLE_BASE::operator new (size_t size);
	T_TDC_PATH_TEXT path_text();
	virtual int read_ctrl () const
	{
		return TDC_CTRL_NOT_AN_UNION;
	}
	virtual void set_skip_to_end (bool skip_to_end);
	virtual bool get_skip_to_end () const;
  virtual T_TDC_HANDLE_BASE* make_element (unsigned index);
	virtual T_TDC_HANDLE_BASE* get_element (unsigned index);
	virtual int get_tap_handle ();
	T_TDC_DESCRIPTOR_BASE ();
	virtual ~T_TDC_DESCRIPTOR_BASE ();
	virtual char* get_name () const
	TDC_PURE_BODY(
		return 0;
	)
	virtual T_TDC_IS_ENUM is ()
	{
		//TODO: TDC_ERROR() here and mov is function to distinct base classes;
		return TDC_IS_UNKNOWN;
	}
};

union T_TDC_BASIC_TYPES 
{
	unsigned long u32;
	signed long s32;
	signed int s16;
	signed char s8;
	char c[4];
};

//----------------------------------------------------------------------------

struct T_TDC_INTERFACE_BASE
{
private:
	void operator &(); /* this member function is only here to prevent the user from taking the address of 
					an interface, which make no sence to the user as it gives the address of
					some internal tdc navigation data */
protected:
	T_TDC_LEVEL level[1];
	T_TDC_ASSIGN_ACTION set_action (const T_TDC_ACTION& action_);
	T_TDC_INTERFACE_BASE ()
	{
		//nothing
	}
public:
	T_TDC_PATH* implement_make_descriptor_ref (T_TDC_RW_MODE rw_mode);
	T_TDC_PATH* make_descriptor_ref (T_TDC_RW_MODE rw_mode);
	const T_TDC_PATH* make_descriptor_ref (T_TDC_RW_MODE rw_mode) const;
	void set_descriptor_value (long value_); 
	void copy_instance (const T_TDC_INSTANCE_BASE * value_);
	void copy_interface (const T_TDC_INTERFACE_BASE * value_);
};

struct T_TDC_INTERFACE_MAIN_BASE
#if DOT_COMPLETE_MEMBERS
#else
	TDC_DOT_COMPLETE_HIDE(:T_TDC_INTERFACE_BASE)
#endif
{
#if DOT_COMPLETE_MEMBERS
#else
protected:
	void set_main_value (const T_TDC_INTERFACE_MAIN_BASE* value_);
	void set_main_value (const T_TDC_INSTANCE_MAIN_BASE* value_);
	T_TDC_INTERFACE_BASE* get_element_navigation(T_TDC_NEW_INTERFACE new_element_interface);
	/*T_TDC_INTERFACE_MAIN_BASE ()
	{
		tdc_level++;
	}*/
#endif
};

struct T_TDC_INTERFACE_REF_BASE
#if DOT_COMPLETE_MEMBERS
#else
	TDC_DOT_COMPLETE_HIDE(:T_TDC_INTERFACE_BASE)
#endif
{
#if DOT_COMPLETE_MEMBERS
	T_TDC_ASSIGN_ACTION _skip () {} /* you can use '= SKIP' as well */
	T_TDC_ASSIGN_ACTION _show () {} /* you can use '= SHOW' as well */
	T_TDC_ASSIGN_ACTION _forbid () {} /* you can use '= FORBID' as well */
	T_TDC_ASSIGN_ACTION _require () {} /* you can use '= REQUIRE' as well */
#else//DOT_COMPLETE_MEMBERS
	TDC_DOT_COMPLETE_HIDE(T_TDC_ASSIGN_ACTION tdc_skip ();) /* you can use '= SKIP' as well */
	TDC_DOT_COMPLETE_HIDE(T_TDC_ASSIGN_ACTION tdc_show ();) /* you can use '= SHOW' as well */
	TDC_DOT_COMPLETE_HIDE(T_TDC_ASSIGN_ACTION tdc_forbid ();) /* you can use '= FORBID' as well */
	TDC_DOT_COMPLETE_HIDE(T_TDC_ASSIGN_ACTION tdc_require ();) /* you can use '= REQUIRE' as well */
#endif//DOT_COMPLETE_MEMBERS
};

struct T_TDC_INTERFACE_VAR_BASE
#if DOT_COMPLETE_MEMBERS
#else
	TDC_DOT_COMPLETE_HIDE(:T_TDC_INTERFACE_BASE)
#endif
{
#if DOT_COMPLETE_MEMBERS
	T_TDC_ASSIGN_ACTION _skip () {} /* you can use '= SKIP' as well */
	T_TDC_ASSIGN_ACTION _show () {} /* you can use '= SHOW' as well */
	T_TDC_ASSIGN_ACTION _forbid () {} /* you can use '= FORBID' as well */
	T_TDC_ASSIGN_ACTION _require () {} /* you can use '= REQUIRE' as well */
#else//DOT_COMPLETE_MEMBERS
	TDC_DOT_COMPLETE_HIDE(T_TDC_ASSIGN_ACTION tdc_skip ();) /* you can use '= SKIP' as well */
	TDC_DOT_COMPLETE_HIDE(T_TDC_ASSIGN_ACTION tdc_show ();) /* you can use '= SHOW' as well */
	TDC_DOT_COMPLETE_HIDE(T_TDC_ASSIGN_ACTION tdc_forbid ();) /* you can use '= FORBID' as well */
	TDC_DOT_COMPLETE_HIDE(T_TDC_ASSIGN_ACTION tdc_require ();) /* you can use '= REQUIRE' as well */
#endif//DOT_COMPLETE_MEMBERS
};

//----------------------------------------------------------------------------

#if TDC_DEBUG_DOT_COMPLETE
void F_TDC_DEBUG_DOT_COMPLETE__TDC_H_1K()
{
  T_TDC_DEBUG_DOT_COMPLETE__TDC_H_1 s;
  s.
    i;
}
#else
#endif

//----------------------------------------------------------------------------

struct T_TDC_PATH
#ifdef TDC_USE_ALLOC_DEBUG_COUNTER
	:T_TDC_ALLOC_DEBUG<T_TDC_PATH>
#endif
{
	T_TDC_HANDLE_BASE* handle;
	T_TDC_DESCRIPTOR_BASE* cahed_descriptor;
	int indexes_count;
  union{
    int *indexes;
    struct T_WATCH_INDEXES{
      int i0,i1,i2,i3,i4,i5,i6,i7,i8,i9;
    }*watch_indexes;
  };
	T_TDC_INTERFACE_BASE* pattern;
	T_TDC_PATH* next;
	T_TDC_PATH (T_TDC_HANDLE_BASE* handle_);
	~T_TDC_PATH ();
	void add_index(T_TDC_DESCRIPTOR_BASE* descriptor, int index);
	void add_to_cashed_path_list ();
	T_TDC_HANDLE_BASE* get_leaf();
	T_TDC_PATH_TEXT get_path_text ();
	T_TDC_PATH* duplicate()const;
};

//----------------------------------------------------------------------------

#if TDC_DEBUG_DOT_COMPLETE
void F_TDC_DEBUG_DOT_COMPLETE__TDC_H_1L()
{
  T_TDC_DEBUG_DOT_COMPLETE__TDC_H_1 s;
  s.
    i;
}
#else
#endif

//----------------------------------------------------------------------------

struct const_T_TDC_COPY
{
	T_TDC_HANDLE_BASE* descriptor_ref;
	const T_TDC_PATH* path;
	const_T_TDC_COPY (const T_TDC_PATH* path_):
		descriptor_ref (const_cast<T_TDC_PATH*>(path_)->get_leaf()),
		path (path_)
	{
	}
	const_T_TDC_COPY (const T_TDC_HANDLE_BASE* descriptor_ref_):
		descriptor_ref (const_cast<T_TDC_HANDLE_BASE*>(descriptor_ref_)),
		path (0)
	{
	}
	const_T_TDC_COPY (const const_T_TDC_COPY& src):
		descriptor_ref (src.descriptor_ref),
		path (0)
	{
		if (src.path)
			path = src.path->duplicate();
	}
	void operator = (const const_T_TDC_COPY& src)
	{
		descriptor_ref = src.descriptor_ref;
		if (path)
			delete path;
		if (src.path)
			path = src.path->duplicate();
		else
			path = 0;
	}
	const T_TDC_HANDLE_BASE* operator->()
	{
		return descriptor_ref;
	}
	operator const T_TDC_HANDLE_BASE*()const
	{
		return descriptor_ref;
	}
	~const_T_TDC_COPY ()
	{
		if (path)
			delete path;
	}
	T_TDC_PATH_TEXT path_text ();
};

struct T_TDC_COPY:const_T_TDC_COPY
{
	friend struct T_TDC_COPY;
	T_TDC_COPY (T_TDC_PATH* path_):
		const_T_TDC_COPY (path_)
	{
	}
	T_TDC_COPY (T_TDC_HANDLE_BASE* descriptor_ref_):
		const_T_TDC_COPY (descriptor_ref_)
	{
	}
	T_TDC_HANDLE_BASE* operator->()
	{
		return descriptor_ref;
	}
	operator T_TDC_HANDLE_BASE*()const
	{
		return descriptor_ref;
	}
	void copy_descriptor_ref (const const_T_TDC_COPY& value_);
	void copy_number (long value_);
	T_TDC_ASSIGN_ACTION copy_action (T_TDC_ACTION_ENUM action_);
  void set_action_and_value (T_TDC_ACTION_ENUM action_, long value_=0xFCFCFCFC);
};

//----------------------------------------------------------------------------

/*
	T_TDC_PATH_TEXT
		is used to return a string on the heap that will auto dealloc
		e.g.
		
		T_TDC_PATH_TEXT f()
		{
			return strdup ("...");
		}

		void g()
		{
			printf ("%s", f()); // free of string allocated in f() w

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -