kicad/new/sch_dir_lib_source.h

203 lines
6.4 KiB
C
Raw Normal View History

2010-12-19 21:42:55 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
2010-12-19 21:42:55 +00:00
*
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2010 KiCad Developers, see change_log.txt for contributors.
2010-12-19 21:42:55 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef DIR_LIB_SOURCE_H_
#define DIR_LIB_SOURCE_H_
#include <set>
#include <vector>
2010-12-19 21:42:55 +00:00
2010-12-30 22:15:53 +00:00
#include <sch_lib.h>
/// This file extension is an implementation detail specific to this LIB_SOURCE
/// and to a corresponding LIB_SINK.
/// Core EESCHEMA should never have to see this.
#define SWEET_EXT ".part"
#define SWEET_EXTZ (sizeof(SWEET_EXT)-1)
2010-12-19 21:42:55 +00:00
/**
* struct BY_REV
* is here to provide a custom way to compare STRINGs. Namely, the revN[N..]
* string if present, is collated according to a 'higher revision first', but
* any part string without a revision, is even 'before' that.
2010-12-19 21:42:55 +00:00
*/
struct BY_REV
{
bool operator() ( const STRING& s1, const STRING& s2 ) const;
};
/**
* Type PART_CACHE
* holds a set of part names in sorted order, according to the sort
* order given by struct BY_REV.
*/
typedef std::set< STRING, BY_REV > PART_CACHE;
/**
* Type NAME_CACHE
* holds a set of categories in sorted order.
*/
typedef std::set< STRING > NAME_CACHE;
2010-12-19 21:42:55 +00:00
namespace SCH {
/**
* Class DIR_LIB_SOURCE
* implements a LIB_SOURCE in a file system directory.
*
* @author Dick Hollenbeck
*/
class DIR_LIB_SOURCE : public LIB_SOURCE
{
2010-12-29 20:30:45 +00:00
friend class LIB_TABLE; ///< constructor is protected, LIB_TABLE can construct
2010-12-19 21:42:55 +00:00
bool useVersioning; ///< use files with extension ".revNNN..", else not
/// normal partnames, some of which may be prefixed with a category,
/// and some of which may have legal "revN[N..]" type strings.
PART_CACHE partnames;
2010-12-23 08:40:53 +00:00
typedef PART_CACHE::const_iterator PN_ITER;
/// categories which we expect to find in the set of @a partnames
NAME_CACHE categories;
2010-12-23 08:40:53 +00:00
std::vector<char> readBuffer; ///< used by readString()
2010-12-19 21:42:55 +00:00
/**
* Function cache
* [re-]loads the directory cache(s).
*/
void cache() throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
/**
2010-12-20 17:12:41 +00:00
* Function isCategoryName
* returns true iff aName is a valid category name.
2010-12-19 21:42:55 +00:00
*/
2010-12-20 17:12:41 +00:00
bool isCategoryName( const char* aName )
{
return true;
}
2010-12-19 21:42:55 +00:00
/**
2010-12-20 17:12:41 +00:00
* Function makePartName
2010-12-19 21:42:55 +00:00
* returns true iff aEntry holds a valid part filename, in the form of
* "someroot.part[.revNNNN]" where NNN are number characters [0-9]
* @param aEntry is the raw directory entry without path information.
* @param aCategory is the last portion of the directory path.
2010-12-20 17:12:41 +00:00
* @param aPartName is where to put a part name, assuming @a aEntry is legal.
2010-12-19 21:42:55 +00:00
* @return bool - true only if aEntry is a legal part file name.
*/
2010-12-20 17:12:41 +00:00
bool makePartName( STRING* aPartName, const char* aEntry, const STRING& aCategory );
2010-12-19 21:42:55 +00:00
/**
2010-12-23 08:40:53 +00:00
* Function readString
* reads a Sweet string into aResult. Candidate for virtual function later.
*/
2010-12-23 08:40:53 +00:00
void readString( STRING* aResult, const STRING& aFileName ) throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
/**
* Function cacheOneDir
2010-12-19 21:42:55 +00:00
* loads part names [and categories] from a directory given by
* "sourceURI + '/' + category"
* Categories are only loaded if processing the top most directory because
2010-12-23 05:24:49 +00:00
* only one level of categories is supported. We know we are in the
2010-12-19 21:42:55 +00:00
* top most directory if aCategory is empty.
*/
void cacheOneDir( const STRING& aCategory ) throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
2010-12-20 17:12:41 +00:00
/**
* Function makeFileName
* converts a part name into a filename and returns it.
*/
STRING makeFileName( const STRING& aPartName );
2010-12-28 21:06:08 +00:00
protected:
2010-12-19 21:42:55 +00:00
/**
* Constructor DIR_LIB_SOURCE( const STRING& aDirectoryPath )
* sets up a LIB_SOURCE using aDirectoryPath in a file system.
2011-01-04 18:53:11 +00:00
* @see LIB_TABLE::LookupPart().
2010-12-19 21:42:55 +00:00
*
* @param aDirectoryPath is a full file pathname of a directory which contains
* the library source of part files. Examples might be "C:\kicad_data\mylib" or
* "/home/designer/mylibdir". This is not a URI, but an OS specific path that
* can be given to opendir().
*
2010-12-23 05:24:49 +00:00
* @param aOptions is the options string from the library table, currently
* the only supported option, that this LIB_SOURCE knows about is
2010-12-29 20:30:45 +00:00
* "useVersioning". If present means support versioning in the directory
2010-12-23 05:24:49 +00:00
* tree, otherwise only a single version of each part is recognized, namely the
* one without the ".revN[N..]" trailer.
2010-12-19 21:42:55 +00:00
*/
2010-12-28 21:06:08 +00:00
DIR_LIB_SOURCE( const STRING& aDirectoryPath, const STRING& aOptions = "" ) throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
~DIR_LIB_SOURCE();
//-----<LIB_SOURCE implementation functions >------------------------------
void ReadPart( STRING* aResult, const STRING& aPartName, const STRING& aRev = "" )
throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
void ReadParts( STRINGS* aResults, const STRINGS& aPartNames )
throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
void GetCategories( STRINGS* aResults ) throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
void GetCategoricalPartNames( STRINGS* aResults, const STRING& aCategory = "" )
throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
2011-01-03 17:47:08 +00:00
void GetRevisions( STRINGS* aResults, const STRING& aPartName )
throw( IO_ERROR );
2010-12-19 21:42:55 +00:00
void FindParts( STRINGS* aResults, const STRING& aQuery ) throw( IO_ERROR )
2010-12-19 21:42:55 +00:00
{
// @todo
2010-12-19 21:42:55 +00:00
}
//-----</LIB_SOURCE implementation functions >------------------------------
#if defined(DEBUG)
2010-12-19 21:42:55 +00:00
/**
* Function Show
* will output a debug dump of contents.
*/
void Show();
2010-12-28 21:06:08 +00:00
public:
static void Test( int argc, char** argv );
#endif
2010-12-19 21:42:55 +00:00
};
} // namespace SCH
#endif // DIR_LIB_SOURCE_H_