00001
00060 #include "utils.hpp"
00061
00062 #include <stdexcept>
00063 #include <istream>
00064
00065
00066 #include <string>
00067
00068 #include <boost/shared_ptr.hpp>
00069 #include <boost/make_shared.hpp>
00070
00071 #ifndef NEBULAR_HPP_
00072 #define NEBULAR_HPP_
00073
00077
00092 namespace libnebular{
00097 typedef long long int Integer;
00098
00099 typedef long double Real;
00100
00105 typedef std::string String;
00106
00110 namespace bits{
00112 const Integer HAVE_NOT = -1;
00114 const Integer ARE_NOT_CONTIG = HAVE_NOT;
00115
00121 template <typename BitContainer>
00122 Integer getContigLength(BitContainer a);
00123
00125 template <typename BitContainer>
00126 bool areContig(BitContainer a);
00127
00129 template <typename BitContainer>
00130 bool areSubsetOf(BitContainer a, BitContainer b);
00131
00133 template <typename BitContainer>
00134 BitContainer generateContig(Integer length);
00135
00139 template <typename BitContainer>
00140 Integer getHighestBitIndex(BitContainer a);
00141 }
00142
00159 class Blob{
00160 private:
00161 struct Impl_;
00162 boost::shared_ptr<Impl_> pimpl_;
00163
00164
00165
00166
00167 public:
00169 char *getDataReadWrite();
00171 const char *getDataReadOnly() const;
00175 size_t getDataHash() const;
00177 Integer getDataRoom() const;
00181 void setDataSize(Integer newSize);
00183 Integer getDataSize() const;
00184
00186 void mAlloc(Integer newSize);
00188 void attach(void *newMemory, Integer newDataRoom);
00194 void prepareForSize(Integer newDataSize);
00196 bool isCanBeReroomed() const;
00197
00201 void assign(Integer newSize, const char* newData);
00203 bool isSubseqFromCurPos(std::istream &inStream) const;
00204
00206 void cleanupData();
00207
00213 void forsakeData();
00214
00216 Blob(Integer newSize, const char* newData);
00217 Blob();
00218 ~Blob();
00219
00221 static Blob createAndMAlloc(Integer newSize);
00223 static Blob createAndAttach(void *newMemory, Integer newDataRoom);
00224 };
00225
00233 class Error: public std::runtime_error{
00234 protected:
00235 Error(const std::string& msg = "");
00236 };
00237
00238 class PluginIterator;
00239 class PluginIteratorImpl_;
00240
00256 class Core{
00257 private:
00259 Core &operator=(const Core &);
00261 Core(const Core &);
00262
00263 struct Impl_;
00264 boost::shared_ptr<Impl_> pimpl_;
00265
00267 friend PluginIterator pluginBegin();
00269 friend PluginIterator pluginEnd();
00270
00271
00272
00273
00274
00275 friend class PluginIteratorImpl_;
00276 public:
00278 Core();
00280 ~Core();
00281
00283 void setPluginDir(const std::string &newPluginDir);
00285 void registerPlugins();
00287 bool isPluginRegDone() const;
00289 void makePluginsRegistered();
00290
00292 static Core &get();
00293 };
00294
00302 class LogListener{
00303 public:
00304 typedef void (*CallbackFunctionStr)(const std::string&);
00305
00307 static void setWarningCallback(CallbackFunctionStr newWarningCallback);
00309 static void setInfoCallback(CallbackFunctionStr newInfoCallback);
00310
00311 #if HAVE_LOKI_FUNCTOR_H
00312 typedef Loki::Functor<void, LOKI_TYPELIST_1(const std::string&)> CallbackStr;
00313
00315 static void setWarningCallback(CallbackStr newWarningCallback);
00317 static void setInfoCallback(CallbackStr newWarningCallback);
00318 #endif
00319
00321 static void emptyCallbackFunctionStr(const std::string &message);
00322 };
00323
00379 class PicturePropContainer{
00380 private:
00382 PicturePropContainer(const PicturePropContainer &);
00384 PicturePropContainer &operator=(const PicturePropContainer &);
00385
00387 class Impl_;
00388 class DefaultImpl_;
00389 class SubtreeProxyImpl_;
00390 boost::shared_ptr<Impl_> pimpl_;
00391
00392 template <class PicturePropContainerBased>
00393 friend boost::shared_ptr<PicturePropContainerBased>
00394 createSubtreeProxy(
00395 PicturePropContainer &realSubject,
00396 const String &subTreePrefix
00397 );
00398
00399 friend void setDefault(
00400 PicturePropContainer &p,
00401 const String &key,
00402 const String &value
00403 );
00404 public:
00408 class PropKeyIterator: public std::iterator<
00409 std::forward_iterator_tag,
00410 const String
00411 >{
00412 private:
00413 struct Impl_;
00414 boost::shared_ptr<Impl_> pimpl_;
00415
00416 friend class PicturePropContainer::DefaultImpl_;
00417 public:
00418
00419 PropKeyIterator();
00420 ~PropKeyIterator();
00421 PropKeyIterator(const PropKeyIterator &);
00422 PropKeyIterator &operator=(const PropKeyIterator &);
00423
00424 PropKeyIterator &operator++();
00425 PropKeyIterator operator++(int);
00426 bool operator!=(const PropKeyIterator &) const;
00427 bool operator==(const PropKeyIterator &) const;
00428
00429 value_type &operator*();
00430 value_type *operator->();
00431 };
00433 PropKeyIterator propKeyBegin();
00435 PropKeyIterator propKeyEnd();
00436
00438 template <typename Src> static String castToPropString(const Src &value);
00440
00441
00442 static String castToPropString(
00443 const char *value
00444 );
00445
00447 template <typename Dest> static Dest castFromPropString(const String &value);
00448
00452 template <typename R> void set(const String &key, const R &value);
00458 template <typename R> const R get(const String &key) const;
00460 template <typename R> void get(const String &key, R &value) const;
00461
00465 void unSet(const String &key);
00466
00467 bool isSet(const String &key) const;
00469 bool isDefault(const String &key) const;
00470
00473
00474
00478 void move(const String &srcKey, const String &destKey);
00479
00481 void acceptOpt(const String &acceptedKey);
00483 bool isSetAndTrue(const String& key) const;
00485 template <typename Value>
00486 void swap(const String &keyA, const String &keyB);
00487
00489 template <typename Value>
00490 void copyFromIfSet(const String &key, const PicturePropContainer &src);
00492 void setDefaultIfNotSet(const String &key, const String &defaultValue);
00493
00495
00496 PicturePropContainer();
00497 virtual ~PicturePropContainer();
00498
00499 };
00500
00502 template<> String PicturePropContainer::castToPropString(const bool& arg);
00504 template<> bool PicturePropContainer::castFromPropString(const String& arg);
00505
00506 template<> const String PicturePropContainer::get<>(const String &key) const;
00508 template<> void PicturePropContainer::set<>(const String &key, const String &value);
00509 template<> const Blob PicturePropContainer::get<>(const String &key) const;
00511 template<> void PicturePropContainer::set<>(const String &key, const Blob &value);
00512
00521 class PictureProps: public PicturePropContainer{
00522 private:
00524 PictureProps(const PictureProps &);
00526 PictureProps &operator=(const PictureProps &);
00527
00528 struct Impl_;
00529 boost::shared_ptr<Impl_> pimpl_;
00530
00531 public:
00532 PictureProps();
00533 ~PictureProps();
00534
00535 class PropBmInfo;
00536 class PropBmData;
00537 class PropBmPixelFormat;
00538 class PropBmPixelsPerLength;
00539 class PropBmMiscStorageParams;
00540 class PropBmMiscDisplayParams;
00541 class PropCalcBmDataSize;
00542 class PropCalcBmSizeLengthUnits;
00543 class PropCalcBmPixelMaskMisc;
00544 class PropCalcBmColorsUsed;
00545
00553 template <typename T> void check();
00554
00558 void setDefaults();
00560 void checkUnusedOpts();
00561
00567 template <typename T> void calculate();
00568
00573
00601 void reproduce(PictureProps &src);
00602
00607 void prepareReproduceBmInfo(PictureProps &src);
00608
00609 };
00610
00612 #if !PROCESSED_BY_DOXYGEN
00613
00614 template <> void PictureProps::check<PictureProps::PropBmInfo>();
00615 template <> void PictureProps::check<PictureProps::PropBmData>();
00616 template <> void PictureProps::check<PictureProps::PropBmPixelFormat>();
00617 template <> void PictureProps::check<PictureProps::PropBmPixelsPerLength>();
00618 template <> void PictureProps::check<PictureProps::PropBmMiscStorageParams>();
00619 template <> void PictureProps::check<PictureProps::PropBmMiscDisplayParams>();
00620
00621 template <> void PictureProps::calculate<PictureProps::PropCalcBmSizeLengthUnits>();
00622 template <> void PictureProps::calculate<PictureProps::PropCalcBmPixelMaskMisc>();
00623 template <> void PictureProps::calculate<PictureProps::PropCalcBmDataSize>();
00624
00625 template <> void PictureProps::calculate<PictureProps::PropCalcBmColorsUsed>();
00626 #endif // PROCESSED_BY_DOXYGEN
00627
00648 class Picture: public PictureProps{
00649 private:
00651 Picture(const Picture &);
00653 Picture &operator=(const Picture &);
00654
00655 struct Impl_;
00656 boost::shared_ptr<Impl_> pimpl_;
00657
00658 public:
00660 bool haveHandler() const;
00661
00670
00671
00672
00674 void attachHandlerByFileExt();
00676 void attachHandlerByContentMagic();
00678 void attachHandlerForWrite();
00680 void attachHandlerSomehow();
00682 void makeHandlerSomehowAttached();
00683
00685
00689 void readFileInfo();
00690
00694 void readBm();
00695
00699 void write();
00700
00701 ~Picture();
00702 Picture();
00703 Picture(const String& newUrl);
00704 };
00705
00713 template <class PicturePropContainerBased>
00714 boost::shared_ptr<PicturePropContainerBased>
00715 createSubtreeProxy(
00716 PicturePropContainer &realSubject,
00717 const String &subTreePrefix
00718 );
00719 }
00720
00781 #include "libnebular.templates.hpp"
00782
00783 #endif //NEBULAR_HPP_
00784