Click here to Skip to main content
15,883,606 members
Articles / Desktop Programming / MFC

Be Sweet - a set of visual source code browsers

Rate me:
Please Sign up or sign in to vote.
4.85/5 (35 votes)
1 Jul 20038 min read 183.7K   4.9K   122  
A set of source code and project browsers to compliment Visual Studio.
/**
/*   Copyright (c) 2003by  Marco Welti
/*
/*   This document is  bound by the  QT Public License
/*   (http://www.trolltech.com/licenses/qpl.html).
/*   See License.txt for more information.
/*
/*
/*
/*   ALL RIGHTS RESERVED.  
/* 
/*   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
/*   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
/*   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
/*   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
/*   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
/*   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
/*   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
/*   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
/*   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
/*   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
/*   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* 
/***********************************************************************/

#ifndef Database_H
#define Database_H

#pragma warning( disable: 4800 )

#include <string>
#include <list>
#include <set>
#include <map>
#include <functional>
#include "stl_ext.h"

#include <Model/CTags/CTagsTag.h>
#include <Model/Workspace.h>

namespace CTags {


class Database
{
public:
  typedef std::list<CTags::Tag> TagTable;

private:
  std::string mName;
  TagTable mTags;

public:
  Database() {};
  Database(const std::string& name);
  Database(const std::list<std::string>& files);
  Database(const Workspace& workspace);


  template<class QueryType>
	TagTable selectTagsWhere(const QueryType &query)
	{
		TagTable result;
		copy_if(mTags.begin(), mTags.end(), std::inserter(result, result.end()), query);
		return result;
	}

  void refreshTagsReferencingFile(const std::string&);

private:
  const TagTable& getTags() const { return mTags; }
  void createTagFile(const std::list<std::string>&, const std::string&);
  void eraseTagsReferencingFile(const std::string&);
  TagTable loadTags(const std::string&);
  void setupTagTable(const std::list<std::string>&files);
};

template<class QueryType, class ArgumentType>
std::binder2nd<QueryType> make_query(const QueryType &query, const ArgumentType &arg)
{
  return std::bind2nd(query, arg);
}

struct TypeIs : public std::binary_function<CTags::Tag, int, bool>
{
	const static int ANY_TYPE;
		
	bool operator()(const first_argument_type &tag, second_argument_type type) const
	{ return static_cast<bool>(tag.getType() & type); }
};

struct ScopeTypeIs : public std::binary_function<CTags::Tag, int, bool>
{
  bool operator()(const first_argument_type &tag, const second_argument_type &type) const
  { return static_cast<bool>(tag.getScopeType() & type); }
};

struct FileIs : public std::binary_function<CTags::Tag, std::string, bool>
{
	bool operator()(const first_argument_type &tag, const second_argument_type &file) const
	{ return tag.getFile()  == file; }
};

struct ScopeOrNameIs : public std::binary_function<CTags::Tag, std::string, bool>
{
	bool operator()(const first_argument_type &tag, const second_argument_type &id) const
	{ return tag.getFQN().scope() == id || tag.getFQN().name() == id; }
};

struct NameIs : public std::binary_function<CTags::Tag, std::string, bool>
{
	bool operator()(const first_argument_type &tag, const second_argument_type &id) const
	{ return tag.getFQN().name() == id; }
};

struct ScopeNameIs : public std::binary_function<CTags::Tag, std::string, bool>
{
	bool operator()(const first_argument_type &tag, const second_argument_type &id) const
	{ return tag.getFQN().scope() == id; }
};

struct FullQualifiedNameIs : public std::binary_function<CTags::Tag, FullQualifiedName, bool>
{
	result_type operator()(const first_argument_type &tag, const second_argument_type &fqn) const
	{ return tag.getFQN() == fqn; }
};

class DatabaseManager
{
private:
  typedef  std::map<std::string, smart_ptr<Database> > DBMap;

  DBMap mManagedDatabases;

public:
  static DatabaseManager& instance();

  smart_ptr<Database> getDatabase(const smart_ptr<Workspace> &);
  smart_ptr<Database> removeDatabase(const smart_ptr<Workspace> &);

private:
  DatabaseManager();
};

} // namespace CTags
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions