visitor

Why can't I visit this custom type with boost::variant?

雨燕双飞 提交于 2019-12-01 06:20:41
问题 The following code: #include <boost/variant.hpp> #include <iostream> #include <string> struct A { A() { } ~A() throw() { } A& operator=(A const & rhs) { return *this; } bool operator==(A const & rhs) { return true; } bool operator<(A const & rhs) { return false; } }; std::ostream & operator<<(std::ostream & os, A const & rhs) { os << "A"; return os; } typedef boost::variant<int, std::string, A> message_t; struct dispatcher_t : boost::static_visitor<> { template <typename T> void operator()(T

Implementing a visitor counter

半城伤御伤魂 提交于 2019-11-30 22:06:21
I am a newbie and developing a website using ASP .Net 2.0 with C# 2005. I would like to add a facility to count the no. of visitors to my website. I have collected the basic informations to add this feature using Global.asax. I have made modifications to Web.config by adding the line "" under system.web section. I am using a table to keep the count of visitors. But I don't know how to complete the task. My default Global.asax file came with different sections Application_Start, Application_End, Application_Error, Session_Start and Session_End. I have tried to extract the current value of the

Using 'dynamic' in C# to implement Visitor Pattern

六眼飞鱼酱① 提交于 2019-11-30 18:16:35
I have an application where I am performing an operation on a series of elements and the exact nature of the operation depends on the type of the element being operated upon. For reasons of encapsulation, it's not appropriate for the element to implement the operation; this means it can't be a virtual method on the element type and so 'standard' polymorphism doesn't work. I posed a previous question related to this and was informed that this was known as the Visitor Pattern. I had previously always implemented this using an if/elseif dispatcher method based on the type of the object, then

Using 'dynamic' in C# to implement Visitor Pattern

泪湿孤枕 提交于 2019-11-30 16:50:15
问题 I have an application where I am performing an operation on a series of elements and the exact nature of the operation depends on the type of the element being operated upon. For reasons of encapsulation, it's not appropriate for the element to implement the operation; this means it can't be a virtual method on the element type and so 'standard' polymorphism doesn't work. I posed a previous question related to this and was informed that this was known as the Visitor Pattern. I had previously

Implementing a visitor counter

∥☆過路亽.° 提交于 2019-11-30 05:44:12
问题 I am a newbie and developing a website using ASP .Net 2.0 with C# 2005. I would like to add a facility to count the no. of visitors to my website. I have collected the basic informations to add this feature using Global.asax. I have made modifications to Web.config by adding the line "" under system.web section. I am using a table to keep the count of visitors. But I don't know how to complete the task. My default Global.asax file came with different sections Application_Start, Application

Alternative to the visitor pattern?

ぐ巨炮叔叔 提交于 2019-11-29 19:40:21
I am looking for an alternative to the visitor pattern. Let me just focus on a couple of pertinent aspects of the pattern, while skipping over unimportant details. I'll use a Shape example (sorry!): You have a hierarchy of objects that implement the IShape interface You have a number of global operations that are to be performed on all objects in the hierarchy, e.g. Draw, WriteToXml etc... It is tempting to dive straight in and add a Draw() and WriteToXml() method to the IShape interface. This is not necessarily a good thing - whenever you wish to add a new operation that is to be performed on

C++ template to cover const and non-const method

怎甘沉沦 提交于 2019-11-29 11:36:55
问题 I have a problem with duplication of identical code for const and non- const versions. I can illustrate the problem with some code. Here are two sample visitors, one which modifies the visited objects and one which does not. struct VisitorRead { template <class T> void operator()(T &t) { std::cin >> t; } }; struct VisitorWrite { template <class T> void operator()(const T &t) { std::cout << t << "\n"; } }; Now here is an aggregate object - this has just two data members but my actual code is

Refactoring Code to avoid Type Casting

可紊 提交于 2019-11-28 08:45:22
I have following C# code in .Net 4.0. It requires a type casting of IBusiness to IRetailBusiness. //Type checking if (bus is IRetailBusiness) { //Type casting investmentReturns.Add(new RetailInvestmentReturn((IRetailBusiness)bus)); } if (bus is IIntellectualRights) { investmentReturns.Add(new IntellectualRightsInvestmentReturn((IIntellectualRights)bus)); } Business Scenario: I am designing a software system for and Investment Holding Company. The company has Retail business and IntellectualRights business. BookShop and AudioCDShop are examples of Retail business. EngineDesignPatent and

need a virtual template member workaround

假如想象 提交于 2019-11-28 06:54:05
I need to write a program implementing the visitor design pattern. The problem is that the base visitor class is a template class. This means that BaseVisited::accept() takes a template class as a parameter and since it uses 'this' and i need 'this' to point to the correct runtime instance of the object, it also needs to be virtual. I'd like to know if there's any way around this problem. template <typename T> class BaseVisitor { public: BaseVisitor(); T visit(BaseVisited *visited); virtual ~BaseVisitor(); } class BaseVisited { BaseVisited(); template <typename T> virtual void accept

How to write the Visitor Pattern for Abstract Syntax Tree in Python?

五迷三道 提交于 2019-11-28 05:00:55
My collegue suggested me to write a visitor pattern to navigate the AST. Can anyone tell me more how would I start writing it? As far as I understand, each Node in AST would have visit() method (?) that would somehow get called (from where?). That about concludes my understanding. To simplify everything, suppose I have nodes Root , Expression , Number , Op and the tree looks like this: Root | Op(+) / \ / \ Number(5) \ Op(*) / \ / \ / \ Number(2) Number(444) Can anyone think of how the visitor pattern would visit this tree to produce output: 5 + 2 * 444 Thanks, Boda Cydo. Wikipedia has a great