repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
GiulioPN/bnlm
src/hpyplm.h
#ifndef HPYPLM_H_ #define HPYPLM_H_ #include <vector> #include <unordered_map> #include "m.h" #include "random.h" #include "crp.h" #include "tied_parameter_resampler.h" #include "uvector.h" #include "uniform_vocab.h" // A not very memory-efficient implementation of an N-gram LM based on PYPs // as described in <NAME>. (2006) A Hierarchical Bayesian Language Model // based on Pitman-Yor Processes. In Proc. ACL. namespace cpyp { template <unsigned N> struct PYPLM; template<> struct PYPLM<0> : public UniformVocabulary { PYPLM(unsigned vs, double a, double b, double c, double d) : UniformVocabulary(vs, a, b, c, d) {} }; // represents an N-gram LM template <unsigned N> struct PYPLM { PYPLM() : backoff(0,1,1,1,1), tr(1,1,1,1,0.8,0.0), lookup(N-1) {} explicit PYPLM(unsigned vs, double da = 1.0, double db = 1.0, double ss = 1.0, double sr = 1.0) : backoff(vs, da, db, ss, sr), tr(da, db, ss, sr, 0.8, 0.0), lookup(N-1) {} template<typename Engine> void increment(unsigned w, const std::vector<unsigned>& context, Engine& eng) { const double bo = backoff.prob(w, context); for (unsigned i = 0; i < N-1; ++i) lookup[i] = context[context.size() - 1 - i]; auto it = p.find(lookup); if (it == p.end()) { it = p.insert(make_pair(lookup, crp<unsigned>(0.8,0))).first; tr.insert(&it->second); // add to resampler } if (it->second.increment(w, bo, eng)) backoff.increment(w, context, eng); } template<typename Engine> void decrement(unsigned w, const std::vector<unsigned>& context, Engine& eng) { for (unsigned i = 0; i < N-1; ++i) lookup[i] = context[context.size() - 1 - i]; auto it = p.find(lookup); assert(it != p.end()); if (it->second.decrement(w, eng)) backoff.decrement(w, context, eng); } double prob(unsigned w, const std::vector<unsigned>& context) const { const double bo = backoff.prob(w, context); for (unsigned i = 0; i < N-1; ++i) lookup[i] = context[context.size() - 1 - i]; auto it = p.find(lookup); if (it == p.end()) return bo; return it->second.prob(w, bo); } double log_likelihood() const { return backoff.log_likelihood() + tr.log_likelihood(); } template<typename Engine> void resample_hyperparameters(Engine& eng) { tr.resample_hyperparameters(eng); backoff.resample_hyperparameters(eng); } template<class Archive> void serialize(Archive& ar, const unsigned int version) { backoff.serialize(ar, version); ar & p; } void print(){ for (auto element : p){ std::cout<<"Context: "<< element.first[0] << std::endl; std::cout<<"\t"<<element.second << std::endl; } } PYPLM<N-1> backoff; tied_parameter_resampler<crp<unsigned>> tr; mutable std::vector<unsigned> lookup; // thread-local //std::unordered_map<std::vector<unsigned>, crp<unsigned>, uvector_hash> p; // .first = context .second = CRP public: std::unordered_map<std::vector<unsigned>, crp<unsigned>, uvector_hash> p; // .first = context .second = CRP }; } #endif
GiulioPN/bnlm
src/mf_crp.h
<gh_stars>1-10 #ifndef _CPYP_MF_CRP_H_ #define _CPYP_MF_CRP_H_ #include <iostream> #include <numeric> #include <cassert> #include <cmath> #include <utility> #include <unordered_map> #include <functional> #include "random.h" #include "slice_sampler.h" #include "crp_table_manager.h" #include "m.h" namespace cpyp { // Chinese restaurant process (Pitman-Yor parameters) histogram-based table tracking // based on the implementation proposed by Blunsom et al. 2009 // // this implementation assumes that the observation likelihoods are either 1 (if they // are identical to the "parameter" drawn from G_0) or 0. This is fine for most NLP // applications but violated in PYP mixture models etc. template <unsigned NumFloors, typename Dish, typename DishHash = std::hash<Dish> > class mf_crp { public: mf_crp() : num_tables_(), num_customers_(), discount_(0.1), strength_(1.0), discount_prior_strength_(std::numeric_limits<double>::quiet_NaN()), discount_prior_beta_(std::numeric_limits<double>::quiet_NaN()), strength_prior_shape_(std::numeric_limits<double>::quiet_NaN()), strength_prior_rate_(std::numeric_limits<double>::quiet_NaN()) { check_hyperparameters(); } mf_crp(double disc, double strength) : num_tables_(), num_customers_(), discount_(disc), strength_(strength), discount_prior_strength_(std::numeric_limits<double>::quiet_NaN()), discount_prior_beta_(std::numeric_limits<double>::quiet_NaN()), strength_prior_shape_(std::numeric_limits<double>::quiet_NaN()), strength_prior_rate_(std::numeric_limits<double>::quiet_NaN()) { check_hyperparameters(); } mf_crp(double d_strength, double d_beta, double c_shape, double c_rate, double d = 0.8, double c = 1.0) : num_tables_(), num_customers_(), discount_(d), strength_(c), discount_prior_strength_(d_strength), discount_prior_beta_(d_beta), strength_prior_shape_(c_shape), strength_prior_rate_(c_rate) { check_hyperparameters(); } void check_hyperparameters() { if (discount_ < 0.0 || discount_ >= 1.0) { std::cerr << "Bad discount: " << discount_ << std::endl; abort(); } if (strength_ <= -discount_) { std::cerr << "Bad strength: " << strength_ << " (discount=" << discount_ << ")" << std::endl; abort(); } llh_ = lgamma(strength_) - lgamma(strength_ / discount_); if (has_discount_prior()) llh_ = Md::log_beta_density(discount_, discount_prior_strength_, discount_prior_beta_); if (has_strength_prior()) llh_ += Md::log_gamma_density(strength_ + discount_, strength_prior_shape_, strength_prior_rate_); if (num_tables_ > 0) llh_ = log_likelihood(discount_, strength_); } double discount() const { return discount_; } double strength() const { return strength_; } void set_hyperparameters(double d, double s) { discount_ = d; strength_ = s; check_hyperparameters(); } void set_discount(double d) { discount_ = d; check_hyperparameters(); } void set_strength(double a) { strength_ = a; check_hyperparameters(); } bool has_discount_prior() const { return !std::isnan(discount_prior_strength_); } bool has_strength_prior() const { return !std::isnan(strength_prior_shape_); } void clear() { num_tables_ = 0; num_customers_ = 0; dish_locs_.clear(); } unsigned num_tables() const { return num_tables_; } unsigned num_tables(const Dish& dish) const { auto it = dish_locs_.find(dish); if (it == dish_locs_.end()) return 0; return it->second.num_tables(); } unsigned num_customers() const { return num_customers_; } unsigned num_customers(const Dish& dish) const { auto it = dish_locs_.find(dish); if (it == dish_locs_.end()) return 0; return it->num_customers(); } // returns (floor,table delta) where table delta +1 or 0 indicates whether a new table was opened or not template <class InputIterator, class InputIterator2, typename Engine> std::pair<unsigned,int> increment(const Dish& dish, InputIterator p0i, InputIterator2 lambdas, Engine& eng) { typedef decltype(*p0i + 0.0) F; const F marginal_p0 = std::inner_product(p0i, p0i + NumFloors, lambdas, F(0.0)); if (marginal_p0 > F(1.000001)) { std::cerr << "bad marginal: " << marginal_p0 << std::endl; abort(); } crp_table_manager<NumFloors>& loc = dish_locs_[dish]; bool share_table = false; if (loc.num_customers()) { const F p_empty = F(strength_ + num_tables_ * discount_) * marginal_p0; const F p_share = F(loc.num_customers() - loc.num_tables() * discount_); share_table = sample_bernoulli(p_empty, p_share, eng); } unsigned floor = 0; if (share_table) { unsigned n = loc.share_table(discount_, eng); update_llh_add_customer_to_table_seating(n); } else { if (NumFloors > 1) { // sample floor F r = F(sample_uniform01<double>(eng)) * marginal_p0; for (unsigned i = 0; i < NumFloors; ++i) { r -= (*p0i) * (*lambdas); ++p0i; ++lambdas; if (r <= F(0.0)) { floor = i; break; } } } loc.create_table(floor); update_llh_add_customer_to_table_seating(0); ++num_tables_; } ++num_customers_; return std::make_pair(floor, share_table ? 0 : 1); } // returns -1 or 0, indicating whether a table was closed // logq = probability that the selected table will be reselected if // increment_no_base is called with dish [optional] template<typename Engine> std::pair<unsigned,int> decrement(const Dish& dish, Engine& eng, double* logq = nullptr) { crp_table_manager<NumFloors>& loc = dish_locs_[dish]; assert(loc.num_customers()); if (loc.num_customers() == 1) { update_llh_remove_customer_from_table_seating(1); unsigned floor = 0; for (; floor < NumFloors; ++floor) if (!loc.h[floor].empty()) break; assert(floor < NumFloors); dish_locs_.erase(dish); --num_tables_; --num_customers_; // q = 1 since this is the first customer return std::make_pair(floor, -1); } else { unsigned selected_table_postcount = 0; const std::pair<unsigned,int> delta = loc.remove_customer(eng, &selected_table_postcount); update_llh_remove_customer_from_table_seating(selected_table_postcount + 1); --num_customers_; if (delta.second) --num_tables_; if (logq) { double p_empty = (strength_ + num_tables_ * discount_); double p_share = (loc.num_customers() - loc.num_tables() * discount_); const double z = p_empty + p_share; p_empty /= z; p_share /= z; if (selected_table_postcount) *logq += log(p_share * (selected_table_postcount - discount_) / (loc.num_customers() - loc.num_tables() * discount_)); else *logq += log(p_empty); } return delta; } } template <class InputIterator, class InputIterator2> decltype(**((InputIterator*) 0) + 0.0) prob(const Dish& dish, InputIterator p0i, InputIterator2 lambdas) const { typedef decltype(*p0i + 0.0) F; const F marginal_p0 = std::inner_product(p0i, p0i + NumFloors, lambdas, F(0.0)); if (marginal_p0 >= F(1.000001)) { std::cerr << "bad marginal: " << marginal_p0 << std::endl; abort(); } if (num_tables_ == 0) return marginal_p0; auto it = dish_locs_.find(dish); const F r = F(num_tables_ * discount_ + strength_); if (it == dish_locs_.end()) { return r * marginal_p0 / F(num_customers_ + strength_); } else { return (F(it->second.num_customers() - discount_ * it->second.num_tables()) + r * marginal_p0) / F(num_customers_ + strength_); } } double log_likelihood() const { return llh_; // return log_likelihood(discount_, strength_); } // call this before changing the number of tables / customers void update_llh_add_customer_to_table_seating(unsigned n) { unsigned t = 0; if (n == 0) t = 1; llh_ -= log(strength_ + num_customers_); if (t == 1) llh_ += log(discount_) + log(strength_ / discount_ + num_tables_); if (n > 0) llh_ += log(n - discount_); } // call this before changing the number of tables / customers void update_llh_remove_customer_from_table_seating(unsigned n) { unsigned t = 0; if (n == 1) t = 1; llh_ += log(strength_ + num_customers_ - 1); if (t == 1) llh_ -= log(discount_) + log(strength_ / discount_ + num_tables_ - 1); if (n > 1) llh_ -= log(n - discount_ - 1); } // adapted from http://en.wikipedia.org/wiki/Chinese_restaurant_process // does not include P_0's double log_likelihood(const double& discount, const double& strength) const { double lp = 0.0; if (has_discount_prior()) lp = Md::log_beta_density(discount, discount_prior_strength_, discount_prior_beta_); if (has_strength_prior()) lp += Md::log_gamma_density(strength + discount, strength_prior_shape_, strength_prior_rate_); assert(lp <= 0.0); if (num_customers_) { // if restaurant is not empty if (discount > 0.0) { // two parameter case: discount > 0 const double r = lgamma(1.0 - discount); if (strength) lp += lgamma(strength) - lgamma(strength / discount); lp += - lgamma(strength + num_customers_) + num_tables_ * log(discount) + lgamma(strength / discount + num_tables_); // above line implies // 1) when adding a customer to a restaurant containing N customers: // lp -= log(strength + N) [because \Gamma(s+N+1) = (s+N)\Gamma(s+N) // 2) when removing a customer from a restaurant containing N customers: // lp += log(strength + N - 1) [because \Gamma(s+N) = (s+N-1)\Gamma(s+N-1)] // 3) when adding a table to a restaurant containing T tables: // lp += log(discount) + log(s / d + T) // 4) when removing a table from a restuarant containint T tables: // lp -= log(discount) + log(s / d + T - 1) assert(std::isfinite(lp)); for (auto& dish_loc : dish_locs_) for (unsigned floor = 0; floor < NumFloors; ++floor) for (auto& bin : dish_loc.second.h[floor]) lp += (lgamma(bin.first - discount) - r) * bin.second; // above implies // 1) when adding to a table seating N > 1 customers // lp += log(N - discount) // 2) when adding a new table // do nothing // 3) when removing a customer from a table with N > 1 customers // lp -= log(N - discount - 1) // 4) when closing a table // do nothing } else if (!discount) { // discount == 0.0 (ie, Dirichlet Process) lp += lgamma(strength) + num_tables_ * log(strength) - lgamma(strength + num_tables_); assert(std::isfinite(lp)); for (auto& dish_loc : dish_locs_) lp += lgamma(dish_loc.second.num_tables()); } else { // should never happen assert(!"discount less than 0 detected!"); } } assert(std::isfinite(lp)); return lp; } template<typename Engine> void resample_hyperparameters(Engine& eng, const unsigned nloop = 5, const unsigned niterations = 10) { assert(has_discount_prior() || has_strength_prior()); if (num_customers() == 0) return; double s = strength_; double d = discount_; for (unsigned iter = 0; iter < nloop; ++iter) { if (has_strength_prior()) { s = slice_sampler1d([this,d](double prop_s) { return this->log_likelihood(d, prop_s); }, s, eng, -d + std::numeric_limits<double>::min(), std::numeric_limits<double>::infinity(), 0.0, niterations, 100*niterations); } if (has_discount_prior()) { double min_discount = std::numeric_limits<double>::min(); if (s < 0.0) min_discount -= s; d = slice_sampler1d([this,s](double prop_d) { return this->log_likelihood(prop_d, s); }, d, eng, min_discount, 1.0, 0.0, niterations, 100*niterations); } } s = slice_sampler1d([this,d](double prop_s) { return this->log_likelihood(d, prop_s); }, s, eng, -d + std::numeric_limits<double>::min(), std::numeric_limits<double>::infinity(), 0.0, niterations, 100*niterations); set_hyperparameters(d, s); } void print(std::ostream* out) const { std::cerr << "PYP(d=" << discount_ << ",c=" << strength_ << ") customers=" << num_customers_ << std::endl; for (auto& dish_loc : dish_locs_) (*out) << dish_loc.first << " : " << dish_loc.second << std::endl; } typedef typename std::unordered_map<Dish, crp_table_manager<NumFloors>, DishHash>::const_iterator const_iterator; const_iterator begin() const { return dish_locs_.begin(); } const_iterator end() const { return dish_locs_.end(); } void swap(crp<Dish>& b) { std::swap(num_tables_, b.num_tables_); std::swap(num_customers_, b.num_customers_); std::swap(dish_locs_, b.dish_locs_); std::swap(discount_, b.discount_); std::swap(strength_, b.strength_); std::swap(discount_prior_strength_, b.discount_prior_strength_); std::swap(discount_prior_beta_, b.discount_prior_beta_); std::swap(strength_prior_shape_, b.strength_prior_shape_); std::swap(strength_prior_rate_, b.strength_prior_rate_); std::swap(llh_, b.llh_); } template<class Archive> void serialize(Archive& ar, const unsigned int version) { ar & num_tables_; ar & num_customers_; ar & discount_; ar & strength_; ar & discount_prior_strength_; ar & discount_prior_beta_; ar & strength_prior_shape_; ar & strength_prior_rate_; ar & llh_; // llh of current partition structure ar & dish_locs_; } private: unsigned num_tables_; unsigned num_customers_; std::unordered_map<Dish, crp_table_manager<NumFloors>, DishHash> dish_locs_; double discount_; double strength_; // optional beta prior on discount_ (NaN if no prior) double discount_prior_strength_; double discount_prior_beta_; // optional gamma prior on strength_ (NaN if no prior) double strength_prior_shape_; double strength_prior_rate_; double llh_; // llh of current partition structure }; template<unsigned N,typename T> void swap(mf_crp<N,T>& a, mf_crp<N,T>& b) { a.swap(b); } template <unsigned N,typename T,typename H> std::ostream& operator<<(std::ostream& o, const mf_crp<N,T,H>& c) { c.print(&o); return o; } } // namespace cpyp #endif
GiulioPN/bnlm
src/tied_parameter_resampler.h
#ifndef _TIED_RESAMPLER_H_ #define _TIED_RESAMPLER_H_ #include <set> #include <vector> #include "random.h" #include "slice_sampler.h" #include "m.h" namespace cpyp { // Tie together CRPs that are conditionally independent given their // hyperparameters. template <class CRP> struct tied_parameter_resampler { explicit tied_parameter_resampler(double da, double db, double ss, double sr, double d=0.5, double s=1.0) : d_alpha(da), d_beta(db), s_shape(ss), s_rate(sr), discount(d), strength(s) {} void insert(CRP* crp) { crps.insert(crp); crp->set_discount(discount); crp->set_strength(strength); assert(!crp->has_discount_prior()); assert(!crp->has_strength_prior()); } void erase(CRP* crp) { crps.erase(crp); } size_t size() const { return crps.size(); } double log_likelihood(double d, double s) const { if (s <= -d) return -std::numeric_limits<double>::infinity(); double llh = Md::log_beta_density(d, d_alpha, d_beta) + Md::log_gamma_density(d + s, s_shape, s_rate); for (auto& crp : crps) { llh += crp->log_likelihood(d, s); } return llh; } double log_likelihood() const { return log_likelihood(discount, strength); } template<typename Engine> void resample_hyperparameters(Engine& eng, const unsigned nloop = 5, const unsigned niterations = 10) { if (size() == 0) { std::cerr << "EMPTY - not resampling\n"; return; } for (unsigned iter = 0; iter < nloop; ++iter) { strength = slice_sampler1d([this](double prop_s) { return this->log_likelihood(discount, prop_s); }, strength, eng, -discount + std::numeric_limits<double>::min(), std::numeric_limits<double>::infinity(), 0.0, niterations, 100*niterations); double min_discount = std::numeric_limits<double>::min(); if (strength < 0.0) min_discount -= strength; discount = slice_sampler1d([this](double prop_d) { return this->log_likelihood(prop_d, strength); }, discount, eng, min_discount, 1.0, 0.0, niterations, 100*niterations); } strength = slice_sampler1d([this](double prop_s) { return this->log_likelihood(discount, prop_s); }, strength, eng, -discount + std::numeric_limits<double>::min(), std::numeric_limits<double>::infinity(), 0.0, niterations, 100*niterations); /*std::cerr << "Resampled " << crps.size() << " CRPs (d=" << discount << ",s=" << strength << ") = " << log_likelihood(discount, strength) << std::endl;*/ for (auto& crp : crps) crp->set_hyperparameters(discount, strength); } private: std::set<CRP*> crps; const double d_alpha, d_beta, s_shape, s_rate; double discount, strength; }; // split according to some criterion template <class CRP> struct bintied_parameter_resampler { explicit bintied_parameter_resampler(unsigned nbins) : resamplers(nbins, tied_parameter_resampler<CRP>(1,1,1,1)) {} void insert(unsigned bin, CRP* crp) { resamplers[bin].insert(crp); } void erase(unsigned bin, CRP* crp) { resamplers[bin].erase(crp); } template <typename Engine> void resample_hyperparameters(Engine& eng) { for (unsigned i = 0; i < resamplers.size(); ++i) { std::cerr << "BIN " << i << " (" << resamplers[i].size() << " CRPs): " << std::flush; resamplers[i].resample_hyperparameters(eng); } } double log_likelihood() const { double llh = 0; for (unsigned i = 0; i < resamplers.size(); ++i) llh += resamplers[i].log_likelihood(); return llh; } private: std::vector<tied_parameter_resampler<CRP> > resamplers; }; } // namespace cpyp #endif
GiulioPN/bnlm
src/shpyplm.h
<gh_stars>1-10 #ifndef SHPYPLM_H_ #define SHPYPLM_H_ #include <vector> #include <unordered_map> #include "hpyplm.h" #include "random.h" namespace cpyp { template <unsigned N> class SPYPLM { private: PYPLM<N> shared_lm; //!< shared Pitman-Yor for LM std::vector<PYPLM<N>> local_lm; //!< local Pitman-Yor process for LM std::vector<double> local_lambda; //!< lambda parameters std::vector<unsigned int> N_words; //!< number of words per text std::vector<unsigned int> N_shared; //!< number of words in shared model. double a; //!< used for lambda resample double b; //!< used for lambda resample public: /* Add costumer w to shared CRP or local j CRP * \param vs vocabulary size * \param n_txt number of corpus */ explicit SPYPLM(unsigned vs, unsigned n_txt, std::vector<unsigned> num_of_words_per_text, double da = 1.0, double db = 1.0, double ss = 1.0, double sr = 1.0, double lambda=0.5, double a_in = 1.0, double b_in = 1.0) : shared_lm(vs, da, db, ss, sr), local_lm(n_txt,PYPLM<N> (vs, da, db, ss, sr)), local_lambda(n_txt,lambda), N_words(num_of_words_per_text), N_shared(n_txt,0), a(a_in), b(b_in) {} ~SPYPLM(){ local_lm.clear(); local_lambda.clear(); } /* Add costumer w to shared CRP or local j CRP * \param w add costumer * \param j text index * \param eng random engine * \return r a bool, called label obs: if 0 the observation w belongs to shared process, else (1) w belongs to the j process */ template<typename Engine> void increment(unsigned w, const std::vector<unsigned>& context, unsigned int j, unsigned int& r,Engine& eng){ //sample const unsigned int r_prec = r; const double p_shared = (1 - local_lambda[j])*shared_lm.prob(w, context); const double p_local = local_lambda[j]*local_lm[j].prob(w, context); const double tot = p_shared + p_local; r = sample_bernoulli(p_shared/tot, p_local/tot, eng); if(r){ local_lm[j].increment(w, context, eng); if(r != r_prec ) N_shared[j]--; } else { shared_lm.increment(w, context, eng); if(r != r_prec )N_shared[j] ++; } } /* Remove costumer w to shared CRP or local j CRP * \param w add costumer * \param j text index * \param eng random engine * \param r a bool, called label obs: if 0 the observation w belongs to shared process, else (1) w belongs to the j process */ template<typename Engine> void decrement(unsigned w, const std::vector<unsigned>& context, unsigned j, bool r, Engine& eng){ if(r) local_lm[j].decrement(w, context, eng); else shared_lm.decrement(w, context, eng); } /* Parameters resemple of language models \param eng random engine */ template<typename Engine> void resample_hyperparameters(Engine& eng){ //shared_lm parameters shared_lm.resample_hyperparameters(eng); //resample local_lm parameters (for each local_lm) for(int j =0; j< local_lm.size(); j++) local_lm[j].resample_hyperparameters(eng); } /* Parameters resemple of language models \param r a bool if 0 the observation w belongs to shared process, else (1) w belongs to the j process \param eng random engine */ template<typename Engine> void resample_lambda_parameters(Engine& eng){ //sample lambda double a_lambda=0, b_lambda=0; for(int j=0; j< local_lambda.size(); j++){ a_lambda = a + N_shared[j]; b_lambda = b + (N_words[j]-N_shared[j]); local_lambda[j] = sample_beta(a_lambda, b_lambda, eng); } } /* helper function for logsumexp calculation * \param nums a vector of numbers, where each number is x_i * \return log(sum_i exp(x_i)) */ double logsumexp(std::vector<double>& nums) { double max_exp = nums[0], sum = 0.0; size_t i; for (i = 1 ; i < nums.size() ; i++) if (nums[i] > max_exp) max_exp = nums[i]; for (i = 0; i < nums.size() ; i++) sum += exp(nums[i] - max_exp); return log(sum) + max_exp; } /* Predict a new word * \param w word index to be predicted * \param j text index * \param r a bool if 0 the observation w belongs to shared process, else (1) w belongs to the j process * \return pred_prob a double which store the prediction log probability */ double prob(unsigned w, const std::vector<unsigned>& context, const unsigned j) const { //Note: shared_lm.prob return a prob, not a log prob double predictive_prob = (1-local_lambda[j])*shared_lm.prob(w, context) + local_lambda[j]*local_lm[j].prob(w, context) ; return predictive_prob; } /* log_likelihood of the model j * \param w word index to be predicted * \param j text index * \param r a bool if 0 the observation w belongs to shared process, else (1) w belongs to the j process * \return log likelihood of the SHPYP model */ double log_likelihood(const unsigned j){ std::vector<double> log_llh; log_llh.push_back( log( 1-local_lambda[j] ) + shared_lm.log_likelihood() ); // log(1-lambda) + shared_lm.log_llh --> x_1 log_llh.push_back( log( local_lambda[j] ) + local_lm[j].log_likelihood() ); // log(local_lambda[j]) + local_lm[j].log_llh --> x_2 return logsumexp(log_llh); // log(exp(x_1) + exp(x_2)) = log ( (1-lambda)*shared.log_llh + local_lambda[j]*local_lm[j].log_llh ) } void print(){ std::cout<<"-----------------------"<<std::endl; std::cout<<"SHARED CRP:"<<std::endl; shared_lm.print(); std::cout<<"LOCAL CRPs:"<<std::endl; for (int i=0; i<local_lm.size(); i++){ std::cout<<"loc "<<i<<": "<<std::endl; local_lm[i].print(); } } }; } #endif
GiulioPN/bnlm
src/corpus.h
#ifndef CPYPDICT_H_ #define CPYPDICT_H_ #include <string> #include <iostream> #include <cassert> #include <fstream> #include <vector> #include <set> #include <unordered_map> #include <functional> namespace cpyp { class Dict { typedef std::unordered_map<std::string, unsigned, std::hash<std::string> > Map; public: Dict() : b0_("<bad0>") { words_.reserve(1000); } inline unsigned max() const { return words_.size(); } static bool is_ws(char x) { return (x == ' ' || x == '\t'); } inline void ConvertWhitespaceDelimitedLine(const std::string& line, std::vector<unsigned>* out) { size_t cur = 0; size_t last = 0; int state = 0; out->clear(); while(cur < line.size()) { if (is_ws(line[cur++])) { if (state == 0) continue; out->push_back(Convert(line.substr(last, cur - last - 1))); state = 0; } else { if (state == 1) continue; last = cur - 1; state = 1; } } if (state == 1) out->push_back(Convert(line.substr(last, cur - last))); } inline unsigned Convert(const std::string& word, bool frozen = false) { Map::iterator i = d_.find(word); if (i == d_.end()) { if (frozen) return 0; words_.push_back(word); d_[word] = words_.size(); return words_.size(); } else { return i->second; } } inline const std::string& Convert(const unsigned id) const { if (id == 0) return b0_; return words_[id-1]; } template<class Archive> void serialize(Archive& ar, const unsigned int version) { ar & b0_; ar & words_; ar & d_; } private: std::string b0_; std::vector<std::string> words_; Map d_; }; void ReadFromFile(const std::string& filename, Dict* d, std::vector<std::vector<unsigned> >* src, std::set<unsigned>* src_vocab) { src->clear(); std::cerr << "Reading from " << filename << std::endl; std::ifstream in(filename); assert(in); std::string line; int lc = 0; while(getline(in, line)) { ++lc; src->push_back(std::vector<unsigned>()); d->ConvertWhitespaceDelimitedLine(line, &src->back()); for (unsigned i = 0; i < src->back().size(); ++i) { src_vocab->insert(src->back()[i]); } } } } // namespace cpyp #endif
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.6/newsApp/ELBArticulo.h
<reponame>miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind- // // ELBArticulo.h // newsApp // // Created by <NAME> on 13/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> @interface ELBArticulo : NSManagedObject @property (nonatomic, retain) NSString * nombre; @property (nonatomic, retain) NSDate * fecha; @property (nonatomic, retain) NSString * texto; - (id)init; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBFechaViewController.h
<gh_stars>0 // // ELBFechaViewController.h // newsApp // // Created by <NAME> on 17/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBFechaViewController : UIViewController @property (nonatomic,weak) UIViewController * delegate; // también ok: id delegate @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBAppDelegate.h
// // ELBAppDelegate.h // newsApp // // Created by <NAME> on 06/06/13. // Copyright (c) 2013 Espí & Le Barbier. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsAppTests/newsAppTests.h
<filename>newsApp 1.9/newsAppTests/newsAppTests.h // // newsAppTests.h // newsAppTests // // Created by <NAME> on 06/06/13. // Copyright (c) 2013 Espí & Le Barbier. All rights reserved. // #import <XCTest/XCTest.h> @interface newsAppTests : XCTestCase @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.4/newsApp/ELBDetalleArticuloViewController.h
<filename>newsApp 1.4/newsApp/ELBDetalleArticuloViewController.h // // ELBDetalleArticuloViewController.h // newsApp // // Created by <NAME> on 09/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBDetalleArticuloViewController : UIViewController - (void) setArticulo:(NSString*)texto; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.0/newsApp/ELBNoticiasTableViewController.h
<filename>newsApp 1.0/newsApp/ELBNoticiasTableViewController.h // // ELBNoticiasTableViewController.h // newsApp // // Created by <NAME> on 30/04/14. // Copyright (c) 2014 Espí & Le Barbier. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBNoticiasTableViewController : UITableViewController @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.7/newsApp/ELBDetalleArticuloViewController.h
// // ELBDetalleArticuloViewController.h // newsApp // // Created by <NAME> on 09/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <UIKit/UIKit.h> @class ELBArticulo; @interface ELBDetalleArticuloViewController : UIViewController @property (strong, nonatomic) IBOutlet UITextView *articuloTextView; - (IBAction)cerrar:(id)sender; - (void) setTextoArticulo:(NSString*)texto; - (void) setArticulo:(ELBArticulo *)articulo; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBLocalizacionViewController.h
// // ELBLocalizacionViewController.h // newsApp // // Created by <NAME> on 20/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interface ELBLocalizacionViewController : UIViewController <MKMapViewDelegate,CLLocationManagerDelegate> @property (strong, nonatomic) IBOutlet MKMapView *mapaMapView; @property (nonatomic, strong) CLLocationManager *locationManager; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBAnotacion.h
<reponame>miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-<filename>newsApp 1.9/newsApp/ELBAnotacion.h // // ELBAnotacion.h // newsApp // // Created by <NAME> on 20/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <MapKit/MapKit.h> @interface ELBAnotacion : NSObject <MKAnnotation> - (id) initConCoordenada:(CLLocationCoordinate2D) coordenada; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/STTwitter/STTwitterOAuth.h
// // STTwitterRequest.h // STTwitterRequests // // Created by <NAME> on 9/5/12. // Copyright (c) 2012 <NAME>. All rights reserved. // #import <Foundation/Foundation.h> #import "STTwitterOAuthProtocol.h" /* Based on the following documentation http://oauth.net/core/1.0/ https://dev.twitter.com/docs/auth/authorizing-request https://dev.twitter.com/docs/auth/implementing-sign-twitter https://dev.twitter.com/docs/auth/creating-signature https://dev.twitter.com/docs/api/1/post/oauth/request_token https://dev.twitter.com/docs/oauth/xauth ... */ @interface STTwitterOAuth : NSObject <STTwitterOAuthProtocol> + (STTwitterOAuth *)twitterServiceWithConsumerName:(NSString *)consumerName consumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret; + (STTwitterOAuth *)twitterServiceWithConsumerName:(NSString *)consumerName consumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret oauthToken:(NSString *)oauthToken oauthTokenSecret:(NSString *)oauthTokenSecret; + (STTwitterOAuth *)twitterServiceWithConsumerName:(NSString *)consumerName consumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret username:(NSString *)username password:(NSString *)password; - (void)postTokenRequest:(void(^)(NSURL *url, NSString *oauthToken))successBlock oauthCallback:(NSString *)oauthCallback errorBlock:(void(^)(NSError *error))errorBlock; - (void)postAccessTokenRequestWithPIN:(NSString *)pin successBlock:(void(^)(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postXAuthAccessTokenRequestWithUsername:(NSString *)username password:(NSString *)password successBlock:(void(^)(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (BOOL)canVerifyCredentials; - (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBlock errorBlock:(void(^)(NSError *error))errorBlock; @end @interface NSString (STTwitterOAuth) + (NSString *)random32Characters; - (NSString *)signHmacSHA1WithKey:(NSString *)key; - (NSDictionary *)parametersDictionary; - (NSString *)urlEncodedString; @end @interface NSURL (STTwitterOAuth) - (NSString *)normalizedForOauthSignatureString; - (NSArray *)rawGetParametersDictionaries; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBNoticiasViewController.h
<filename>newsApp 1.9/newsApp/ELBNoticiasViewController.h // // ELBNoticiasViewController.h // newsApp // // Created by <NAME> on 09/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBNoticiasViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> @property (strong, nonatomic) IBOutlet UIPickerView *periodicoPickerView; @property (strong, nonatomic) IBOutlet UIWebView *periodicoWebView; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBTwitterAPIClient.h
// // ELBTwitterAPIClient.h // // // Created by <NAME> on 13/06/13. // Copyright (c) 2013 Espí & Le Barbier. All rights reserved. // #import "STTwitterAPIWrapper.h" @interface ELBTwitterAPIClient : STTwitterAPIWrapper + (STTwitterAPIWrapper *)twitterAPIApplicationOnlyWithConsumerKey; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBTwitterTableViewController.h
// // ELBTwitterTableViewController.h // newsApp // // Created by <NAME> on 18/06/13. // Copyright (c) 2013 Espí & Le Barbier. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBTwitterTableViewController : UITableViewController @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.5/newsApp/Factura.h
<gh_stars>0 // // Factura.h // newsApp // // Created by <NAME> on 08/05/14. // Copyright (c) 2014 Espí & Le Barbier. All rights reserved. // #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> @class Cliente; @interface Factura : NSManagedObject @property (nonatomic, retain) NSNumber * codigo; @property (nonatomic, retain) NSNumber * importe; @property (nonatomic, retain) Cliente *clienteDeLaFactura; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBStore.h
<reponame>miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind- // // ELBStore.h // newsApp // // Created by <NAME> on 20/01/13. // Copyright (c) 2013 <NAME>. All rights reserved. // #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> extern NSString *const kExceptionRaise; extern NSString *const kExceptionFormat; extern NSString *const kErrorCrearObjectFormat; extern NSString *const kErrorSaveObjectFormat; extern NSString *const kErrorFetchObjectFormat; extern NSString *const kErrorSaveObjectFormat; extern NSString *const kErrorSaveContextObjectFormat; @interface ELBStore : NSObject ; @property (nonatomic,strong) NSManagedObjectContext *context; @property (nonatomic,strong) NSManagedObjectModel *model; + (ELBStore *)defaultStore; - (BOOL)grabaCambios; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
funnyApp 1.3/funnyApp/ELBMovimientoViewController.h
<reponame>miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-<gh_stars>0 // // ELBMovimientoViewController.h // funnyApp // // Created by <NAME> on 14/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBMovimientoViewController : UIViewController @property (strong, nonatomic) IBOutlet UILabel *movimientoLabel; @property (strong, nonatomic) IBOutlet UILabel *gestosLabel; - (IBAction)swipe:(id)sender; - (IBAction)tap:(id)sender; - (IBAction)rotation:(id)sender; - (IBAction)pinch:(id)sender; - (IBAction)pan:(id)sender; - (IBAction)longPress:(id)sender; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBArticulosTableViewController.h
<filename>newsApp 1.9/newsApp/ELBArticulosTableViewController.h // // ELBArticulosTableViewController.h // newsApp // // Created by <NAME> on 17/06/13. // Copyright (c) 2013 Espí & Le Barbier. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBArticulosTableViewController : UITableViewController @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/STTwitter/STTwitterAPIWrapper.h
<filename>newsApp 1.9/STTwitter/STTwitterAPIWrapper.h /* Copyright (c) 2012, <NAME> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Nicolas Seriot nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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. */ // // STTwitterAPI.h // STTwitterRequests // // Created by <NAME> on 9/18/12. // Copyright (c) 2012 <NAME>. All rights reserved. // #import <Foundation/Foundation.h> /* Partial Objective-C front-end for https://dev.twitter.com/docs/api/1.1 */ /* Tweet fields contents https://dev.twitter.com/docs/platform-objects/tweets https://dev.twitter.com/blog/new-withheld-content-fields-api-responses */ @interface STTwitterAPIWrapper : NSObject #if TARGET_OS_IPHONE #else + (STTwitterAPIWrapper *)twitterAPIWithOAuthOSX; #endif + (STTwitterAPIWrapper *)twitterAPIWithOAuthConsumerName:(NSString *)consumerName consumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret; + (STTwitterAPIWrapper *)twitterAPIWithOAuthConsumerName:(NSString *)consumerName consumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret username:(NSString *)username password:(NSString *)password; + (STTwitterAPIWrapper *)twitterAPIWithOAuthConsumerName:(NSString *)consumerName consumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret oauthToken:(NSString *)oauthToken oauthTokenSecret:(NSString *)oauthTokenSecret; // https://dev.twitter.com/docs/auth/application-only-auth + (STTwitterAPIWrapper *)twitterAPIApplicationOnlyWithConsumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret; - (void)postTokenRequest:(void(^)(NSURL *url, NSString *oauthToken))successBlock oauthCallback:(NSString *)oauthCallback errorBlock:(void(^)(NSError *error))errorBlock; - (void)postAccessTokenRequestWithPIN:(NSString *)pin successBlock:(void(^)(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)invalidateBearerTokenWithSuccessBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; @property (nonatomic, retain) NSString *consumerName; @property (nonatomic, retain) NSString *userName; // available for osx, set after successful connection for STTwitterOAuth @property (nonatomic, readonly) NSString *oauthAccessToken; @property (nonatomic, readonly) NSString *oauthAccessTokenSecret; @property (nonatomic, readonly) NSString *bearerToken; #pragma mark Generic methods to GET and POST - (void)getResource:(NSString *)resource parameters:(NSDictionary *)parameters successBlock:(void(^)(id json))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postResource:(NSString *)resource parameters:(NSDictionary *)parameters successBlock:(void(^)(id response))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark Timelines /* GET statuses/mentions_timeline Returns Tweets (*: mentions for the user) Returns the 20 most recent mentions (tweets containing a users's @screen_name) for the authenticating user. The timeline returned is the equivalent of the one seen when you view your mentions on twitter.com. This method can only return up to 800 tweets. */ - (void)getMentionsTimelineSinceID:(NSString *)optionalSinceID count:(NSUInteger)optionalCount successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET statuses/user_timeline Returns Tweets (*: tweets for the user) Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters. User timelines belonging to protected users may only be requested when the authenticated user either "owns" the timeline or is an approved follower of the owner. The timeline returned is the equivalent of the one seen when you view a user's profile on twitter.com. This method can only return up to 3,200 of a user's most recent Tweets. Native retweets of other statuses by the user is included in this total, regardless of whether include_rts is set to false when requesting this resource. */ - (void)getUserTimelineWithScreenName:(NSString *)screenName sinceID:(NSString *)optionalSinceID maxID:(NSString *)optionalMaxID count:(NSUInteger)optionalCount successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getUserTimelineWithScreenName:(NSString *)screenName count:(NSUInteger)optionalCount successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getUserTimelineWithScreenName:(NSString *)screenName successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET statuses/home_timeline Returns Tweets (*: tweets from people the user follows) Returns a collection of the most recent Tweets and retweets posted by the authenticating user and the users they follow. The home timeline is central to how most users interact with the Twitter service. Up to 800 Tweets are obtainable on the home timeline. It is more volatile for users that follow many users or follow users who tweet frequently. */ - (void)getHomeTimelineSinceID:(NSString *)optionalSinceID count:(NSUInteger)optionalCount successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET statuses/retweets_of_me Returns the most recent tweets authored by the authenticating user that have been retweeted by others. This timeline is a subset of the user's GET statuses/user_timeline. See Working with Timelines for instructions on traversing timelines. */ - (void)getStatusesRetweetsOfMeWithOptionalCount:(NSString *)count optionalSinceID:(NSString *)sinceID optionalMaxID:(NSString *)maxID trimUser:(BOOL)trimUser includeEntitied:(BOOL)includeEntities includeUserEntities:(BOOL)includeUserEntities successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // convenience method without all optional values - (void)getStatusesRetweetsOfMeWithSuccessBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark Tweets // GET statuses/retweets/:id - (void)getStatusesRetweetsForID:(NSString *)statusID optionalCount:(NSString *)count trimUser:(BOOL)trimUser successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // GET statuses/show/:id - (void)getStatusesShowID:(NSString *)statusID trimUser:(BOOL)trimUser includeMyRetweet:(BOOL)includeMyRetweet includeEntities:(BOOL)includeEntities successBlock:(void(^)(NSDictionary *status))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // POST statuses/destroy/:id // Returns Tweets (1: the destroyed tweet) - (void)postDestroyStatusWithID:(NSString *)statusID successBlock:(void(^)(NSDictionary *status))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // POST statuses/update // Returns Tweets (1: the new tweet) - (void)postStatusUpdate:(NSString *)status inReplyToStatusID:(NSString *)optionalExistingStatusID placeID:(NSString *)optionalPlaceID // wins over lat/lon lat:(NSString *)optionalLat lon:(NSString *)optionalLon successBlock:(void(^)(NSDictionary *status))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // POST statuses/retweet/:id // Returns Tweets (1: the retweeted tweet) - (void)postStatusRetweetWithID:(NSString *)statusID successBlock:(void(^)(NSDictionary *status))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // POST statuses/update_with_media // Returns Tweets (1: the new tweet) - (void)postStatusUpdate:(NSString *)status inReplyToStatusID:(NSString *)optionalExistingStatusID mediaURL:(NSURL *)mediaURL placeID:(NSString *)optionalPlaceID // wins over lat/lon lat:(NSString *)optionalLat lon:(NSString *)optionalLon successBlock:(void(^)(NSDictionary *status))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // GET statuses/oembed // GET statuses/retweeters/ids - (void)getStatusesRetweetersIDsForStatusID:(NSString *)statusID optionalCursor:(NSString *)cursor returnIDsAsStrings:(BOOL)returnIDsAsStrings successBlock:(void(^)(NSArray *ids, NSString *previousCursor, NSString *nextCursor))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark Search // GET search/tweets // full method - (void)getSearchTweetsWithQuery:(NSString *)q optionalGeocode:(NSString *)geoCode // eg. "37.781157,-122.398720,1mi" optionalLang:(NSString *)lang // eg. "eu" optionalLocale:(NSString *)locale // eg. "ja" optionalResultType:(NSString *)resultType // eg. "mixed, recent, popular" optionalCount:(NSString *)count // eg. "100" optionalUntil:(NSString *)until // eg. "2012-09-01" optionalSinceID:(NSString *)sinceID // eg. "12345" optionalMaxID:(NSString *)maxID // eg. "54321" includeEntities:(BOOL)includeEntities optionalCallback:(NSString *)callback // eg. "processTweets" successBlock:(void(^)(NSDictionary *searchMetadata, NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // convenience method // Returns Tweets (*: tweets matching the query) - (void)getSearchTweetsWithQuery:(NSString *)q successBlock:(void(^)(NSDictionary *searchMetadata, NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark Streaming // POST statuses/filter // GET statuses/sample // GET statuses/firehose // GET user // GET site #pragma mark Direct Messages // GET direct_messages // Returns Tweets (*: direct messages to the user) - (void)getDirectMessagesSinceID:(NSString *)optionalSinceID count:(NSUInteger)optionalCount successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // GET direct_messages/sent // GET direct_messages/show // POST direct_messages/destroy // Returns Tweets (1: the destroyed DM) - (void)postDestroyDirectMessageWithID:(NSString *)dmID successBlock:(void(^)(NSDictionary *dm))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // POST direct_messages/new // Returns Tweets (1: the sent DM) - (void)postDirectMessage:(NSString *)status to:(NSString *)screenName successBlock:(void(^)(NSDictionary *dm))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark Friends & Followers /* GET friendships/no_retweets/ids Returns a collection of user_ids that the currently authenticated user does not want to receive retweets from. Use POST friendships/update to set the "no retweets" status for a given user account on behalf of the current user. */ /* GET friends/ids Returns Users (*: user IDs for followees) Returns a cursored collection of user IDs for every user the specified user is following (otherwise known as their "friends"). At this time, results are ordered with the most recent following first — however, this ordering is subject to unannounced change and eventual consistency issues. Results are given in groups of 5,000 user IDs and multiple "pages" of results can be navigated through using the next_cursor value in subsequent requests. See Using cursors to navigate collections for more information. This method is especially powerful when used in conjunction with GET users/lookup, a method that allows you to convert user IDs into full user objects in bulk. */ - (void)getFriendsIDsForScreenName:(NSString *)screenName successBlock:(void(^)(NSArray *friends))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET followers/ids Returns Users (*: user IDs for followers) Returns a cursored collection of user IDs for every user following the specified user. At this time, results are ordered with the most recent following first — however, this ordering is subject to unannounced change and eventual consistency issues. Results are given in groups of 5,000 user IDs and multiple "pages" of results can be navigated through using the next_cursor value in subsequent requests. See Using cursors to navigate collections for more information. This method is especially powerful when used in conjunction with GET users/lookup, a method that allows you to convert user IDs into full user objects in bulk. */ - (void)getFollowersIDsForScreenName:(NSString *)screenName successBlock:(void(^)(NSArray *followers))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET friendships/lookup Returns the relationships of the authenticating user to the comma-separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none. */ /* GET friendships/incoming Returns a collection of numeric IDs for every user who has a pending request to follow the authenticating user. */ /* GET friendships/outgoing Returns a collection of numeric IDs for every protected user for whom the authenticating user has a pending follow request. */ /* POST friendships/create Returns Users (1: the followed user) Allows the authenticating users to follow the user specified in the ID parameter. Returns the befriended user in the requested format when successful. Returns a string describing the failure condition when unsuccessful. If you are already friends with the user a HTTP 403 may be returned, though for performance reasons you may get a 200 OK message even if the friendship already exists. Actions taken in this method are asynchronous and changes will be eventually consistent. */ - (void)postFollow:(NSString *)screenName successBlock:(void(^)(NSDictionary *user))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST friendships/destroy Returns Users (1: the unfollowed user) Allows the authenticating user to unfollow the user specified in the ID parameter. Returns the unfollowed user in the requested format when successful. Returns a string describing the failure condition when unsuccessful. Actions taken in this method are asynchronous and changes will be eventually consistent. */ - (void)postUnfollow:(NSString *)screenName successBlock:(void(^)(NSDictionary *user))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // POST friendships/update // Returns ? - (void)postUpdateNotifications:(BOOL)notify forScreenName:(NSString *)screenName successBlock:(void(^)(NSDictionary *relationship))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET friendships/show Returns detailed information about the relationship between two arbitrary users. */ /* GET friends/list Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends"). At this time, results are ordered with the most recent following first — however, this ordering is subject to unannounced change and eventual consistency issues. Results are given in groups of 20 users and multiple "pages" of results can be navigated through using the next_cursor value in subsequent requests. See Using cursors to navigate collections for more information. */ - (void)getFriendsForScreenName:(NSString *)screenName successBlock:(void(^)(NSArray *friends))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET followers/list Returns a cursored collection of user objects for users following the specified user. At this time, results are ordered with the most recent following first — however, this ordering is subject to unannounced change and eventual consistency issues. Results are given in groups of 20 users and multiple "pages" of results can be navigated through using the next_cursor value in subsequent requests. See Using cursors to navigate collections for more information. */ - (void)getFollowersForScreenName:(NSString *)screenName successBlock:(void(^)(NSArray *followers))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark Users /* GET account/settings Returns settings (including current trend, geo and sleep time information) for the authenticating user. */ /* GET account/verify_credentials Returns Users (1: the user) Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not. Use this method to test if supplied user credentials are valid. */ - (void)getAccountVerifyCredentialsSkipStatus:(BOOL)skipStatus successBlock:(void(^)(NSDictionary *myInfo))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST account/settings Updates the authenticating user's settings. */ /* POST account/update_delivery_device Sets which device Twitter delivers updates to for the authenticating user. Sending none as the device parameter will disable SMS updates. */ /* POST account/update_profile Returns Users (1: the user) Sets values that users are able to set under the "Account" tab of their settings page. Only the parameters specified will be updated. */ - (void)postUpdateProfile:(NSDictionary *)profileData successBlock:(void(^)(NSDictionary *myInfo))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST account/update_profile_background_image Updates the authenticating user's profile background image. This method can also be used to enable or disable the profile background image. Although each parameter is marked as optional, at least one of image, tile or use must be provided when making this request. */ /* POST account/update_profile_colors Sets one or more hex values that control the color scheme of the authenticating user's profile page on twitter.com. Each parameter's value must be a valid hexidecimal value, and may be either three or six characters (ex: #fff or #ffffff). */ /* POST account/update_profile_image Returns Users (1: the user) Updates the authenticating user's profile image. Note that this method expects raw multipart data, not a URL to an image. This method asynchronously processes the uploaded file before updating the user's profile image URL. You can either update your local cache the next time you request the user's information, or, at least 5 seconds after uploading the image, ask for the updated URL using GET users/show. */ #if TARGET_OS_IPHONE - (void)postUpdateProfileImage:(UIImage *)newImage #else - (void)postUpdateProfileImage:(NSImage *)newImage #endif successBlock:(void(^)(NSDictionary *myInfo))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET blocks/list Returns a collection of user objects that the authenticating user is blocking. Important On October 15, 2012 this method will become cursored by default, altering the default response format. See Using cursors to navigate collections for more details on how cursoring works. */ /* GET blocks/ids Returns an array of numeric user ids the authenticating user is blocking. Important On October 15, 2012 this method will become cursored by default, altering the default response format. See Using cursors to navigate collections for more details on how cursoring works. */ /* POST blocks/create Blocks the specified user from following the authenticating user. In addition the blocked user will not show in the authenticating users mentions or timeline (unless retweeted by another user). If a follow or friend relationship exists it is destroyed. */ /* POST blocks/destroy Un-blocks the user specified in the ID parameter for the authenticating user. Returns the un-blocked user in the requested format when successful. If relationships existed before the block was instated, they will not be restored. */ /* GET users/lookup Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters. This method is especially useful when used in conjunction with collections of user IDs returned from GET friends/ids and GET followers/ids. GET users/show is used to retrieve a single user object. */ /* GET users/show Returns a variety of information about the user specified by the required user_id or screen_name parameter. The author's most recent Tweet will be returned inline when possible. GET users/lookup is used to retrieve a bulk collection of user objects. */ // Returns Users (1: detailed information for the user) - (void)getUserInformationFor:(NSString *)screenName successBlock:(void(^)(NSDictionary *user))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)profileImageFor:(NSString *)screenName #if TARGET_OS_IPHONE successBlock:(void(^)(UIImage *image))successBlock #else successBlock:(void(^)(NSImage *image))successBlock #endif errorBlock:(void(^)(NSError *error))errorBlock; /* GET users/search Provides a simple, relevance-based search interface to public user accounts on Twitter. Try querying by topical interest, full name, company name, location, or other criteria. Exact match searches are not supported. Only the first 1,000 matching results are available. */ - (void)getUsersSearchQuery:(NSString *)query optionalPage:(NSString *)page optionalCount:(NSString *)count includeEntities:(BOOL)includeEntities successBlock:(void(^)(NSDictionary *users))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET users/contributees Returns a collection of users that the specified user can "contribute" to. */ /* GET users/contributors Returns a collection of users who can contribute to the specified account. */ /* POST account/remove_profile_banner Removes the uploaded profile banner for the authenticating user. Returns HTTP 200 upon success. */ /* POST account/update_profile_banner Uploads a profile banner on behalf of the authenticating user. For best results, upload an <5MB image that is exactly 1252px by 626px. Images will be resized for a number of display options. Users with an uploaded profile banner will have a profile_banner_url node in their Users objects. More information about sizing variations can be found in User Profile Images and Banners and GET users/profile_banner. Profile banner images are processed asynchronously. The profile_banner_url and its variant sizes will not necessary be available directly after upload. */ /* GET users/profile_banner Returns a map of the available size variations of the specified user's profile banner. If the user has not uploaded a profile banner, a HTTP 404 will be served instead. This method can be used instead of string manipulation on the profile_banner_url returned in user objects as described in User Profile Images and Banners. */ #pragma mark Suggested Users // GET users/suggestions/:slug // GET users/suggestions // GET users/suggestions/:slug/members #pragma mark Favorites // GET favorites/list // Returns Tweets (20: last 20 favorited tweets) - (void)getFavoritesListWithSuccessBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // POST favorites/destroy // POST favorites/create // Returns Tweets (1: the (un)favorited tweet) - (void)postFavoriteState:(BOOL)favoriteState forStatusID:(NSString *)statusID successBlock:(void(^)(NSDictionary *status))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark Lists /* GET lists/list Returns all lists the authenticating or specified user subscribes to, including their own. The user is specified using the user_id or screen_name parameters. If no user is given, the authenticating user is used. This method used to be GET lists in version 1.0 of the API and has been renamed for consistency with other call. A maximum of 100 results will be returned by this call. Subscribed lists are returned first, followed by owned lists. This means that if a user subscribes to 90 lists and owns 20 lists, this method returns 90 subscriptions and 10 owned lists. The reverse method returns owned lists first, so with reverse=true, 20 owned lists and 80 subscriptions would be returned. If your goal is to obtain every list a user owns or subscribes to, use GET lists/ownerships and/or GET lists/subscriptions instead. */ - (void)getListsSubscribedByUsername:(NSString *)username orUserID:(NSString *)userID reverse:(BOOL)reverse successBlock:(void(^)(NSArray *lists))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET lists/statuses Returns a timeline of tweets authored by members of the specified list. Retweets are included by default. Use the include_rts=false parameter to omit retweets. Embedded Timelines is a great way to embed list timelines on your website. */ - (void)getListsStatusesForListID:(NSString *)listID optionalSinceID:(NSString *)sinceID optionalMaxID:(NSString *)maxID optionalCount:(NSString *)count includeEntities:(BOOL)includeEntities includeRetweets:(BOOL)includeRetweets successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getListsStatusesForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID optionalSinceID:(NSString *)sinceID optionalMaxID:(NSString *)maxID optionalCount:(NSString *)count includeEntities:(BOOL)includeEntities includeRetweets:(BOOL)includeRetweets successBlock:(void(^)(NSArray *statuses))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/members/destroy Removes the specified member from the list. The authenticated user must be the list's owner to remove members from the list. */ - (void)postListsMembersDestroyForListID:(NSString *)listID successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postListsMembersDestroyForSlug:(NSString *)slug optionalUserID:(NSString *)userID optionalScreenName:(NSString *)screenName optionalOwnerScreenName:(NSString *)ownerScreenName optionalOwnerID:(NSString *)ownerID successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET lists/subscribers Returns the subscribers of the specified list. Private list subscribers will only be shown if the authenticated user owns the specified list. */ - (void)getListsSubscribersForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID optionalCursor:(NSString *)cursor includeEntities:(BOOL)includeEntities skipStatus:(BOOL)skipStatus successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getListsSubscribersForListID:(NSString *)listID optionalCursor:(NSString *)cursor includeEntities:(BOOL)includeEntities skipStatus:(BOOL)skipStatus successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/subscribers/create Subscribes the authenticated user to the specified list. */ - (void)postListSubscribersCreateForListID:(NSString *)listID successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postListSubscribersCreateForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET lists/subscribers/show Check if the specified user is a subscriber of the specified list. Returns the user if they are subscriber. */ - (void)getListsSubscribersShowForListID:(NSString *)listID userID:(NSString *)userID orScreenName:(NSString *)screenName includeEntities:(BOOL)includeEntities skipStatus:(BOOL)skipStatus successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getListsSubscribersShowForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID userID:(NSString *)userID orScreenName:(NSString *)screenName includeEntities:(BOOL)includeEntities skipStatus:(BOOL)skipStatus successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/subscribers/destroy Unsubscribes the authenticated user from the specified list. */ - (void)postListSubscribersDestroyForListID:(NSString *)listID successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postListSubscribersDestroyForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/members/create_all Adds multiple members to a list, by specifying a comma-separated list of member ids or screen names. The authenticated user must own the list to be able to add members to it. Note that lists can't have more than 5,000 members, and you are limited to adding up to 100 members to a list at a time with this method. Please note that there can be issues with lists that rapidly remove and add memberships. Take care when using these methods such that you are not too rapidly switching between removals and adds on the same list. */ - (void)postListsMembersCreateAllForListID:(NSString *)listID userIDs:(NSArray *)userIDs // array of strings orScreenNames:(NSArray *)screenNames // array of strings successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postListsMembersCreateAllForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID userIDs:(NSArray *)userIDs // array of strings orScreenNames:(NSArray *)screenNames // array of strings successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET lists/members/show Check if the specified user is a member of the specified list. */ - (void)getListsMembersShowForListID:(NSString *)listID userID:(NSString *)userID screenName:(NSString *)screenName includeEntities:(BOOL)includeEntities skipStatus:(BOOL)skipStatus successBlock:(void(^)(NSDictionary *user))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getListsMembersShowForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID userID:(NSString *)userID screenName:(NSString *)screenName includeEntities:(BOOL)includeEntities skipStatus:(BOOL)skipStatus successBlock:(void(^)(NSDictionary *user))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET lists/members Returns the members of the specified list. Private list members will only be shown if the authenticated user owns the specified list. */ - (void)getListsMembersForListID:(NSString *)listID optionalCursor:(NSString *)cursor includeEntities:(BOOL)includeEntities skipStatus:(BOOL)skipStatus successBlock:(void(^)(NSArray *users, NSString *previousCursor, NSString *nextCursor))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getListsMembersForSlug:(NSString *)slug ownerScreenName:(NSString *)screenName orOwnerID:(NSString *)ownerID optionalCursor:(NSString *)cursor includeEntities:(BOOL)includeEntities skipStatus:(BOOL)skipStatus successBlock:(void(^)(NSArray *users, NSString *previousCursor, NSString *nextCursor))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/members/create Creates a new list for the authenticated user. Note that you can't create more than 20 lists per account. */ - (void)postListMemberCreateForListID:(NSString *)listID userID:(NSString *)userID screenName:(NSString *)screenName successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postListMemberCreateForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID userID:(NSString *)userID screenName:(NSString *)screenName successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/destroy Deletes the specified list. The authenticated user must own the list to be able to destroy it. */ - (void)postListsDestroyForListID:(NSString *)listID successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postListsDestroyForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/update Updates the specified list. The authenticated user must own the list to be able to update it. */ - (void)postListsUpdateForListID:(NSString *)listID optionalName:(NSString *)name isPrivate:(BOOL)isPrivate optionalDescription:(NSString *)description successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postListsUpdateForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID optionalName:(NSString *)name isPrivate:(BOOL)isPrivate optionalDescription:(NSString *)description successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/create Creates a new list for the authenticated user. Note that you can't create more than 20 lists per account. */ - (void)postListsCreateWithName:(NSString *)name isPrivate:(BOOL)isPrivate optionalDescription:(NSString *)description successBlock:(void(^)(NSDictionary *list))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET lists/show Returns the specified list. Private lists will only be shown if the authenticated user owns the specified list. */ - (void)getListsShowListID:(NSString *)listID successBlock:(void(^)(NSDictionary *list))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getListsShowListSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID successBlock:(void(^)(NSDictionary *list))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET lists/subscriptions Obtain a collection of the lists the specified user is subscribed to, 20 lists per page by default. Does not include the user's own lists. */ - (void)getListsSubscriptionsForUserID:(NSString *)userID orScreenName:(NSString *)screenName optionalCount:(NSString *)count optionalCursor:(NSString *)cursor successBlock:(void(^)(NSArray *lists, NSString *previousCursor, NSString *nextCursor))successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* POST lists/members/destroy_all Removes multiple members from a list, by specifying a comma-separated list of member ids or screen names. The authenticated user must own the list to be able to remove members from it. Note that lists can't have more than 500 members, and you are limited to removing up to 100 members to a list at a time with this method. Please note that there can be issues with lists that rapidly remove and add memberships. Take care when using these methods such that you are not too rapidly switching between removals and adds on the same list. */ - (void)postListsMembersDestroyAllForListID:(NSString *)listID userIDs:(NSArray *)userIDs // array of strings orScreenNames:(NSArray *)screenNames // array of strings successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)postListsMembersDestroyAllForSlug:(NSString *)slug ownerScreenName:(NSString *)ownerScreenName orOwnerID:(NSString *)ownerID userIDs:(NSArray *)userIDs // array of strings orScreenNames:(NSArray *)screenNames // array of strings successBlock:(void(^)())successBlock errorBlock:(void(^)(NSError *error))errorBlock; /* GET lists/ownerships Returns the lists owned by the specified Twitter user. Private lists will only be shown if the authenticated user is also the owner of the lists. */ - (void)getListsOwnershipsForUserID:(NSString *)userID orScreenName:(NSString *)screenName optionalCount:(NSString *)count optionalCursor:(NSString *)cursor successBlock:(void(^)(NSArray *lists, NSString *previousCursor, NSString *nextCursor))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark Saved Searches #pragma mark Places & Geo // GET geo/id/:place_id // GET geo/reverse_geocode // Returns Places (*: up to 20 places that match the lat/lon) - (void)getGeoReverseGeocodeWithLatitude:(NSString *)latitude longitude:(NSString *)longitude successBlock:(void(^)(NSArray *places))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // GET geo/search // Returns Places (*: places that match the lat/lon) - (void)getGeoSearchWithLatitude:(NSString *)latitude longitude:(NSString *)longitude successBlock:(void(^)(NSArray *places))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getGeoSearchWithIPAddress:(NSString *)ipAddress successBlock:(void(^)(NSArray *places))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getGeoSearchWithQuery:(NSString *)query successBlock:(void(^)(NSArray *places))successBlock errorBlock:(void(^)(NSError *error))errorBlock; // GET geo/similar_places // POST geo/place #pragma mark Trends #pragma mark Spam Reporting - (void)postReportSpamWithScreenName:(NSString *)screenName orUserID:(NSString *)userID successBlock:(void(^)(id userProfile))successBlock errorBlock:(void(^)(NSError *error))errorBlock; #pragma mark OAuth #pragma mark Help // GET application/rate_limit_status // Returns ? - (void)getRateLimitsForResources:(NSArray *)resources successBlock:(void(^)(NSDictionary *rateLimits))successBlock errorBlock:(void(^)(NSError *error))errorBlock; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.5/newsApp/Cliente.h
// // Cliente.h // newsApp // // Created by <NAME> on 08/05/14. // Copyright (c) 2014 Espí & Le Barbier. All rights reserved. // #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> @interface Cliente : NSManagedObject @property (nonatomic, retain) NSString * nif; @property (nonatomic, retain) NSString * nombre; @property (nonatomic, retain) NSSet *facturasDelCliente; @end @interface Cliente (CoreDataGeneratedAccessors) - (void)addFacturasDelClienteObject:(NSManagedObject *)value; - (void)removeFacturasDelClienteObject:(NSManagedObject *)value; - (void)addFacturasDelCliente:(NSSet *)values; - (void)removeFacturasDelCliente:(NSSet *)values; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.2/newsApp/ELBListaPeriodicosTableViewController.h
<reponame>miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-<gh_stars>0 // // ELBListaPeriodicosTableViewController.h // newsApp // // Created by <NAME> on 12/06/13. // Copyright (c) 2013 Espí & Le Barbier. All rights reserved. // #import <UIKit/UIKit.h> @interface ELBListaPeriodicosTableViewController : UITableViewController @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
funnyApp 1.3/funnyApp/ELBRotateTabBarController.h
<reponame>miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-<gh_stars>0 // // ELBRotateTabBarController.h // funnyApp // // Created by <NAME> on 14/06/13. // Copyright (c) 2013 Espí & Le Barbier. All rights reserved. // #import <UIKit/UIKit.h> //@interface ELBRotateTabBarController : UITabBarController @interface UITabBarController (rotate) @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBDetalleArticuloViewController.h
<gh_stars>0 // // ELBDetalleArticuloViewController.h // newsApp // // Created by <NAME> on 09/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <UIKit/UIKit.h> #import <MessageUI/MessageUI.h> @class ELBArticulo; @interface ELBDetalleArticuloViewController : UIViewController <MFMailComposeViewControllerDelegate,UIActionSheetDelegate> @property (strong, nonatomic) IBOutlet UITextView *articuloTextView; @property (nonatomic, strong) ELBArticulo *articulo; - (IBAction)cerrar:(id)sender; - (IBAction)compartir:(id)sender; //- (void) setArticulo:(ELBArticulo *)articulo; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
funnyApp 1.3/funnyAppTests/funnyAppTests.h
// // funnyAppTests.h // funnyAppTests // // Created by <NAME> on 08/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <XCTest/XCTest.h> @interface funnyAppTests : XCTestCase @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.5/newsApp/ELBArticuloViewController.h
// // ELBArticuloViewController.h // newsApp // // Created by <NAME> on 09/06/13. // Copyright (c) 2013 Espí & <NAME>. All rights reserved. // #import <UIKit/UIKit.h> @class ELBArticulo; @interface ELBArticuloViewController : UIViewController @property (strong, nonatomic) IBOutlet UITextField *nombreEscritorTextField; @property (strong, nonatomic) IBOutlet UITextField *fechaArticuloTextField; @property (strong, nonatomic) IBOutlet UITextView *textoArticuloTextView; - (IBAction)ocultarTeclado:(id)sender; - (void) setFecha: (NSDate *) fecha; - (void) setArticulo : (ELBArticulo *)articulo; - (IBAction)send:(id)sender; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/newsApp/ELBPost.h
// // ELBPost.h // // // Created by <NAME> on 13/06/13. // Copyright (c) 2013 Espí & Le Barbier. All rights reserved. // #import <Foundation/Foundation.h> #define MAX_POSTS 20 @interface ELBPost : NSObject @property (readonly) NSString *iden; @property (readonly) NSString *texto; @property (readonly) NSDate *creado; - (id)initWithAttributes:(NSDictionary *)attributes; - (BOOL) isEqual:(id)object; + (void)ultimosPost:(void (^)(NSArray *post,NSError *error))completionBlock total:(int)total; @end
miguelgutierrez/Curso-iOS-ObjC-Programming-Netmind-
newsApp 1.9/STTwitter/STTwitterOAuthOSX.h
<gh_stars>1-10 // // MGTwitterEngine+TH.h // TwitHunter // // Created by <NAME> on 5/1/10. // Copyright 2010 <EMAIL>. All rights reserved. // #import <Foundation/Foundation.h> #import "STTwitterOAuthProtocol.h" #if TARGET_OS_IPHONE #else typedef void (^STTE_completionBlock_t)(NSArray *statuses); typedef void (^STTE_errorBlock_t)(NSError *error); @class ACAccount; @interface STTwitterOAuthOSX : NSObject <STTwitterOAuthProtocol> { } - (BOOL)canVerifyCredentials; - (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBlock errorBlock:(void(^)(NSError *error))errorBlock; - (void)getResource:(NSString *)resource parameters:(NSDictionary *)params successBlock:(STTE_completionBlock_t)completionBlock errorBlock:(STTE_errorBlock_t)errorBlock; - (void)postResource:(NSString *)resource parameters:(NSDictionary *)params successBlock:(STTE_completionBlock_t)completionBlock errorBlock:(STTE_errorBlock_t)errorBlock; - (NSString *)username; @end #endif
MuthuvelKaruppanaGounder/OCDMI
IMediaSessionSystem.h
<reponame>MuthuvelKaruppanaGounder/OCDMI<gh_stars>1-10 /* * Copyright 2018 Metrological * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <nagra/prm_asm.h> #include <nagra/prm_dsm.h> namespace CDMi { struct IMediaSessionConnect; struct IMediaSessionSystem { virtual TNvSession OpenDescramblingSession(IMediaSessionConnect* session, const uint32_t TSID, const uint16_t Emi) = 0; //returns Descramlbingsession ID virtual void CloseDescramblingSession(TNvSession session, const uint32_t TSID) = 0; virtual void SetPrmContentMetadata(TNvSession descamblingsession, TNvBuffer* data, TNvStreamType streamtype) = 0; virtual void SetPlatformMetadata(TNvSession descamblingsession, const uint32_t TSID, uint8_t *data, size_t size) = 0; virtual void Addref() const = 0; virtual uint32_t Release() const = 0; }; #ifdef __cplusplus extern "C" { #endif CDMi::IMediaSessionSystem* GetMediaSessionSystemInterface(const char* systemsessionid); #ifdef __cplusplus } #endif } // namespace CDMi
MuthuvelKaruppanaGounder/OCDMI
Report.h
/* * Copyright 2018 Metrological * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <core/core.h> #define REPORT_PRM_EXT(success, result, callname, x, ...) \ if( result != success ) { \ fprintf(stderr, "Call to %s failed, result = [%d]" #x "\n", callname, result, __VA_ARGS__); \ fflush(stderr); \ } #define REPORT_PRM(success, result, callname) \ if( result != success ) { \ fprintf(stderr, "Call to %s failed, result = [%d]\n", callname, result); \ fflush(stderr); \ } #define REPORT(x) \ fprintf(stderr, #x "\n"); \ fflush(stderr); #define REPORT_EXT(x, ...) \ fprintf(stderr, #x "\n", __VA_ARGS__); \ fflush(stderr); #define REPORT_ASM_EXT(result, callname, x, ...) REPORT_PRM_EXT(NV_ASM_SUCCESS, callname, x, ...) #define REPORT_ASM(result, callname) REPORT_PRM(NV_ASM_SUCCESS, result, callname) #define REPORT_DSM_EXT(result, callname, x, ...) REPORT_PRM_EXT(NV_DSM_SUCCESS, callname, x, ...) #define REPORT_DSM(result, callname) REPORT_PRM(NV_DSM_SUCCESS, result, callname) #define REPORT_LDS_EXT(result, callname, x, ...) REPORT_PRM_EXT(NV_LDS_SUCCESS, callname, x, ...) #define REPORT_LDS(result, callname) REPORT_PRM(NV_LDS_SUCCESS, result, callname) #define REPORT_IMSM_EXT(result, callname, x, ...) REPORT_PRM_EXT(NV_IMSM_SUCCESS, callname, x, ...) #define REPORT_IMSM(result, callname) REPORT_PRM(NV_IMSM_SUCCESS, result, callname) #define REPORT_DPSC_EXT(result, callname, x, ...) REPORT_PRM_EXT(NV_DPSC_SUCCESS, callname, x, ...) #define REPORT_DPSC(result, callname) REPORT_PRM(NV_DPSC_SUCCESS, result, callname) static void DumpData(const char* buffername, const uint8_t data[], const uint16_t size) { printf("Data for [%s] with length [%d]:\n", buffername, size); if( size != 0 && data != nullptr) { for (uint16_t teller = 0; teller < size; teller++) { printf("%02X ", data[teller]); if (((teller + 1) & 0x7) == 0) { printf("\n"); } } } printf("\n\n"); fflush(stdout); }
MuthuvelKaruppanaGounder/OCDMI
MediaRequest.h
/* * Copyright 2018 Metrological * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <core/core.h> #pragma once namespace CDMi { using requestsSize = uint32_t; // do not just increase the size, part of the interface specification! enum class Request : requestsSize { NONE = 0x0000, FILTERS = 0x0001, KEYREADY = 0x0002, KEYNEEDED = 0x0004, RENEWAL = 0x0008, EMMDELIVERY = 0x0010, PROVISION = 0x0020, ECMDELIVERY = 0x0040, PLATFORMDELIVERY = 0x0080, }; } // namespace CDMi
kkkon/test_cef
test_cef_app/cef_client.h
<reponame>kkkon/test_cef /** * The MIT License * * Copyright (C) 2017 <NAME> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #pragma once #include "include/cef_client.h" #include "include/base/cef_lock.h" #include <list> class Client : public CefClient //, public CefDisplayHandler , public CefLifeSpanHandler , public CefLoadHandler , public CefRequestHandler #if defined(USE_CEF_OFFSCREEN) , public CefRenderHandler #endif // defined(USE_CEF_OFFSCREEN) , public CefFocusHandler { public: Client() {} CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE { return this; } // CefLifeSpanHandler void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE; void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE; CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE { return this; } // CefLoadHandler void OnLoadingStateChange( CefRefPtr<CefBrowser> browser , bool isLoading , bool canGoBack , bool canGoForward ) OVERRIDE; #if 0 void OnLoadEnd( CefRefPtr<CefBrowser> browser , CefRefPtr<CefFrame> frame , int httpStatusCode ) OVERRIDE; void OnLoadError( CefRefPtr<CefBrowser> browser , CefRefPtr<CefFrame> frame , ErrorCode errorCode , const CefString& errorText , const CefString& failedURL ) OVERRIDE; #endif CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE { return this; } // CefRequestHandler CefRefPtr<CefResourceHandler> GetResourceHandler( CefRefPtr<CefBrowser> browser , CefRefPtr<CefFrame> frame , CefRefPtr<CefRequest> request ) OVERRIDE; // CefResourceHandler CefRequestHandler::ReturnValue OnBeforeResourceLoad( CefRefPtr<CefBrowser> browser , CefRefPtr<CefFrame> frame , CefRefPtr<CefRequest> request , CefRefPtr<CefRequestCallback> callback ) OVERRIDE; #if defined(USE_CEF_OFFSCREEN) CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE { return this; } // CefRenderHandler bool GetViewRect( CefRefPtr<CefBrowser> browser , CefRect& rect ) OVERRIDE; void OnPaint( CefRefPtr<CefBrowser> browser , PaintElementType type , const RectList& dirtyRects , const void* buffer , int width, int height ) OVERRIDE; #endif // defined(USE_CEF_OFFSCREEN) CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE { return this; } // CefFocusHandler void OnGotFocus( CefRefPtr<CefBrowser> browser ) OVERRIDE; private: IMPLEMENT_REFCOUNTING(Client); DISALLOW_COPY_AND_ASSIGN(Client); };
Miladxsar23/terminal-regular-command-with-javascript-and-cpp
stat/stat-cpp/checktype.h
#include <iostream> #include <sys/types.h> using namespace std; string typeOfFile(int mode) { if(S_ISREG(mode)) { return "regular File"; }else if(S_ISDIR(mode)) { return "directory File"; }else { return "special File"; } }
agrishutin/teambook
contrib/su4/cpp2tex/include/data/set.h
/* * This file [data/set.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { template <template <typename Type> class CollectionTemplate, typename Type> class Set; } #include "../basic/types.h" template <template <typename Type> class CollectionTemplate, typename Type> class tamias::Set { public: typedef typename CollectionTemplate<Type>::Iterator Iterator; typedef typename CollectionTemplate<Type>::ConstIterator ConstIterator; public: Set(); Set( Set <CollectionTemplate, Type> const &set ); Set& operator = ( Set const &set ); ~Set(); sizetype size() const; void insert( Type const &value ); void erase( Type const &value ); sizetype count( const Type &value ) const; Iterator begin(); Iterator end(); ConstIterator begin() const; ConstIterator end() const; // TODO: other iterators, methods etc private: CollectionTemplate <Type> collection; }; #include "set_implementation.h"
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/utilities.h
/* * This file [basic/utilities.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_basic_utilities_h_ #define _libtamias_basic_utilities_h_ #include "../basic/types.h" namespace tamias { namespace utilities { void memoryCopy( void *target, const void *source, sizetype size ); void memorySet( void *target, char filler, sizetype size ); template <typename ValueType> ValueType abs( ValueType value ); template <typename ValueType> ValueType min( ValueType value1, ValueType value2 ); template <typename ValueType> ValueType max( ValueType value1, ValueType value2 ); template <typename ValueType> void swap( ValueType &a, ValueType &b ); template <typename IteratorType> void reverse( IteratorType begin, IteratorType end ); template <typename ExceptionType> void assert( bool expression ); template <typename ExceptionType, typename ErrorType> void assert( bool expression, ErrorType error ); }; } template <typename ValueType> ValueType tamias::utilities::abs( ValueType value ) { if (value < 0) return -value; return value; } template <typename ValueType> ValueType tamias::utilities::min( ValueType value1, ValueType value2 ) { if (value1 <= value2) return value1; return value2; } template <typename ValueType> ValueType tamias::utilities::max( ValueType value1, ValueType value2 ) { if (value1 >= value2) return value1; return value2; } template <typename ValueType> void tamias::utilities::swap( ValueType &a, ValueType &b ) { ValueType c = a; a = b, b = c; } template <typename IteratorType> void tamias::utilities::reverse( IteratorType begin, IteratorType end ) { while (begin != end) { end--; if (begin == end) break; swap(*begin, *end); begin++; } } template <typename ExceptionType> void tamias::utilities::assert( bool expression ) { if (!expression) throw ExceptionType(); } template <typename ExceptionType, typename ErrorType> void tamias::utilities::assert( bool expression, ErrorType error ) { if (!expression) throw ExceptionType(error); } #endif /* _libtamias_basic_utilities_h_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/byte_array.h
/* * This file [basic/byte_array.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once #include "../basic/abstract_data.h" #include "../basic/iterator.h" #include "../basic/types.h" #include "../basic/utilities.h" namespace tamias { /* class ByteArray stores some binary data, or string in generic 8-bit encoding */ class ByteArray : private hidden::AbstractData { public: typedef tamias::hidden::DefaultIterator<char*> Iterator; typedef tamias::hidden::DefaultConstIterator<char*> ConstIterator; typedef tamias::hidden::DefaultReverseIterator<char*> ReverseIterator; typedef tamias::hidden::DefaultConstReverseIterator<char*> ConstReverseIterator; private: sizetype arraySize; public: ByteArray(); ByteArray( char source ); ByteArray( const char *source ); ByteArray( const void *source, sizetype sourceSize ); ByteArray( const ByteArray &source ); ByteArray& operator = ( const ByteArray &source ); ~ByteArray(); // ByteArray& operator = ( char source ); // ByteArray& operator = ( const char *source ); template <typename Type> static ByteArray makeDump( const Type &source ); ByteArray& operator += ( const ByteArray &source ); ByteArray operator + ( const ByteArray &source ) const; sizetype size() const; sizetype length() const; char& operator [] ( sizetype index); char operator [] ( sizetype index) const; Iterator begin(); ConstIterator begin() const; Iterator end(); ConstIterator end() const; ReverseIterator reverseBegin(); ConstReverseIterator reverseBegin() const; ReverseIterator reverseEnd(); ConstReverseIterator reverseEnd() const; int compare( char source ) const; int compare( const char *source ) const; int compare( const ByteArray &source) const; sizetype find( char source ) const; sizetype find( const char *source ) const; sizetype find( const ByteArray &source ) const; ByteArray subString( sizetype index, sizetype size ) const; void write( void *target, sizetype size ) const; char* cString(); const char* cString() const; bool operator < ( char source ) const; bool operator < ( const char *source ) const; bool operator < ( const ByteArray &source ) const; bool operator <= ( char source ) const; bool operator <= ( const char *source ) const; bool operator <= ( const ByteArray &source ) const; bool operator > ( char source ) const; bool operator > ( const char *source ) const; bool operator > ( const ByteArray &source ) const; bool operator >= ( char source ) const; bool operator >= ( const char *source ) const; bool operator >= ( const ByteArray &source ) const; bool operator == ( char source ) const; bool operator == ( const char *source ) const; bool operator == ( const ByteArray &source ) const; bool operator != ( char source ) const; bool operator != ( const char *source ) const; bool operator != ( const ByteArray &source ) const; }; ByteArray operator + ( char first, const ByteArray &second ); ByteArray operator + ( const char *first, const ByteArray &second ); bool operator < ( char first, const ByteArray &second ); bool operator < ( const char *first, const ByteArray &second ); bool operator <= ( char first, const ByteArray &second ); bool operator <= ( const char *first, const ByteArray &second ); bool operator > ( char first, const ByteArray &second ); bool operator > ( const char *first, const ByteArray &second ); bool operator >= ( char first, const ByteArray &second ); bool operator >= ( const char *first, const ByteArray &second ); bool operator == ( char first, const ByteArray &second ); bool operator == ( const char *first, const ByteArray &second ); bool operator != ( char first, const ByteArray &second ); bool operator != ( const char *first, const ByteArray &second ); } template <typename Type> tamias::ByteArray tamias::ByteArray::makeDump( const Type &source ) { return ByteArray(&source, sizeof(Type)); }
agrishutin/teambook
contrib/su4/cpp2tex/include/sql/query.h
/* * This file [sql/query.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { namespace sql { class Query; // Format-like method for creating queries } } #include "../io/format.h" class tamias::sql::Query : public Format { public: Query( String const &format ); Query( Query const &query ); Query& operator = ( Query const &query ); ~Query(); static String escape( String const &s ); protected: String handle( ValueType type, String const &spec, char value ); String handle( ValueType type, String const &spec, char const *value ); String handle( ValueType type, String const &spec, String const &value ); };
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/types.h
<gh_stars>10-100 /* * This file [basic/types.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_basic_types_ #define _libtamias_basic_types_ namespace tamias { /* These types are correct on i386+ and x86_64 archetictures */ /* But I think that on x86_64 int should be 64-bit, not long */ typedef char inttype8; typedef unsigned char uinttype8; typedef short int inttype16; typedef unsigned short int uinttype16; typedef int inttype32; typedef unsigned int uinttype32; typedef long long inttype64; typedef unsigned long long uinttype64; typedef unsigned long sizetype; /* 32-bit on i386+ and 64-bit on x86_64 */ typedef uinttype32 chartype; /* utf32 character */ } #endif /* _libtamias_basic_types_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/random_lcg.h
#pragma once #include "../basic/string.h" #include "../basic/types.h" namespace tamias { namespace wtf { class LCGRandom { public: LCGRandom( uinttype64 seed = 0 ); ~LCGRandom(); void setSeed( uinttype64 seed ); uinttype32 next(); String nextToken( sizetype length ); // TODO: setup character set private: LCGRandom( LCGRandom const &random ); LCGRandom& operator = ( LCGRandom const &random ); uinttype64 lcg; }; } }
agrishutin/teambook
contrib/su4/cpp2tex/include/network/socket.h
<reponame>agrishutin/teambook<filename>contrib/su4/cpp2tex/include/network/socket.h<gh_stars>10-100 /* * This file [network/socket.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_network_socket_h_ #define _libtamias_network_socket_h_ #include <errno.h> #include <netdb.h> #include <poll.h> #include <unistd.h> #include <sys/socket.h> #include <sys/types.h> #include "../basic/byte_array.h" #include "../basic/types.h" #include "../basic/string.h" #include "../io/event_poll.h" #include "../io/iodevice.h" #include "../io/ioexception.h" #include "../network/ip.h" namespace tamias { class Socket : public IODevice, public EventFd { public: enum SocketState { NOSOCKET, // TODO: rename to STATE_NOSOCKET etc... ERROR, CONNECTED, CLOSED, FINISHED }; Socket(); Socket( const Socket &socket ); Socket& operator = ( const Socket &socket ); ~Socket(); Socket* clone() const; bool canRead() const; bool canWrite() const; bool canSeek() const; void close(); bool eof(); bool waitForRead(); ByteArray read( sizetype maxSize = (sizetype)-1 ); sizetype write( const ByteArray &data ); void seek( sizetype index ); friend class TcpClientSocket; friend class TcpServerSocket; SocketState state() const; IpAddress foreignIp() const; private: SocketState socketState; int socketHandle; Socket( int newHandle ); int handle(); }; class TcpClientSocket : public Socket { // TODO: standart methods (constructors, destructor, copy) public: void connect( const String &host, const uinttype16 port ); void disconnect(); }; class TcpServerSocket : public Socket // TODO: this public is only for EventFd::handle() { // TODO: standart methods (constructors, destructor, copy) public: void bind( const uinttype16 port ); Socket accept(); }; } #endif // _libtamias_network_socket_h_
agrishutin/teambook
contrib/su4/cpp2tex/include/data/byte_queue.h
<reponame>agrishutin/teambook /* * This file [data/byte_queue.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { class ByteQueue; } #include "../basic/abstract_data.h" #include "../basic/byte_array.h" #include "../basic/exception.h" #include "../basic/utilities.h" #include "../basic/types.h" class tamias::ByteQueue : private hidden::AbstractData { public: ByteQueue(); ByteQueue( ByteQueue const &queue ); ByteQueue& operator = ( ByteQueue const &queue ); ~ByteQueue(); sizetype size() const; char operator [] ( sizetype index ) const; char& operator [] ( sizetype index ); void append( ByteArray const &data ); ByteArray get( sizetype size ); void clear(); private: sizetype mStart, mSize; };
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/web_utilities.h
<filename>contrib/su4/cpp2tex/include/wtf/web_utilities.h<gh_stars>10-100 #pragma once #include "../basic/byte_array.h" #include "../basic/string.h" #include "../basic/types.h" namespace tamias { namespace wtf { namespace web { namespace utilities { String decodeURIString( const ByteArray &source ); String encodeHTTPParameter( const String &source ); } } } }
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/debug.h
<gh_stars>10-100 /* * libtamias/wtf/debug.h — package for debug output */ #pragma once /* * About debug levels. * Normally debug levels are numbered from 0 (no output) to n-1 (full output) for some n. * So if output device accept level x it would receive all debug with level less or equal to x. * Nothing cat stop you to use negative levels ^_~ * Example debug levels (from testsys): * 0 NOLOGGING * 1 FATAL * 2 ERROR * 3 WARNING * 4 INFO * 5 DIAG * 6 DEBUG * 7 EXTRADEBUG * 8 NEVER */ #include <cstdarg> #include "../basic/string.h" #include "../data/pair.h" #include "../io/iodevice.h" #include "../io/printer.h" #include "../main/vector.h" namespace tamias { namespace wtf { class DebugOutput { public: DebugOutput(); DebugOutput( const DebugOutput &output ); DebugOutput& operator = ( const DebugOutput &output ); ~DebugOutput(); void addOutput( IODevice &output, int debugLevel ); void output( int debugLevel, const String &format, ... ); private: Vector <Pair <int, Printer*> > mPrinters; }; } }
agrishutin/teambook
contrib/su4/cpp2tex/include/system/thread_implementation.h
/* * This file [system/thread_implementation.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ template <typename ClassType> tamias::MethodThread<ClassType>::MethodThread( ClassType &object, Function function ) : Thread(), mObject(&object), mFunction(function) { } template <typename ClassType> tamias::MethodThread<ClassType>::MethodThread( ClassType *object, Function function ) : Thread(), mObject(object), mFunction(function) { } template <typename ClassType> tamias::MethodThread<ClassType>::MethodThread( MethodThread const &thread ) : Thread(thread), mObject(thread.mObject), mFunction(thread.mFunction) { } template <typename ClassType> tamias::MethodThread<ClassType>& tamias::MethodThread<ClassType>::operator = ( MethodThread const &thread ) { Thread::operator = (thread); mFunction = thread.mFunction; mObject = thread.mObject; return *this; } template <typename ClassType> tamias::MethodThread<ClassType>::~MethodThread() { } template <typename ClassType> void* tamias::MethodThread<ClassType>::run() { (mObject->*mFunction)(); return NULL; }
agrishutin/teambook
contrib/su4/cpp2tex/include/sql/driver.h
<reponame>agrishutin/teambook /* * This file [sql/driver.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_sql_driver_h_ #define _libtamias_sql_driver_h_ #include <dlfcn.h> #include "../basic/types.h" #include "../basic/string.h" #include "../sql/exception.h" namespace tamias { namespace sql { class Driver { public: Driver(); Driver( const Driver &driver ); virtual ~Driver(); Driver& operator = ( const Driver &driver ); virtual uinttype32 setHost( const String &newHost ) = 0; virtual uinttype32 setUser( const String &newUser ) = 0; virtual uinttype32 setUser( const String &newUser, const String &newPassword ) = 0; virtual uinttype32 setDatabase( const String &newDatabase ) = 0; virtual uinttype32 connect() = 0; virtual uinttype32 disconnect() = 0; virtual uinttype32 query( const String &query, uinttype32 *resultHandle ) = 0; virtual uinttype32 resultNext( uinttype32 resultHandle ) = 0; virtual uinttype32 resultFree( uinttype32 resultHandle ) = 0; virtual uinttype32 resultGet( uinttype32 resultHandle, sizetype column, String *result ) = 0; virtual uinttype32 resultGet( uinttype32 resultHandle, const String &column, String *result ) = 0; virtual String errorString( uinttype32 error ) = 0; virtual void errorFree( uinttype32 error ) = 0; }; class ExternalDriver { private: typedef Driver* (*CreateFunction)(); public: ExternalDriver(); ExternalDriver( const ExternalDriver &driver ); ~ExternalDriver(); ExternalDriver& operator = ( const ExternalDriver &driver ); static Driver* loadDriver( const String &fileName ); }; } } #endif /* _libtamias_sql_driver_h_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/terve_generator.h
#pragma once #include "../basic/byte_array.h" #include "../basic/string.h" #include "../basic/types.h" #include "../data/pair.h" #include "../main/map.h" #include "../main/tree_rbst.h" #include "../main/vector.h" #include "../io/file.h" #include "../io/scanner.h" #include "../wtf/utilities.h" #include "../wtf/terve_entity.h" /* * У меня самого не получилось через 2 дня вспомнить, что на что а как должно ссылаться. * Видимо, это означает, что надо написать какое-то описание. —burunduk3 * * Есть следующие сущности: * 1. Строчка (ENTITY_STRING). Характеризуется индексом в массиве templateStrings, означает тупо текст. * 2. Непереведённая строчка (ENTITY_I18N). Характеризуется индексом в templateStrings и значением * в отображении templateI18n. Означает строчку, к которой ещё нужно применить (это происходит в * функции assemble) это отображение. * 3. Встроенный кусок (ENTITY_PART). Характеризуется индексом в templateParts, означает набор * сущностей. * 4. Выключный кусок (ENTITY_MULTIPART). Характеризется индексом в templateMutliParts, означает * набор полных строк (line) и сдвигов — на сколько требуется сдвинуть все внутренние строки, если * это ссылка на другой выключный кусок. Сдвиги складываются. * Вспомогательные элементы: * 1. Переменные. Отображение строчек в сущности. * 2. Полная строка. Набор сущностей. * TODO: * 1. Выделить элемент «ссылка на шаблон». Зачем? * 2. Сделать line отдельной сущностью. * 3. Переписать это описание ^_^ * Внезапно! Объекты типа Entity вообще-то жёстко привязаны к шаблону. Так-то. */ namespace tamias { namespace wtf { namespace terve { class Generator { public: Generator(); Generator( const Generator &generator ); Generator& operator = ( const Generator &generator ); ~Generator(); Generator& setVariable( const String &name, const Entity &entity ); // методы add{Test,I18n,Line,Group,Template} возвращают ссылку на построенную сущность. Entity addText( const String &text ); Entity addI18n( const String &text ); Entity addLine( const Vector <Entity> &line, sizetype indent = 0 ); Entity addGroup( const Vector <Entity> &group); Entity addTemplate( const ByteArray &fileName ); Map <RBSTree, String, String>& i18n(); String assemble( const Entity &root ); void clear(); static String escape( const String &s ); private: Vector <String> mStrings; Vector <Pair <Vector <Entity>, sizetype> > mLines; Vector <Vector <Entity> > mGroups; Map <RBSTree, String, String> mI18n; Map <RBSTree, String, Entity> mVariables; sizetype createString( const String &string ); sizetype createLine(); // creates an empty line sizetype createGroup(); // creates an empty group void dfs( const Entity &entity, String &result, sizetype indent ); }; } } }
agrishutin/teambook
contrib/su4/cpp2tex/include/io/file.h
/* * This file [io/file.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_io_file_h_ #define _libtamias_io_file_h_ #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include "../basic/byte_array.h" #include "../basic/types.h" #include "../io/ioexception.h" #include "../io/iodevice.h" namespace tamias { class File : public IODevice { public: enum OpenMode { CLOSED, OPEN_READ, OPEN_WRITE, OPEN_RW }; private: int handle; uinttype64 filePos, fileSize; OpenMode openMode; File( int handle, OpenMode newOpenMode ); public: static File stdin; static File stdout; static File stderr; File(); File( const File &file ); File& operator = ( const File &file ); virtual ~File(); virtual IODevice* clone() const; static File openRead( const ByteArray &fileName ); static File openWrite( const ByteArray &fileName ); virtual bool canRead() const; virtual bool canWrite() const; virtual bool canSeek() const; virtual void close(); virtual bool eof(); virtual bool waitForRead(); virtual ByteArray read( sizetype maxSize = (sizetype)-1 ); virtual sizetype write( const ByteArray &data ); virtual void seek( sizetype index ); }; } #endif /* _libtamias_io_file_h_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/iterator.h
/* * This file [basic/iterator.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_basic_iterator_h #define _libtamias_basic_iterator_h #include <cstdlib> #include "../basic/types.h" namespace tamias { namespace hidden { template <typename IteratorType> class IteratorTypes { public: typedef typename IteratorType::ValueType ValueType; typedef typename IteratorType::Pointer Pointer; typedef typename IteratorType::Reference Reference; typedef typename IteratorType::ConstPointer ConstPointer; typedef typename IteratorType::ConstReference ConstReference; }; template <typename Type> class IteratorTypes <Type*> { public: typedef Type ValueType; typedef Type* Pointer; typedef Type& Reference; typedef const Type* ConstPointer; typedef const Type& ConstReference; }; template <typename IteratorType> class DefaultIterator { public: typedef typename IteratorTypes<IteratorType>::ValueType ValueType; typedef typename IteratorTypes<IteratorType>::Pointer Pointer; typedef typename IteratorTypes<IteratorType>::Reference Reference; typedef typename IteratorTypes<IteratorType>::ConstPointer ConstPointer; typedef typename IteratorTypes<IteratorType>::ConstReference ConstReference; private: Pointer pointer; public: DefaultIterator( Pointer value = NULL ); DefaultIterator( const DefaultIterator &iterator ); ~DefaultIterator(); DefaultIterator<IteratorType>& operator = ( const DefaultIterator &iterator ); Reference operator * () const; Pointer operator -> () const; Reference operator [] ( sizetype offset ) const; DefaultIterator& operator ++ (); DefaultIterator operator ++ ( int ); DefaultIterator& operator -- (); DefaultIterator operator -- ( int ); DefaultIterator& operator += ( sizetype offset ); DefaultIterator& operator -= ( sizetype offset ); DefaultIterator operator + ( sizetype offset ) const; DefaultIterator operator - ( sizetype offset ) const; bool operator == ( const DefaultIterator &second ) const; bool operator != ( const DefaultIterator &second ) const; bool operator < ( const DefaultIterator &second ) const; bool operator <= ( const DefaultIterator &second ) const; bool operator > ( const DefaultIterator &second ) const; bool operator >= ( const DefaultIterator &second ) const; }; template <typename IteratorType> class DefaultConstIterator { public: typedef typename IteratorTypes<IteratorType>::ValueType ValueType; typedef typename IteratorTypes<IteratorType>::Pointer Pointer; typedef typename IteratorTypes<IteratorType>::Reference Reference; typedef typename IteratorTypes<IteratorType>::ConstPointer ConstPointer; typedef typename IteratorTypes<IteratorType>::ConstReference ConstReference; private: ConstPointer pointer; public: DefaultConstIterator( ConstPointer value = NULL ); DefaultConstIterator( const DefaultConstIterator &iterator ); ~DefaultConstIterator(); DefaultConstIterator<IteratorType>& operator = ( const DefaultConstIterator &iterator ); ConstReference operator * () const; ConstPointer operator -> () const; ConstReference operator [] ( sizetype offset ) const; DefaultConstIterator& operator ++ (); DefaultConstIterator operator ++ ( int ); DefaultConstIterator& operator -- (); DefaultConstIterator operator -- ( int ); DefaultConstIterator& operator += ( sizetype offset ); DefaultConstIterator& operator -= ( sizetype offset ); DefaultConstIterator operator + ( sizetype offset ) const; DefaultConstIterator operator - ( sizetype offset ) const; bool operator == ( const DefaultConstIterator &second ) const; bool operator != ( const DefaultConstIterator &second ) const; bool operator < ( const DefaultConstIterator &second ) const; bool operator <= ( const DefaultConstIterator &second ) const; bool operator > ( const DefaultConstIterator &second ) const; bool operator >= ( const DefaultConstIterator &second ) const; }; template <typename IteratorType> class DefaultReverseIterator { public: typedef typename IteratorTypes<IteratorType>::ValueType ValueType; typedef typename IteratorTypes<IteratorType>::Pointer Pointer; typedef typename IteratorTypes<IteratorType>::Reference Reference; typedef typename IteratorTypes<IteratorType>::ConstPointer ConstPointer; typedef typename IteratorTypes<IteratorType>::ConstReference ConstReference; private: Pointer pointer; public: DefaultReverseIterator( Pointer value = NULL ); DefaultReverseIterator( const DefaultReverseIterator &iterator ); ~DefaultReverseIterator(); DefaultReverseIterator<IteratorType>& operator = ( const DefaultReverseIterator &iterator ); Reference operator * () const; Pointer operator -> () const; Reference operator [] ( sizetype offset ) const; DefaultReverseIterator& operator ++ (); DefaultReverseIterator operator ++ ( int ); DefaultReverseIterator& operator -- (); DefaultReverseIterator operator -- ( int ); DefaultReverseIterator& operator += ( sizetype offset ); DefaultReverseIterator& operator -= ( sizetype offset ); DefaultReverseIterator operator + ( sizetype offset ) const; DefaultReverseIterator operator - ( sizetype offset ) const; bool operator == ( const DefaultReverseIterator &second ) const; bool operator != ( const DefaultReverseIterator &second ) const; bool operator < ( const DefaultReverseIterator &second ) const; bool operator <= ( const DefaultReverseIterator &second ) const; bool operator > ( const DefaultReverseIterator &second ) const; bool operator >= ( const DefaultReverseIterator &second ) const; }; template <typename IteratorType> class DefaultConstReverseIterator { public: typedef typename IteratorTypes<IteratorType>::ValueType ValueType; typedef typename IteratorTypes<IteratorType>::Pointer Pointer; typedef typename IteratorTypes<IteratorType>::Reference Reference; typedef typename IteratorTypes<IteratorType>::ConstPointer ConstPointer; typedef typename IteratorTypes<IteratorType>::ConstReference ConstReference; private: ConstPointer pointer; public: DefaultConstReverseIterator( ConstPointer value = NULL ); DefaultConstReverseIterator( const DefaultConstReverseIterator &iterator ); ~DefaultConstReverseIterator(); DefaultConstReverseIterator<IteratorType>& operator = ( const DefaultConstReverseIterator &iterator ); ConstReference operator * () const; ConstPointer operator -> () const; ConstReference operator [] ( sizetype offset ) const; DefaultConstReverseIterator& operator ++ (); DefaultConstReverseIterator operator ++ ( int ); DefaultConstReverseIterator& operator -- (); DefaultConstReverseIterator operator -- ( int ); DefaultConstReverseIterator& operator += ( sizetype offset ); DefaultConstReverseIterator& operator -= ( sizetype offset ); DefaultConstReverseIterator operator + ( sizetype offset ) const; DefaultConstReverseIterator operator - ( sizetype offset ) const; bool operator == ( const DefaultConstReverseIterator &second ) const; bool operator != ( const DefaultConstReverseIterator &second ) const; bool operator < ( const DefaultConstReverseIterator &second ) const; bool operator <= ( const DefaultConstReverseIterator &second ) const; bool operator > ( const DefaultConstReverseIterator &second ) const; bool operator >= ( const DefaultConstReverseIterator &second ) const; }; } } /* template DefaultIterator */ template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>::DefaultIterator( Pointer value ) : pointer(value) { } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>::DefaultIterator( const DefaultIterator &source ) : pointer(source.pointer) { } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>::~DefaultIterator() { } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator = ( const DefaultIterator &source ) { pointer = source.pointer; return *this; } template <typename IteratorType> typename tamias::hidden::DefaultIterator<IteratorType>::Reference tamias::hidden::DefaultIterator<IteratorType>::operator * () const { return *pointer; } template <typename IteratorType> typename tamias::hidden::DefaultIterator<IteratorType>::Pointer tamias::hidden::DefaultIterator<IteratorType>::operator -> () const { return pointer; } template <typename IteratorType> typename tamias::hidden::DefaultIterator<IteratorType>::Reference tamias::hidden::DefaultIterator<IteratorType>::operator [] ( tamias::sizetype offset ) const { return *(pointer + offset); } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator ++ () { ++pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType> tamias::hidden::DefaultIterator<IteratorType>::operator ++ ( int ) { return DefaultIterator<IteratorType>(pointer++); } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator -- () { --pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType> tamias::hidden::DefaultIterator<IteratorType>::operator -- ( int ) { return DefaultIterator<IteratorType>(pointer--); } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator += ( tamias::sizetype offset ) { pointer += offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator -= ( tamias::sizetype offset ) { pointer -= offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType> tamias::hidden::DefaultIterator<IteratorType>::operator + ( tamias::sizetype value ) const { return DefaultIterator<IteratorType>(pointer + value); } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType> tamias::hidden::DefaultIterator<IteratorType>::operator - ( tamias::sizetype value ) const { return DefaultIterator<IteratorType>(pointer - value); } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator == ( const DefaultIterator& value ) const { return pointer == value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator != ( const DefaultIterator& value ) const { return pointer != value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator < ( const DefaultIterator& value ) const { return pointer < value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator <= ( const DefaultIterator& value ) const { return pointer <= value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator > ( const DefaultIterator& value ) const { return pointer > value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator >= ( const DefaultIterator& value ) const { return pointer >= value.pointer; } /* template DefaultConstIterator */ template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::DefaultConstIterator( ConstPointer value ) : pointer(value) { } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::DefaultConstIterator( const DefaultConstIterator &source ) : pointer(source.pointer) { } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::~DefaultConstIterator() { } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator = ( const DefaultConstIterator &source ) { pointer = source.pointer; return *this; } template <typename IteratorType> typename tamias::hidden::DefaultConstIterator<IteratorType>::ConstReference tamias::hidden::DefaultConstIterator<IteratorType>::operator * () const { return *pointer; } template <typename IteratorType> typename tamias::hidden::DefaultConstIterator<IteratorType>::ConstPointer tamias::hidden::DefaultConstIterator<IteratorType>::operator -> () const { return pointer; } template <typename IteratorType> typename tamias::hidden::DefaultConstIterator<IteratorType>::ConstReference tamias::hidden::DefaultConstIterator<IteratorType>::operator [] ( tamias::sizetype offset ) const { return *(pointer + offset); } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator ++ () { ++pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::operator ++ ( int ) { return DefaultConstIterator<IteratorType>(pointer++); } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator -- () { --pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::operator -- ( int ) { return DefaultIterator<IteratorType>(pointer--); } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator += ( tamias::sizetype offset ) { pointer += offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator -= ( tamias::sizetype offset ) { pointer -= offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::operator + ( tamias::sizetype value ) const { return DefaultConstIterator<IteratorType>(pointer + value); } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::operator - ( tamias::sizetype value ) const { return DefaultConstIterator<IteratorType>(pointer - value); } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator == ( const DefaultConstIterator& value ) const { return pointer == value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator != ( const DefaultConstIterator& value ) const { return pointer != value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator < ( const DefaultConstIterator& value ) const { return pointer < value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator <= ( const DefaultConstIterator& value ) const { return pointer <= value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator > ( const DefaultConstIterator& value ) const { return pointer > value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator >= ( const DefaultConstIterator& value ) const { return pointer >= value.pointer; } /* template DefaultReverseIterator */ template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::DefaultReverseIterator( Pointer value ) : pointer(value) { } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::DefaultReverseIterator( const DefaultReverseIterator &source ) : pointer(source.pointer) { } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::~DefaultReverseIterator() { } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator = ( const DefaultReverseIterator &source ) { pointer = source.pointer; return *this; } template <typename IteratorType> typename tamias::hidden::DefaultReverseIterator<IteratorType>::Reference tamias::hidden::DefaultReverseIterator<IteratorType>::operator * () const { return *pointer; } template <typename IteratorType> typename tamias::hidden::DefaultReverseIterator<IteratorType>::Pointer tamias::hidden::DefaultReverseIterator<IteratorType>::operator -> () const { return pointer; } template <typename IteratorType> typename tamias::hidden::DefaultReverseIterator<IteratorType>::Reference tamias::hidden::DefaultReverseIterator<IteratorType>::operator [] ( tamias::sizetype offset ) const { return *(pointer - offset); } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator ++ () { --pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::operator ++ ( int ) { return DefaultReverseIterator<IteratorType>(pointer--); } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator -- () { ++pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::operator -- ( int ) { return DefaultReverseIterator<IteratorType>(pointer++); } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator += ( tamias::sizetype offset ) { pointer -= offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator -= ( tamias::sizetype offset ) { pointer += offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::operator + ( tamias::sizetype value ) const { return DefaultReverseIterator<IteratorType>(pointer - value); } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::operator - ( tamias::sizetype value ) const { return DefaultReverseIterator<IteratorType>(pointer + value); } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator == ( const DefaultReverseIterator& value ) const { return pointer == value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator != ( const DefaultReverseIterator& value ) const { return pointer != value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator < ( const DefaultReverseIterator& value ) const { return pointer > value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator <= ( const DefaultReverseIterator& value ) const { return pointer >= value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator > ( const DefaultReverseIterator& value ) const { return pointer < value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator >= ( const DefaultReverseIterator& value ) const { return pointer <= value.pointer; } /* template DefaultConstReverseIterator */ template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::DefaultConstReverseIterator( ConstPointer value ) : pointer(value) { } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> ::DefaultConstReverseIterator( const DefaultConstReverseIterator &source ) : pointer(source.pointer) { } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::~DefaultConstReverseIterator() { } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator = ( const DefaultConstReverseIterator &source ) { pointer = source.pointer; return *this; } template <typename IteratorType> typename tamias::hidden::DefaultConstReverseIterator<IteratorType>::ConstReference tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator * () const { return *pointer; } template <typename IteratorType> typename tamias::hidden::DefaultConstReverseIterator<IteratorType>::ConstPointer tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator -> () const { return pointer; } template <typename IteratorType> typename tamias::hidden::DefaultConstReverseIterator<IteratorType>::ConstReference tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator [] ( tamias::sizetype offset ) const { return *(pointer - offset); } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator ++ () { --pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator ++ ( int ) { return DefaultConstReverseIterator<IteratorType>(pointer--); } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator -- () { ++pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator -- ( int ) { return DefaultConstReverseIterator<IteratorType>(pointer++); } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator += ( tamias::sizetype offset ) { pointer -= offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator -= ( tamias::sizetype offset ) { pointer += offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator + ( tamias::sizetype value ) const { return DefaultConstReverseIterator<IteratorType>(pointer - value); } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator - ( tamias::sizetype value ) const { return DefaultConstReverseIterator<IteratorType>(pointer + value); } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType> ::operator == ( const DefaultConstReverseIterator& value ) const { return pointer == value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType> ::operator != ( const DefaultConstReverseIterator& value ) const { return pointer != value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType> ::operator < ( const DefaultConstReverseIterator& value ) const { return pointer > value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType> ::operator <= ( const DefaultConstReverseIterator& value ) const { return pointer >= value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType> ::operator > ( const DefaultConstReverseIterator& value ) const { return pointer < value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType> ::operator >= ( const DefaultConstReverseIterator& value ) const { return pointer <= value.pointer; } #endif /* _libtamias_basic_iterator_h */
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/generic_exception.h
/* * This file [basic/generic_exception.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { /* base of all exceptions */ class GenericException { public: GenericException(); GenericException( const GenericException &exception ); GenericException& operator = ( const GenericException &exception ); virtual ~GenericException(); virtual const char* type() const = 0; virtual const char* message() const = 0; }; /* should be used in development, when more informative exception class is not written yet */ class DefaultException : public GenericException { public: DefaultException(); DefaultException( const DefaultException &exception ); DefaultException& operator = ( const DefaultException &exception ); virtual ~DefaultException(); virtual const char* type() const; virtual const char* message() const; }; /* some common exceptions */ class OutOfMemoryException : public GenericException { public: OutOfMemoryException(); OutOfMemoryException( const OutOfMemoryException &exception ); virtual ~OutOfMemoryException(); OutOfMemoryException& operator = ( const OutOfMemoryException &exception ); virtual const char* type() const; virtual const char* message() const; }; class OutOfBoundsException : public GenericException { public: OutOfBoundsException(); OutOfBoundsException( const OutOfBoundsException &exception ); OutOfBoundsException& operator = ( const OutOfBoundsException &exception ); virtual ~OutOfBoundsException(); virtual const char* type() const; virtual const char* message() const; }; };
agrishutin/teambook
contrib/su4/cpp2tex/include/data/array_implementation.h
/* * This file [data/array.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ template <typename Type> tamias::Array<Type>::Array() : mIt(), mData() { } template <typename Type> tamias::Array<Type>::Array( Array const &array ) : mIt(array.mIt), mData(array.mData) { } template <typename Type> tamias::Array<Type>& tamias::Array<Type>::operator = ( Array const &array ) { mIt = array.mIt; mData = array.mData; return *this; } template <typename Type> tamias::Array<Type>::~Array() { } template <typename Type> tamias::sizetype tamias::Array<Type>::insert( Type const &element ) { sizetype index = it_jumpZero(0, 0); if (index < mData.size()) mData[index] = element, it_change(index, +1); else index = mData.size(), mData.pushBack(element), it_create(1); return index; } template <typename Type> Type const& tamias::Array<Type>::operator[]( sizetype index ) const { utilities::assert<OutOfBoundsException>(index < mData.size() && it_get(index) == 1); return mData[index]; } template <typename Type> Type& tamias::Array<Type>::operator[]( sizetype index ) { utilities::assert<OutOfBoundsException>(index < mData.size() && it_get(index) == 1); return mData[index]; } template <typename Type> void tamias::Array<Type>::erase( sizetype index ) { utilities::assert<OutOfBoundsException>(index < mData.size() && it_get(index) == 1); mData[index] = Type(); // OLOLO it_change(index, -1); // TODO: delete something if last (index == mData.size() - 1) } template <typename Type> tamias::sizetype tamias::Array<Type>::first() const { return it_jumpOne(0, 0); } template <typename Type> tamias::sizetype tamias::Array<Type>::next( sizetype index ) const { utilities::assert<OutOfBoundsException>(index < mData.size() && it_get(index) == 1); return it_jumpOne(index, 1); } // magic begins here template <typename Type> void tamias::Array<Type>::it_change( sizetype index, sizetype add ) { index *= 2; mIt[index] += add; sizetype level = 0, n = mIt.size(); while (true) { bool left = ((index - (1 << level) + 1) >> (level + 1)) % 2 == 0; sizetype parent = left ? index + (1 << level) : index - (1 << level); if (parent < n) mIt[parent] += add; else if ((parent & (1 + parent)) == 0) break; index = parent; level++; } } template <typename Type> void tamias::Array<Type>::it_create( sizetype value ) { if (mIt.size() != 0) { sizetype vertex = mIt.size(), level = 0; while ((vertex & ((2u << level) - 1)) == (2u << level) - 1) level++; level--; // obfuscated code, huh mIt.pushBack(mIt[vertex - (1 << level)]); } mIt.pushBack(0); it_change((mIt.size() - 1) / 2, value); } template <typename Type> tamias::sizetype tamias::Array<Type>::it_get( sizetype index ) const { return mIt[index * 2]; } template <typename Type> tamias::sizetype tamias::Array<Type>::it_jumpOne( sizetype index, sizetype length ) const { sizetype n = mIt.size(), level = 0; index *= 2; while (true) if (index >= n || length < mIt[index]) { if (level == 0) return index < n ? index / 2 : (sizetype)-1; level--; sizetype left = index - (1 << level), right = index + (1 << level); if (left >= n || length < mIt[left]) index = left; else index = right, length -= mIt[left]; } else { bool left = ((index - (1 << level) + 1) >> (level + 1)) % 2 == 0; sizetype parent = left ? index + (1 << level) : index - (1 << level); level++; if (!left) length += mIt[index - (1 << level)]; index = parent; } } template <typename Type> tamias::sizetype tamias::Array<Type>::it_jumpZero( sizetype index, sizetype length ) const { sizetype n = mIt.size(), level = 0; index *= 2; while (true) if (index >= n || length < (1 << level) - mIt[index]) { if (level == 0) return index < n ? index / 2 : (sizetype)-1; level--; sizetype left = index - (1 << level), right = index + (1 << level); if (left >= n || length < (1 << level) - mIt[left]) index = left; else index = right, length -= (1 << level) - mIt[left]; } else { bool left = ((index - (1 << level) + 1) >> (level + 1)) % 2 == 0; sizetype parent = left ? index + (1 << level) : index - (1 << level); if (!left) length += (1 << level) - mIt[index - (2 << level)]; level++; index = parent; } } /* * ......3...... * /.../-/.\-\... * ..1.......5.. * ./.\...../.\. * 0...2...4...6 */
agrishutin/teambook
contrib/su4/cpp2tex/include/io/printer.h
/* * This file [io/printer.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once #include <cstdarg> #include "../basic/string.h" #include "../basic/utilities.h" #include "../data/pair.h" #include "../data/queue.h" #include "../io/iodevice.h" /* * about conversions * the generic form is: %<flags><width><precision><modificators><specifier> * specifiers: * c — character * d, i — decimal integer * e — float number, exponential format * f — float number, fixed format * g — float number, automatic format * o — octal integer * s — string * x — hex integer * % — special, outputs '%' into output stream */ namespace tamias { namespace hidden { class Conversion; } class Printer { public: Printer( IODevice const &device ); Printer( Printer const &printer ); Printer& operator = ( Printer const &printer ); virtual ~Printer(); void close(); // TODO void flush(); void print( String const &value ); void println( String const &value ); Printer& printf( String const &format ); Printer& operator << ( String const &value ); Printer& operator << ( char value ); Printer& operator << ( char const *value ); Printer& operator << ( int value ); Printer& operator << ( unsigned int value ); /* template <typename Type> void println( const Type &value ); template <typename Type> void print( const Type &value );*/ int _printf( const String &format, ... ); int vprintf( const String &format, va_list arguments ) __attribute((deprecated)); static String endln; static String intToString( int value, int base = 10 ); // TODO: override for other types static String intToString( long long int value, int base = 10 ); static String intToString( unsigned int value, int base = 10 ); static String intToString( unsigned long int value, int base = 10 ); private: IODevice *device; Queue <hidden::Conversion> buffer; /* enum Format { FORMAT_STRING, FORMAT_CONVERSION };*/ // Queue <Pair <Format, String> > buffer; void flushBuffer(); }; class hidden::Conversion { public: Conversion( Conversion const &conversion ); Conversion& operator = ( Conversion const &conversion ); ~Conversion(); static Conversion parse( String const &format ); static Conversion plain( String const &format ); bool ready() const; void add( String const &value ); // and add's for other values void add( char value ); void add( char const *value ); void add( int value ); void add( unsigned int value ); String output() const; private: enum Type { TYPE_PLAIN, TYPE_CHARACTER, TYPE_DECIMAL, TYPE_OCTAL, TYPE_HEX, TYPE_FLOAT, TYPE_EXPONENT, TYPE_STRING } type; int width; // special value is -1 char widthPadder; String result; bool mReady; Conversion(); }; }
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/thread.h
<reponame>agrishutin/teambook<gh_stars>10-100 /* * This file [basic/thread.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_basic_thread_h_ #define _libtamias_basic_thread_h_ #include <pthread.h> #include <time.h> #include "../basic/time.h" namespace tamias { class Thread { private: pthread_t threadHandle; protected: virtual void* run(); public: Thread(); Thread( const Thread &thread ); Thread& operator = ( const Thread &thread ); virtual ~Thread(); void create(); void cancel(); static void sleep( const Time &time ); friend void* threadRun( void* thread ); }; class FunctionThread : public Thread { public: typedef void(*Function)(void); private: Function threadFunction; virtual void* run(); public: FunctionThread( Function function ); FunctionThread( const FunctionThread &thread ); FunctionThread& operator = ( const FunctionThread &thread ); virtual ~FunctionThread(); }; template <typename ClassType> class MethodThread : public Thread { public: typedef void (ClassType::* Function)(void); private: ClassType *threadObject; Function threadFunction; virtual void* run(); public: MethodThread( ClassType &object, Function function ); MethodThread( ClassType *object, Function function ); MethodThread( const MethodThread &thread ); MethodThread& operator = ( const MethodThread &thread ); virtual ~MethodThread(); }; } template <typename ClassType> void* tamias::MethodThread<ClassType>::run() { (threadObject->*threadFunction)(); return NULL; } template <typename ClassType> tamias::MethodThread<ClassType>::MethodThread( ClassType &object, Function function ) : Thread(), threadObject(&object), threadFunction(function) { } template <typename ClassType> tamias::MethodThread<ClassType>::MethodThread( ClassType *object, Function function ) : Thread(), threadObject(object), threadFunction(function) { } template <typename ClassType> tamias::MethodThread<ClassType>::MethodThread( const MethodThread &thread ) : Thread(thread), threadObject(thread.threadObject), threadFunction(thread.threadFunction) { } template <typename ClassType> tamias::MethodThread<ClassType>& tamias::MethodThread<ClassType>::operator = ( const MethodThread &thread ) { Thread::operator = (thread); threadFunction = thread.threadFunction; threadObject = thread.threadObject; return *this; } template <typename ClassType> tamias::MethodThread<ClassType>::~MethodThread() { } #endif // _libtamias_basic_thread_h_
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/abstract_data.h
/* * This file [basic/abstract_data.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_basic_abstract_data_ #define _libtamias_basic_abstract_data_ #include <cstring> #include <cstdlib> #include "../basic/generic_exception.h" #include "../basic/types.h" #include "../basic/utilities.h" namespace tamias { namespace hidden { /* provides distensible data block */ class AbstractData { protected: static const tamias::sizetype MAXSIZE = 0x80000000; void *data; tamias::sizetype dataSize; public: AbstractData( tamias::sizetype initialSize = 0 ); AbstractData( const AbstractData &data ); AbstractData& operator = ( const AbstractData &data ); virtual ~AbstractData( void ); void autoReserve( sizetype size ); /* Allocates between size and size*4 bytes */ void autoReserveUp( sizetype size ); /* Allocates minimum size bytes */ void manualReserve( sizetype size ); /* Allocates exactly size bytes */ void* getData() const; }; } } #endif /* _libtamias_basic_abstract_data_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/xml_data.h
<gh_stars>10-100 #pragma once namespace tamias { namespace wtf { namespace xml { class Data; // provides common access to base string } } } #include "../basic/string.h" #include "../basic/types.h" #include "../data/flyweight.h" class tamias::wtf::xml::Data : private Flyweight <String> { public: Data( tamias::String const &s = "" ); Data( Data const &data ); Data& operator = ( Data const &data ); ~Data(); sizetype length() const; chartype operator[] ( sizetype index ) const; tamias::String subString( sizetype start, sizetype length ) const; Data& append( tamias::String const &s ); };
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/xml_element.h
#pragma once namespace tamias { namespace wtf { namespace xml { class Element; } } } #include "../data/map.h" #include "../data/tree_rbst.h" #include "../data/vector.h" #include "../wtf/xml_string.h" class tamias::wtf::xml::Element { public: Element(); Element( Element const &element ); Element& operator = ( Element const &element ); ~Element(); Element& setName( String const &name ); Element& setContent( String const &content ); Element& addAttribute( String const &name, String const &value ); Element& addElement( Element const &element ); private: String mName, mContent; Vector <String> mAttributes; Map <RBSTree, String, String> mValues; Vector <Element> mElements; };
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/sax_parser.h
<gh_stars>10-100 #pragma once namespace tamias { namespace wtf { namespace sax { class Parser; } } } #include "../data/vector.h" #include "../wtf/sax_callback.h" class tamias::wtf::sax::Parser { public: explicit Parser( Callback &callback ); ~Parser(); void parse( String const &document ); // A whole document in one time. Sorry. private: Parser( Parser const &parser ); Parser& operator = ( Parser const &parser ); bool isAlpha( chartype ch ); bool isSpace( chartype ch ); void flush(); bool tag( bool close, bool selfClose ); Callback &mCallback; String temp; String tagName; bool closeTag, started; Vector <String> tagStack, attributeNames, attributeValues; };
agrishutin/teambook
contrib/su4/cpp2tex/include/network/ip.h
/* * This file [network/ip.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_network_ip_h_ #define _libtamias_network_ip_h_ #include "../basic/types.h" #include "../basic/string.h" namespace tamias { class IpAddress { public: IpAddress( uinttype32 ip = 0 ); IpAddress( const IpAddress &address ); IpAddress& operator = ( const IpAddress &address ); ~IpAddress(); uinttype32 ip() const; void setIp( uinttype32 ip ); String toString() const; // TODO: may be move this somewhere private: uinttype32 ipAddress; }; } #endif // _libtamias_network_socket_h_
agrishutin/teambook
contrib/su4/cpp2tex/include/data/flyweight.h
/* * This file [data/flyweight.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { template <typename Type> class Flyweight; // some data that shouldn't be dublicated by copying object } #include "../basic/types.h" template <typename Type> class tamias::Flyweight { protected: Flyweight(); Flyweight( Flyweight const &fly ); Flyweight& operator = ( Flyweight const &fly ); ~Flyweight(); Type& data(); Type const& data() const; private: struct Data { sizetype counter; Type data; } *mData; }; #include "flyweight_implementation.h"
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/time.h
<gh_stars>10-100 /* * This file [basic/time.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_basic_time_h_ #define _libtamias_basic_time_h_ #include "../basic/types.h" namespace tamias { /* second (second) = 1 second millisecons (msecond) = 1e-3 seconds microsecond (usecond) = 1e-6 seconds nanosecond (nsecond) = 1e-9 seconds */ class Time { private: inttype64 timeSeconds; uinttype32 timeNanoSeconds; public: Time( inttype64 seconds = 0, uinttype32 nanoSeconds = 0 ); Time( const Time &time ); ~Time(); Time& operator = ( const Time &time ); static Time fromSeconds( long double seconds ); inttype64& seconds(); inttype64 seconds() const; void setSeconds( inttype64 seconds ); uinttype32& nanoSeconds(); uinttype32 nanoSeconds() const; void setNanoSeconds( uinttype32 nanoSeconds ); long double toSeconds() const; Time& operator += ( const Time &time ); Time& operator -= ( const Time &time ); Time operator + ( const Time &time ) const; Time operator - ( const Time &time ) const; int compare( const Time &time ) const; bool operator == ( const Time &time ) const; bool operator != ( const Time &time ) const; bool operator < ( const Time &time ) const; bool operator <= ( const Time &time ) const; bool operator > ( const Time &time ) const; bool operator >= ( const Time &time ) const; }; } #endif /* _libtamias_basic_time_h_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/xml_string.h
#pragma once namespace tamias { namespace wtf { namespace xml { class String; // string as a substring of one big } } } #include "../basic/types.h" #include "../wtf/xml_data.h" class tamias::wtf::xml::String { public: String(); String( Data const &data, sizetype start, sizetype length ); String( String const &string ); String& operator = ( String const &string ); ~String(); sizetype length() const; chartype operator[] ( sizetype index ) const; tamias::String value() const; String subString( sizetype start, sizetype length ) const; bool operator < ( String const &s ) const; private: Data mData; sizetype mStart, mLength; };
agrishutin/teambook
contrib/su4/cpp2tex/include/system/socket.h
/* * This file [system/socket.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { class Socket; class TcpClientSocket; class TcpServerSocket; } #include <errno.h> #include <netdb.h> #include <poll.h> #include <unistd.h> #include <sys/socket.h> #include <sys/types.h> #include "../basic/byte_array.h" #include "../basic/types.h" #include "../basic/utilities.h" #include "../system/event_poll.h" #include "../system/ip.h" class tamias::Socket : public EventFd { public: enum SocketState { STATE_NOSOCKET, STATE_ERROR, STATE_CONNECTED, STATE_CLOSED, STATE_FINISHED }; public: Socket(); ~Socket(); ByteArray read( sizetype maxSize = (sizetype)-1 ); void write( ByteArray const &data ); sizetype tryWrite( ByteArray const &data ); // added for testing once void close(); SocketState state() const; IpAddress foreignIp() const; private: SocketState mState; int mHandle; Socket( int newHandle ); int handle(); Socket( Socket const &socket ); Socket& operator = ( Socket const &socket ); friend class TcpClientSocket; friend class TcpServerSocket; }; class tamias::TcpClientSocket : public Socket { public: TcpClientSocket(); ~TcpClientSocket(); void connect( ByteArray const &host, uinttype16 port ); void disconnect(); private: TcpClientSocket( TcpClientSocket const &socket ); TcpClientSocket& operator = ( TcpClientSocket const &socket ); }; class tamias::TcpServerSocket : public Socket { // TODO: this public is only for EventFd::handle() public: TcpServerSocket(); ~TcpServerSocket(); void bind( uinttype16 port ); Socket* accept(); // TODO: where is disconnect? private: TcpServerSocket( TcpServerSocket const &socket ); TcpServerSocket& operator = ( TcpServerSocket const &socket ); };
agrishutin/teambook
contrib/su4/cpp2tex/include/system/thread.h
/* * This file [system/thread.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { class Thread; class FunctionThread; template <typename ClassType> class MethodThread; } #include <pthread.h> #include <time.h> #include "../basic/time.h" class tamias::Thread { public: Thread(); Thread( Thread const &thread ); Thread& operator = ( Thread const &thread ); virtual ~Thread(); void create(); void cancel(); static void sleep( Time const &time ); protected: virtual void* run(); private: pthread_t mHandle; friend void* threadRun( void *thread ); }; class tamias::FunctionThread : public Thread { public: typedef void(*Function)(void); public: FunctionThread( Function function ); FunctionThread( FunctionThread const &thread ); FunctionThread& operator = ( FunctionThread const &thread ); ~FunctionThread(); private: Function mFunction; void* run(); }; template <typename ClassType> class tamias::MethodThread : public Thread { public: typedef void (ClassType::* Function)(void); public: MethodThread( ClassType &object, Function function ); MethodThread( ClassType *object, Function function ); MethodThread( MethodThread const &thread ); MethodThread& operator = ( MethodThread const &thread ); ~MethodThread(); private: ClassType *mObject; Function mFunction; virtual void* run(); }; #include "thread_implementation.h"
agrishutin/teambook
contrib/su4/cpp2tex/include/data/set_implementation.h
<filename>contrib/su4/cpp2tex/include/data/set_implementation.h /* * This file [data/set_implementation.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ template <template <typename Type> class CollectionTemplate, typename Type> tamias::Set<CollectionTemplate, Type>::Set() : collection() { } template <template <typename Type> class CollectionTemplate, typename Type> tamias::Set<CollectionTemplate, Type>::Set( Set const &set ) : collection(set.collection) { } template <template <typename Type> class CollectionTemplate, typename Type> tamias::Set<CollectionTemplate, Type>& tamias::Set <CollectionTemplate, Type>::operator = ( Set const &set ) { collection = set.collection; return *this; } template <template <typename Type> class CollectionTemplate, typename Type> tamias::Set<CollectionTemplate, Type>::~Set() { } template <template <typename Type> class CollectionTemplate, typename Type> tamias::sizetype tamias::Set<CollectionTemplate, Type>::size() const { return collection.size(); } template <template <typename Type> class CollectionTemplate, typename Type> void tamias::Set<CollectionTemplate, Type>::insert( Type const &value ) { collection.insert(value); } template <template <typename Type> class CollectionTemplate, typename Type> void tamias::Set<CollectionTemplate, Type>::erase( Type const &value ) { collection.erase(value); } template <template <typename Type> class CollectionTemplate, typename Type> tamias::sizetype tamias::Set<CollectionTemplate, Type>::count( Type const &value ) const { return collection.count(value); } template <template <typename Type> class CollectionTemplate, typename Type> typename tamias::Set<CollectionTemplate, Type>::Iterator tamias::Set<CollectionTemplate, Type>::begin() { return collection.begin(); } template <template <typename Type> class CollectionTemplate, typename Type> typename tamias::Set<CollectionTemplate, Type>::Iterator tamias::Set<CollectionTemplate, Type>::end() { return collection.end(); } template <template <typename Type> class CollectionTemplate, typename Type> typename tamias::Set<CollectionTemplate, Type>::ConstIterator tamias::Set<CollectionTemplate, Type>::begin() const { return collection.begin(); } template <template <typename Type> class CollectionTemplate, typename Type> typename tamias::Set<CollectionTemplate, Type>::ConstIterator tamias::Set<CollectionTemplate, Type>::end() const { return collection.end(); }
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/sax_callback.h
#pragma once namespace tamias { namespace wtf { namespace sax { class Callback; } } } #include "../basic/string.h" class tamias::wtf::sax::Callback { protected: Callback(); virtual ~Callback(); virtual void start(); virtual void finish(); virtual void elementBegin( String const &name ); virtual void elementEnd(); virtual void attribute( String const &name, String const &value ); virtual void text( String const &text ); virtual void error( String const &comment ) = 0; private: Callback( Callback const &callback ); Callback& operator = ( Callback const &callback ); friend class Parser; };
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/web_server.h
<gh_stars>10-100 #pragma once #include "../basic/byte_array.h" #include "../basic/string.h" #include "../basic/types.h" #include "../io/printer.h" #include "../io/scanner.h" #include "../main/map.h" #include "../main/tree_rbst.h" #include "../main/vector.h" #include "../wtf/utilities.h" #include "../wtf/web_cookies.h" #include "../wtf/web_utilities.h" namespace tamias { namespace wtf { namespace web { class HttpResponse { public: HttpResponse(); HttpResponse( const HttpResponse &response ); HttpResponse& operator = ( const HttpResponse &response ); ~HttpResponse(); void addCookie( const Cookie &cookie ); void setContent( const String &content ); void output( Printer &out ); private: Vector <Cookie> mCookies; String mContent; }; class HttpRequest { public: HttpRequest(); HttpRequest( int argc, char **argv, char **env, Scanner &input ); HttpRequest( const HttpRequest &request ); HttpRequest& operator = ( const HttpRequest &request ); ~HttpRequest(); const Map <RBSTree, String, String>& cookies() const; const Map <RBSTree, String, String>& enviropment() const; const Map <RBSTree, String, String>& getParameters() const; const Map <RBSTree, String, String>& postParameters() const; private: Map <RBSTree, String, String> mCookies; // TODO: Map -> HashMap Map <RBSTree, String, String> mEnviropment; Map <RBSTree, String, String> mGetParameters; Map <RBSTree, String, String> mPostParameters; }; class HttpServer { public: HttpServer(); HttpServer( const HttpServer &server ); HttpServer& operator = ( const HttpServer &server ); virtual ~HttpServer(); void make( int argc, char **argv, char **env, Scanner &input, Printer &out ); protected: virtual HttpResponse action( const HttpRequest &request ) = 0; }; } } }
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/string.h
<gh_stars>10-100 /* * This file [basic/string.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_basic_string_h_ #define _libtamias_basic_string_h_ #include "../basic/abstract_data.h" #include "../basic/byte_array.h" #include "../basic/types.h" namespace tamias { /* UTF-32 string */ /* by default, char* means string in UTF-8. Luckily, it is compatible with acsii */ class String : private hidden::AbstractData { public: typedef tamias::hidden::DefaultIterator<chartype*> Iterator; typedef tamias::hidden::DefaultConstIterator<chartype*> ConstIterator; typedef tamias::hidden::DefaultReverseIterator<chartype*> ReverseIterator; typedef tamias::hidden::DefaultConstReverseIterator<chartype*> ConstReverseIterator; private: sizetype stringLength; public: String(); String( chartype source ); String( const chartype *source ); String( const chartype *source, sizetype sourceLength ); String( const char *source ); String( const char *source, sizetype sourceLength ); String( const ByteArray &source ); String( const String &string ); String& operator = ( const String &source ); ~String(); // static String fromUtf8( const char *source ); // static String fromUtf8( const char *source, sizetype sourceLength ); static String fromUtf8( const ByteArray &source ); // TODO: ByteData operator()(); String& operator += ( const String &source ); String operator + ( const String &source ) const; sizetype length() const; sizetype size() const; chartype& operator [] ( sizetype index ); chartype operator [] ( sizetype index ) const; Iterator begin(); ConstIterator begin() const; Iterator end(); ConstIterator end() const; ReverseIterator reverseBegin(); ConstReverseIterator reverseBegin() const; ReverseIterator reverseEnd(); ConstReverseIterator reverseEnd() const; // int compare( chartype source ) const; int compare( const chartype *source ) const; // TODO optimize for const char* and ByteArray // int compare( const char *source ) const; int compare( const String &source ) const; // sizetype find( chartype source ) const; // TODO: remove all finds but find( const String &source )? // sizetype find( const chartype *source ) const; // sizetype find( const char *source ) const; /* We use Rabin-Karp algorithm to find a substring. http://en.wikipedia.org/wiki/Rabin-Karp_string_search_algorithm */ sizetype find( const String &source ) const; String subString( sizetype start, sizetype length ) const; ByteArray toUtf8() const; // returns UTF-8 interpretation of string ByteArray toUtf16() const; // return UTF-16 interpretation of string // bool operator < ( chartype source ) const; // bool operator <= ( chartype source ) const; // bool operator > ( chartype source ) const; // bool operator >= ( chartype source ) const; // bool operator == ( chartype source ) const; // bool operator != ( chartype source ) const; bool operator < ( const chartype *source ) const; bool operator <= ( const chartype *source ) const; bool operator > ( const chartype *source ) const; bool operator >= ( const chartype *source ) const; bool operator == ( const chartype *source ) const; bool operator != ( const chartype *source ) const; // bool operator < ( const char *source ) const; // bool operator <= ( const char *source ) const; // bool operator > ( const char *source ) const; // bool operator >= ( const char *source ) const; // bool operator == ( const char *source ) const; // bool operator != ( const char *source ) const; bool operator < ( const String &source ) const; bool operator <= ( const String &source ) const; bool operator > ( const String &source ) const; bool operator >= ( const String &source ) const; bool operator == ( const String &source ) const; bool operator != ( const String &source ) const; }; String operator + ( chartype first, const String &second ); String operator + ( const chartype *first, const String &second ); String operator + ( const char *first, const String &second ); bool operator < ( chartype first, const String &second ); bool operator <= ( chartype first, const String &second ); bool operator > ( chartype first, const String &second ); bool operator >= ( chartype first, const String &second ); bool operator == ( chartype first, const String &second ); bool operator != ( chartype first, const String &second ); bool operator < ( const chartype *fist, const String &second ); bool operator <= ( const chartype *fist, const String &second ); bool operator > ( const chartype *fist, const String &second ); bool operator >= ( const chartype *fist, const String &second ); bool operator == ( const chartype *fist, const String &second ); bool operator != ( const chartype *fist, const String &second ); bool operator < ( const char *fist, const String &second ); bool operator <= ( const char *fist, const String &second ); bool operator > ( const char *fist, const String &second ); bool operator >= ( const char *fist, const String &second ); bool operator == ( const char *fist, const String &second ); bool operator != ( const char *fist, const String &second ); } #endif // _libtamias_basic_string_h_
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/iterator_implementation.h
<filename>contrib/su4/cpp2tex/include/basic/iterator_implementation.h /* * This file [basic/iterator_implementation.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ /* template DefaultIterator */ template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>::DefaultIterator( Pointer value ) : pointer(value) { } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>::DefaultIterator( DefaultIterator const &source ) : pointer(source.pointer) { } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator = ( DefaultIterator const &source ) { pointer = source.pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>::~DefaultIterator() { } template <typename IteratorType> typename tamias::hidden::DefaultIterator<IteratorType>::Reference tamias::hidden::DefaultIterator<IteratorType>::operator * () const { return *pointer; } template <typename IteratorType> typename tamias::hidden::DefaultIterator<IteratorType>::Pointer tamias::hidden::DefaultIterator<IteratorType>::operator -> () const { return pointer; } template <typename IteratorType> typename tamias::hidden::DefaultIterator<IteratorType>::Reference tamias::hidden::DefaultIterator<IteratorType>::operator [] ( tamias::sizetype offset ) const { return *(pointer + offset); } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator ++ () { ++pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType> tamias::hidden::DefaultIterator<IteratorType>::operator ++ ( int ) { return DefaultIterator<IteratorType>(pointer++); } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator -- () { --pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType> tamias::hidden::DefaultIterator<IteratorType>::operator -- ( int ) { return DefaultIterator<IteratorType>(pointer--); } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator += ( tamias::sizetype offset ) { pointer += offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType>& tamias::hidden::DefaultIterator<IteratorType>::operator -= ( tamias::sizetype offset ) { pointer -= offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType> tamias::hidden::DefaultIterator<IteratorType>::operator + ( tamias::sizetype value ) const { return DefaultIterator<IteratorType>(pointer + value); } template <typename IteratorType> tamias::hidden::DefaultIterator<IteratorType> tamias::hidden::DefaultIterator<IteratorType>::operator - ( tamias::sizetype value ) const { return DefaultIterator<IteratorType>(pointer - value); } template <typename IteratorType> tamias::sizetype tamias::hidden::DefaultIterator<IteratorType>::operator - ( DefaultIterator const &iterator ) const { return iterator.pointer - pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator == ( DefaultIterator const &value ) const { return pointer == value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator != ( DefaultIterator const &value ) const { return pointer != value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator < ( DefaultIterator const &value ) const { return pointer < value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator <= ( DefaultIterator const&value ) const { return pointer <= value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator > ( DefaultIterator const &value ) const { return pointer > value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultIterator<IteratorType>::operator >= ( DefaultIterator const &value ) const { return pointer >= value.pointer; } /* template DefaultConstIterator */ template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::DefaultConstIterator( ConstPointer value ) : pointer(value) { } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::DefaultConstIterator( DefaultConstIterator const &source ) : pointer(source.pointer) { } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator = ( DefaultConstIterator const &source ) { pointer = source.pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::~DefaultConstIterator() { } template <typename IteratorType> typename tamias::hidden::DefaultConstIterator<IteratorType>::ConstReference tamias::hidden::DefaultConstIterator<IteratorType>::operator * () const { return *pointer; } template <typename IteratorType> typename tamias::hidden::DefaultConstIterator<IteratorType>::ConstPointer tamias::hidden::DefaultConstIterator<IteratorType>::operator -> () const { return pointer; } template <typename IteratorType> typename tamias::hidden::DefaultConstIterator<IteratorType>::ConstReference tamias::hidden::DefaultConstIterator<IteratorType>::operator [] ( tamias::sizetype offset ) const { return *(pointer + offset); } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator ++ () { ++pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::operator ++ ( int ) { return DefaultConstIterator<IteratorType>(pointer++); } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator -- () { --pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::operator -- ( int ) { return DefaultIterator<IteratorType>(pointer--); } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator += ( tamias::sizetype offset ) { pointer += offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>& tamias::hidden::DefaultConstIterator<IteratorType>::operator -= ( tamias::sizetype offset ) { pointer -= offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::operator + ( tamias::sizetype value ) const { return DefaultConstIterator<IteratorType>(pointer + value); } template <typename IteratorType> tamias::hidden::DefaultConstIterator<IteratorType> tamias::hidden::DefaultConstIterator<IteratorType>::operator - ( tamias::sizetype value ) const { return DefaultConstIterator<IteratorType>(pointer - value); } template <typename IteratorType> tamias::sizetype tamias::hidden::DefaultConstIterator<IteratorType>::operator - ( DefaultConstIterator const &iterator ) const { return iterator.pointer - pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator == ( DefaultConstIterator const &value ) const { return pointer == value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator != ( DefaultConstIterator const &value ) const { return pointer != value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator < ( DefaultConstIterator const &value ) const { return pointer < value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator <= ( DefaultConstIterator const &value ) const { return pointer <= value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator > ( DefaultConstIterator const &value ) const { return pointer > value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstIterator<IteratorType>::operator >= ( DefaultConstIterator const &value ) const { return pointer >= value.pointer; } /* template DefaultReverseIterator */ template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::DefaultReverseIterator( Pointer value ) : pointer(value) { } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::DefaultReverseIterator( DefaultReverseIterator const &source ) : pointer(source.pointer) { } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator = ( DefaultReverseIterator const &source ) { pointer = source.pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::~DefaultReverseIterator() { } template <typename IteratorType> typename tamias::hidden::DefaultReverseIterator<IteratorType>::Reference tamias::hidden::DefaultReverseIterator<IteratorType>::operator * () const { return *pointer; } template <typename IteratorType> typename tamias::hidden::DefaultReverseIterator<IteratorType>::Pointer tamias::hidden::DefaultReverseIterator<IteratorType>::operator -> () const { return pointer; } template <typename IteratorType> typename tamias::hidden::DefaultReverseIterator<IteratorType>::Reference tamias::hidden::DefaultReverseIterator<IteratorType>::operator [] ( tamias::sizetype offset ) const { return *(pointer - offset); } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator ++ () { --pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::operator ++ ( int ) { return DefaultReverseIterator<IteratorType>(pointer--); } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator -- () { ++pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::operator -- ( int ) { return DefaultReverseIterator<IteratorType>(pointer++); } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator += ( tamias::sizetype offset ) { pointer -= offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>& tamias::hidden::DefaultReverseIterator<IteratorType>::operator -= ( tamias::sizetype offset ) { pointer += offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::operator + ( tamias::sizetype value ) const { return DefaultReverseIterator<IteratorType>(pointer - value); } template <typename IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType> tamias::hidden::DefaultReverseIterator<IteratorType>::operator - ( tamias::sizetype value ) const { return DefaultReverseIterator<IteratorType>(pointer + value); } template <typename IteratorType> tamias::sizetype tamias::hidden::DefaultReverseIterator<IteratorType>::operator - ( DefaultReverseIterator const &iterator ) const { return pointer - iterator.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator == ( DefaultReverseIterator const &value ) const { return pointer == value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator != ( DefaultReverseIterator const &value ) const { return pointer != value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator < ( DefaultReverseIterator const &value ) const { return pointer > value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator <= ( DefaultReverseIterator const &value ) const { return pointer >= value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator > ( DefaultReverseIterator const &value ) const { return pointer < value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultReverseIterator<IteratorType>::operator >= ( DefaultReverseIterator const &value ) const { return pointer <= value.pointer; } /* template DefaultConstReverseIterator */ template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::DefaultConstReverseIterator( ConstPointer value ) : pointer(value) { } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::DefaultConstReverseIterator( DefaultConstReverseIterator const &source ) : pointer(source.pointer) { } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator = ( DefaultConstReverseIterator const &source ) { pointer = source.pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::~DefaultConstReverseIterator() { } template <typename IteratorType> typename tamias::hidden::DefaultConstReverseIterator<IteratorType>::ConstReference tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator * () const { return *pointer; } template <typename IteratorType> typename tamias::hidden::DefaultConstReverseIterator<IteratorType>::ConstPointer tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator -> () const { return pointer; } template <typename IteratorType> typename tamias::hidden::DefaultConstReverseIterator<IteratorType>::ConstReference tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator [] ( tamias::sizetype offset ) const { return *(pointer - offset); } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator ++ () { --pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator ++ ( int ) { return DefaultConstReverseIterator<IteratorType>(pointer--); } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator -- () { ++pointer; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator -- ( int ) { return DefaultConstReverseIterator<IteratorType>(pointer++); } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator += ( tamias::sizetype offset ) { pointer -= offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>& tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator -= ( tamias::sizetype offset ) { pointer += offset; return *this; } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator + ( tamias::sizetype value ) const { return DefaultReverseIterator<IteratorType>(pointer - value); } template <typename IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType> tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator - ( tamias::sizetype value ) const { return DefaultReverseIterator<IteratorType>(pointer + value); } template <typename IteratorType> tamias::sizetype tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator - ( DefaultConstReverseIterator const &iterator ) const { return pointer - iterator.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator == ( DefaultConstReverseIterator const &value ) const { return pointer == value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator != ( DefaultConstReverseIterator const &value ) const { return pointer != value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator < ( DefaultConstReverseIterator const &value ) const { return pointer > value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator <= ( DefaultConstReverseIterator const &value ) const { return pointer >= value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator > ( DefaultConstReverseIterator const &value ) const { return pointer < value.pointer; } template <typename IteratorType> bool tamias::hidden::DefaultConstReverseIterator<IteratorType>::operator >= ( DefaultConstReverseIterator const &value ) const { return pointer <= value.pointer; }
agrishutin/teambook
contrib/su4/cpp2tex/include/io/string_stream.h
/* * This file [io/string_stream.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_io_string_stream_h_ #define _libtamias_io_string_stream_h_ #include "../basic/byte_array.h" #include "../basic/types.h" #include "../io/iodevice.h" #include "../io/ioexception.h" namespace tamias { class StringStream : public IODevice { // by now, we support only output string stream private: ByteArray streamBuffer; public: StringStream(); StringStream( const StringStream &stream ); StringStream& operator = ( const StringStream &stream ); virtual ~StringStream(); virtual IODevice* clone() const; bool canRead() const; bool canWrite() const; bool canSeek() const; void close(); bool eof(); bool waitForRead(); ByteArray read( sizetype maxSize = (sizetype)-1 ); sizetype write( const ByteArray &data ); void seek( sizetype index = 0 ); const ByteArray& output() const; }; class StringStreamClone : public IODevice { private: ByteArray *streamBuffer; public: StringStreamClone( const ByteArray *buffer ); StringStreamClone( const StringStreamClone &stream ); StringStreamClone& operator = ( const StringStreamClone &stream ); virtual ~StringStreamClone(); virtual IODevice* clone() const; bool canRead() const; bool canWrite() const; bool canSeek() const; void close(); bool eof(); bool waitForRead(); ByteArray read( sizetype maxSize = (sizetype)-1 ); sizetype write( const ByteArray &data ); void seek( sizetype index = 0 ); const ByteArray& output() const; }; } #endif // _libtamias_io_string_stream_h_
agrishutin/teambook
contrib/su4/cpp2tex/include/data/pair.h
/* * This file [main/pair.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { template <typename TypeA, typename TypeB> class Pair { public: TypeA first; TypeB second; Pair(); Pair( const TypeA &newFirst , const TypeB &newSecond ); template <typename newTypeA, typename newTypeB> Pair( const Pair <newTypeA, newTypeB> &source ); Pair <TypeA, TypeB>& operator = ( const Pair <TypeA, TypeB> &source); ~Pair(); bool operator < ( const Pair &pair ) const; }; template <typename TypeA, typename TypeB> Pair <TypeA, TypeB> makePair( const TypeA &first, const TypeB &second ); } template <typename TypeA, typename TypeB> tamias::Pair<TypeA, TypeB>::Pair() : first(), second() { } template <typename TypeA, typename TypeB> tamias::Pair <TypeA, TypeB> ::Pair( const TypeA &newFirst, const TypeB &newSecond ) : first(newFirst), second(newSecond) { } template <typename TypeA, typename TypeB> template <typename newTypeA, typename newTypeB> tamias::Pair <TypeA, TypeB> ::Pair( const Pair <newTypeA, newTypeB> &source ) : first(source.first), second(source.second) { } template <typename TypeA, typename TypeB> tamias::Pair <TypeA, TypeB>& tamias::Pair <TypeA, TypeB> ::operator = ( const Pair <TypeA, TypeB> &source ) { first = source.first; second = source.second; return *this; } template <typename TypeA, typename TypeB> tamias::Pair <TypeA, TypeB> ::~Pair() { } template <typename TypeA, typename TypeB> bool tamias::Pair <TypeA, TypeB> ::operator < ( const Pair &pair ) const { if (first < pair.first) return true; if (pair.first < first) return false; return second < pair.second; } template <typename TypeA, typename TypeB> tamias::Pair <TypeA, TypeB> tamias::makePair( const TypeA &first, const TypeB &second ) { return Pair <TypeA, TypeB> (first, second); }
agrishutin/teambook
contrib/su4/cpp2tex/include/sql/connection.h
<filename>contrib/su4/cpp2tex/include/sql/connection.h /* * This file [sql/connection.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_sql_connection_h_ #define _libtamias_sql_connection_h_ #include "../sql/driver.h" #include "../sql/result.h" #include "../basic/string.h" namespace tamias { namespace sql { class Connection { private: Driver* driver; uinttype32 error; public: Connection( Driver *newDriver ); Connection( const Connection &connection ); ~Connection(); Connection& operator = ( const Connection &connection ); void connect( const String &host, const String &user, const String &password, const String &database ); void close(); Result query( const String &str ); }; } } #endif /* _libtamias_sql_connection_h_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/xml_tag.h
#pragma once namespace tamias { namespace wtf { namespace xml { class Tag; } } } #include "../wtf/xml_string.h" class tamias::wtf::xml::Tag { public: enum Type { TYPE_NOTAG, TYPE_OPEN, TYPE_CLOSE, TYPE_EMPTY, TYPE_COMMENT, TYPE_SPECIAL }; Tag( Type type, String const& name, String const& content ); Tag( Tag const &tag ); Tag& operator = ( Tag const &tag ); ~Tag(); Type type() const; String const& name() const; String const& content() const; private: Type mType; String mName, mContent; };
agrishutin/teambook
contrib/su4/cpp2tex/include/main/tree_rbst.h
/* * This file [main/tree_rbst.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once #include <cstdlib> #include "../basic/iterator.h" namespace tamias { /* http://en.wikipedia.org/wiki/Randomized_binary_search_tree */ template <typename KeyType> class RBSTree; namespace hidden { template <typename KeyType> struct RBSTreeNode { KeyType key; RBSTreeNode *left, *right, *parent; sizetype size; RBSTreeNode( const KeyType &newKey = KeyType() ); RBSTreeNode( const RBSTreeNode& node ); ~RBSTreeNode(); RBSTreeNode& operator = ( const RBSTreeNode &node ); }; template <typename KeyType> class RBSTreeIterator { public: typedef KeyType* Pointer; typedef KeyType& Reference; private: RBSTreeNode<KeyType> *node; public: RBSTreeIterator(); RBSTreeIterator( RBSTreeNode<KeyType> *node ); RBSTreeIterator( const RBSTreeIterator &iterator ); ~RBSTreeIterator(); RBSTreeIterator& operator = ( const RBSTreeIterator &iterator ); Reference operator * (); Pointer operator -> (); // TODO: all operators RBSTreeIterator& operator ++ (); RBSTreeIterator operator ++ ( int ); RBSTreeIterator& operator -- (); RBSTreeIterator operator -- ( int ); bool operator == ( const RBSTreeIterator &iterator ) const; bool operator != ( const RBSTreeIterator &iterator ) const; }; template <typename KeyType> class ConstRBSTreeIterator { public: typedef const KeyType* Pointer; typedef const KeyType& Reference; private: const RBSTreeNode<KeyType> *node; public: ConstRBSTreeIterator(); ConstRBSTreeIterator( const RBSTreeNode<KeyType> *node ); ConstRBSTreeIterator( const ConstRBSTreeIterator &iterator ); ~ConstRBSTreeIterator(); ConstRBSTreeIterator& operator = ( const ConstRBSTreeIterator &iterator ); Reference operator * (); Pointer operator -> (); ConstRBSTreeIterator& operator ++ (); ConstRBSTreeIterator operator ++ ( int ); ConstRBSTreeIterator& operator -- (); ConstRBSTreeIterator operator -- ( int ); bool operator == ( const ConstRBSTreeIterator &iterator ) const; bool operator != ( const ConstRBSTreeIterator &iterator ) const; }; } template <typename KeyType> class RBSTree { public: typedef hidden::RBSTreeIterator<KeyType> Iterator; typedef hidden::ConstRBSTreeIterator<KeyType> ConstIterator; private: typedef hidden::RBSTreeNode<KeyType> *TreeReference; TreeReference root; void recalc( TreeReference node ); TreeReference merge( TreeReference first, TreeReference second ); bool split( TreeReference root, TreeReference &left, TreeReference &right , const KeyType &splitter ); bool addKey( TreeReference &root, const KeyType &value ); Iterator beginIterator( TreeReference root ); Iterator findIterator( TreeReference root, const KeyType &value ); ConstIterator beginIterator( TreeReference root ) const; ConstIterator findIterator( TreeReference root, const KeyType &value ) const; TreeReference findKey( TreeReference root, const KeyType &value ); public: RBSTree(); RBSTree( const RBSTree &tree ); ~RBSTree(); RBSTree& operator = ( const RBSTree &tree ); sizetype size() const; bool add( const KeyType &value ); // [TODO] ? insert bool erase( const KeyType &value ); Iterator find( const KeyType &value ); ConstIterator find( const KeyType &value ) const; Iterator findKth( sizetype k ); ConstIterator findKth( sizetype k ) const; sizetype count( const KeyType &value ) const; Iterator begin(); Iterator end(); ConstIterator begin() const; ConstIterator end() const; void clear(); }; } template <typename KeyType> tamias::hidden::RBSTreeNode<KeyType>::RBSTreeNode( const KeyType &newKey ) : key(newKey), left(NULL), right(NULL), parent(NULL), size(1) { } template <typename KeyType> tamias::hidden::RBSTreeNode<KeyType>::RBSTreeNode( const RBSTreeNode &node ) : key(node.key), left(node.left), right(node.right), parent(node.parent), size(node.size) { } template <typename KeyType> tamias::hidden::RBSTreeNode<KeyType>::~RBSTreeNode() { } template <typename KeyType> tamias::hidden::RBSTreeNode<KeyType>& tamias::hidden::RBSTreeNode<KeyType>::operator = ( const RBSTreeNode<KeyType> &node ) { key = node.key; left = node.left; right = node.rigth; parent = node.parent; size = node.size; return *this; } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>::RBSTreeIterator() : node(NULL) { } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>::RBSTreeIterator( RBSTreeNode<KeyType> *newNode ) : node(newNode) { } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>::RBSTreeIterator( const RBSTreeIterator &iterator ) : node(iterator.node) { } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>::~RBSTreeIterator() { } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>& tamias::hidden::RBSTreeIterator<KeyType>::operator = ( const RBSTreeIterator &iterator ) { node = iterator.node; return *this; } template <typename KeyType> typename tamias::hidden::RBSTreeIterator<KeyType>::Reference tamias::hidden::RBSTreeIterator<KeyType>::operator * () { // TODO: ? if (node == NULL) throw Exception ? return node->key; } template <typename KeyType> typename tamias::hidden::RBSTreeIterator<KeyType>::Pointer tamias::hidden::RBSTreeIterator<KeyType>::operator -> () { return node == NULL ? NULL : &(node->key); } template <typename KeyType> typename tamias::hidden::RBSTreeIterator<KeyType> tamias::hidden::RBSTreeIterator<KeyType>::operator ++ ( int ) { RBSTreeIterator result(*this); if (node == NULL) return result; if (node->right != NULL) { node = node->right; while (node->left != NULL) node = node->left; } else while (node != NULL) { RBSTreeNode<KeyType> *oldNode = node; node = node->parent; if (node == NULL || node->right != oldNode) break; } return result; } template <typename KeyType> bool tamias::hidden::RBSTreeIterator<KeyType>::operator == ( const RBSTreeIterator &iterator ) const { return node == iterator.node; } template <typename KeyType> bool tamias::hidden::RBSTreeIterator<KeyType>::operator != ( const RBSTreeIterator &iterator ) const { return node != iterator.node; } template <typename KeyType> tamias::hidden::ConstRBSTreeIterator<KeyType>::ConstRBSTreeIterator() : node(NULL) { } template <typename KeyType> tamias::hidden::ConstRBSTreeIterator<KeyType>::ConstRBSTreeIterator ( const RBSTreeNode<KeyType> *newNode ) : node(newNode) { } template <typename KeyType> tamias::hidden::ConstRBSTreeIterator<KeyType>::ConstRBSTreeIterator( const ConstRBSTreeIterator &iterator ) : node(iterator.node) { } template <typename KeyType> tamias::hidden::ConstRBSTreeIterator<KeyType>::~ConstRBSTreeIterator() { } template <typename KeyType> tamias::hidden::ConstRBSTreeIterator<KeyType>& tamias::hidden::ConstRBSTreeIterator<KeyType>::operator = ( const ConstRBSTreeIterator &iterator ) { node = iterator.node; return *this; } template <typename KeyType> typename tamias::hidden::ConstRBSTreeIterator<KeyType>::Reference tamias::hidden::ConstRBSTreeIterator<KeyType>::operator * () { // TODO: ? if (node == NULL) throw Exception ? return node->key; } template <typename KeyType> typename tamias::hidden::ConstRBSTreeIterator<KeyType>::Pointer tamias::hidden::ConstRBSTreeIterator<KeyType>::operator -> () { return node == NULL ? NULL : &(node->key); } template <typename KeyType> typename tamias::hidden::ConstRBSTreeIterator<KeyType> tamias::hidden::ConstRBSTreeIterator<KeyType>::operator ++ ( int ) { ConstRBSTreeIterator result(*this); if (node == NULL) return result; if (node->right != NULL) { node = node->right; while (node->left != NULL) node = node->left; } else while (node != NULL) { const RBSTreeNode<KeyType> *oldNode = node; node = node->parent; if (node == NULL || node->right != oldNode) break; } return result; } template <typename KeyType> bool tamias::hidden::ConstRBSTreeIterator<KeyType>::operator == ( const ConstRBSTreeIterator &iterator ) const { return node == iterator.node; } template <typename KeyType> bool tamias::hidden::ConstRBSTreeIterator<KeyType>::operator != ( const ConstRBSTreeIterator &iterator ) const { return node != iterator.node; } /* template RBSTree */ template <typename KeyType> void tamias::RBSTree<KeyType>::recalc( TreeReference vertex ) { if (vertex == NULL) return; sizetype size = 1; if (vertex->left != NULL) { size += vertex->left->size; vertex->left->parent = vertex; } if (vertex->right != NULL) { size += vertex->right->size; vertex->right->parent = vertex; } vertex->size = size; } template <typename KeyType> typename tamias::RBSTree<KeyType>::TreeReference tamias::RBSTree<KeyType>::merge( TreeReference left, TreeReference right ) { if (left == NULL || right == NULL) return left != NULL ? left : right; if (rand() % (left->size + right->size) < left->size) { left->right = merge(left->right, right); recalc(left); return left; } else { right->left = merge(left, right->left); recalc(right); return right; } } template <typename KeyType> bool tamias::RBSTree<KeyType>::split( TreeReference vertex, TreeReference &left, TreeReference &right, const KeyType &value ) { if (vertex == NULL) { left = right = NULL; return true; } if (value < vertex->key) { TreeReference tmpLeft, tmpRight; if (!split(vertex->left, tmpLeft, tmpRight, value)) return false; left = tmpLeft; right = vertex; right->left = tmpRight; right->parent = NULL; recalc(right); } else if (vertex->key < value) { TreeReference tmpLeft, tmpRight; if (!split(vertex->right, tmpLeft, tmpRight, value)) return false; left = vertex; right = tmpRight; left->right = tmpLeft; left->parent = NULL; recalc(left); } else return false; return true; } template <typename KeyType> bool tamias::RBSTree<KeyType>::addKey( TreeReference &vertex, const KeyType &key ) { bool result; if (vertex == NULL || rand() % (vertex->size + 1) == 0u) { TreeReference tmpLeft, tmpRight; if (!split(vertex, tmpLeft, tmpRight, key)) return false; vertex = new tamias::hidden::RBSTreeNode<KeyType>(key); vertex->left = tmpLeft; vertex->right = tmpRight; recalc(vertex); result = true; } else { if (key < vertex->key) result = addKey(vertex->left, key); else if (vertex->key < key) result = addKey(vertex->right, key); else result = false; if (result) recalc(vertex); } return result; } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::findIterator( TreeReference root, const KeyType &key ) { if (root == NULL) return Iterator(NULL); if (key < root->key) return findIterator(root->left, key); if (root->key < key) return findIterator(root->right, key); return Iterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::beginIterator( TreeReference root ) { if (root == NULL) return Iterator(NULL); if (root->left != NULL) return beginIterator(root->left); return Iterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::findIterator( TreeReference root, const KeyType &key ) const { if (root == NULL) return ConstIterator(NULL); if (key < root->key) return findIterator(root->left, key); if (root->key < key) return findIterator(root->right, key); return ConstIterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::beginIterator( TreeReference root ) const { if (root == NULL) return ConstIterator(NULL); if (root->left != NULL) return beginIterator(root->left); return ConstIterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::TreeReference tamias::RBSTree<KeyType>::findKey( TreeReference vertex, const KeyType &key ) { if (vertex == NULL) return NULL; if (key < vertex->key) return findKey(vertex->left, key); if (vertex->key < key) return findKey(vertex->right, key); return vertex; } template <typename KeyType> tamias::RBSTree<KeyType>::RBSTree() : root(NULL) { } template <typename KeyType> tamias::RBSTree<KeyType>::RBSTree( const RBSTree &tree ) : root(tree.root) { } template <typename KeyType> tamias::RBSTree<KeyType>::~RBSTree() { // !!!TODO!!! : free memory! // printf("---\n"); } template <typename KeyType> tamias::RBSTree<KeyType>& tamias::RBSTree<KeyType>::operator = ( const RBSTree &tree ) { root = tree.root; // TODO: это что за приколы? return *this; } template <typename KeyType> tamias::sizetype tamias::RBSTree<KeyType>::size() const { return root == NULL ? 0 : root->size; } template <typename KeyType> bool tamias::RBSTree<KeyType>::add( const KeyType &key ) { return addKey(root, key); } template <typename KeyType> bool tamias::RBSTree<KeyType>::erase( const KeyType &key ) { TreeReference index = findKey(root, key); if (index == NULL) return false; TreeReference result = merge(index->left, index->right); if (index->parent != NULL) { (index->parent->left == index ? index->parent->left : index->parent->right) = result; result = index->parent; while (result != NULL) recalc(result), result = result->parent; } else if (index == root) { root = result; if (result != NULL) result->parent = NULL; } else { // TODO maybe an assert? } delete index; return true; } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::find( const KeyType& key ) { return findIterator(root, key); } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::find( const KeyType& key ) const { return findIterator(root, key); } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::findKth( sizetype k ) { if (root->size <= k) return Iterator(NULL); // TODO: end-iterator is NOT null-iterator TreeReference vertex = root; while (true) { sizetype cntLeft = vertex->left == NULL ? 0 : vertex->left->size; if (k < cntLeft) vertex = vertex->left; else if (k > cntLeft) vertex = vertex->right, k -= cntLeft + 1; else return Iterator(vertex); } } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::findKth( sizetype k ) const { if (root->size >= k) return ConstIterator(NULL); // TODO: end-iterator is NOT null-iterator TreeReference vertex = root; while (true) { sizetype cntLeft = vertex->left == NULL ? 0 : vertex->left->size; if (k < cntLeft) vertex = vertex->left; else if (k > cntLeft) vertex = vertex->right, k -= cntLeft + 1; else return ConstIterator(vertex); } } template <typename KeyType> tamias::sizetype tamias::RBSTree<KeyType>::count( const KeyType& key ) const { return findIterator(root, key) == ConstIterator(NULL) ? 0 : 1; } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::begin() { return beginIterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::end() { return Iterator(NULL); // TODO ^^ This is wrong. } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::begin() const { return beginIterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::end() const { return ConstIterator(NULL); } template <typename KeyType> void tamias::RBSTree<KeyType>::clear() { // !!!TODO!!! free memory root = NULL; }
agrishutin/teambook
contrib/su4/cpp2tex/include/system/event_poll.h
/* * This file [system/event_poll.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { class EventFd; class EventPoll; } #include <poll.h> // POXIS support for polling #include "../data/pair.h" #include "../data/vector.h" class tamias::EventFd { protected: EventFd(); virtual ~EventFd(); virtual int handle() = 0; private: EventFd( EventFd const &fd ); EventFd& operator = ( EventFd const &fd ); friend class EventPoll; }; class tamias::EventPoll { public: enum EventType { EVENT_IN }; EventPoll(); EventPoll( EventPoll const &poll ); EventPoll& operator = ( EventPoll const &poll ); virtual ~EventPoll(); sizetype addEvent( EventFd &fd, EventType type ); // TODO: support of deleting events. Vector <sizetype> poll(); private: Vector <Pair <int, EventType> > events; };
agrishutin/teambook
contrib/su4/cpp2tex/include/data/queue_implementation.h
<reponame>agrishutin/teambook /* * This file [data/queue_implementation.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ template <typename Type> tamias::Queue<Type>::Queue() : hidden::AbstractData(), mStart(0), mSize(0) { } template <typename Type> tamias::Queue<Type>::Queue( Queue const &queue ) : AbstractData(queue.mSize * sizeof(Type)), mStart(0), mSize(queue.mSize) { for (sizetype i = 0; i < mSize; i++) new ((Type*)data + i) Type(((Type*)queue.data)[i]); } template <typename Type> tamias::Queue<Type>& tamias::Queue<Type>::operator = ( Queue const &queue ) { for (sizetype i = 0; i < mSize; i++) ((Type*)data)[mStart + i].~Type(); mStart = 0; mSize = queue.mSize; manualReserve(mSize * sizeof(Type)); for (sizetype i = 0; i < mSize; i++) new ((Type*)data + i) Type(((Type*)queue.data)[i]); return *this; } template <typename Type> tamias::Queue<Type>::~Queue() { for (sizetype i = 0; i < mSize; i++) ((Type*)data)[mStart + i].~Type(); mSize = mStart = 0; } template <typename Type> tamias::sizetype tamias::Queue<Type>::size() const { return mSize; } template <typename Type> void tamias::Queue<Type>::push( Type const &item ) { autoReserveUp((mStart + mSize + 1) * sizeof(Type)); new ((Type*)data + mStart + mSize) Type(item); mSize++; } template <typename Type> Type tamias::Queue<Type>::pop() { Type result = ((Type*)data)[mStart]; ((Type*)data)[mStart].~Type(); mStart++, mSize--; if (mStart > mSize) { // The magic force of amortized analysis starts here. for (sizetype i = 0; i < mSize; i++) { new ((Type*)data + i) Type(((Type*)data)[mStart + i]); ((Type*)data)[mStart + i].~Type(); } mStart = 0; manualReserve(mSize * sizeof(Type)); } return result; } template <typename Type> Type& tamias::Queue<Type>::front() { return ((Type*)data)[mStart]; } template <typename Type> Type const& tamias::Queue<Type>::front() const { return ((Type*)data)[mStart]; }
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/xml_parser.h
#pragma once namespace tamias { namespace wtf { namespace xml { namespace hidden { class Symbol; class Reader; } class Parser; } } } #include "../basic/string.h" #include "../basic/types.h" //#include "../data/pair.h" //#include "../data/stack.h" //#include "../wtf/xml_element.h" //#include "../wtf/xml_tag.h" class tamias::wtf::xml::hidden::Symbol { public: enum Type { TYPE_NONE, TYPE_ERROR, TYPE_NORMAL, TYPE_FORCED // TYPE_FORCED means that symbol is forced not to be key, likely generated by &entity; }; Symbol( Type type, chartype value ); Symbol( Symbol const &symbol ); Symbol& operator = ( Symbol const & symbol ); ~Symbol(); Type type() const; chartype value() const; private: Type mType; chartype mValue; }; class tamias::wtf::xml::hidden::Reader { public: Reader(); ~Reader(); Symbol add( chartype ch ); void reset(); static bool isAlpha( chartype ch ); private: Reader( Reader const &reader ); Reader& operator = ( Reader const &reader ); enum { STATE_DEFAULT, STATE_ENTITY, STATE_ERROR } mState; String mEntity; Symbol entity(); }; class tamias::wtf::xml::Parser { public: enum ParserEvent { EVENT_NONE, EVENT_ERROR, EVENT_ELEMENT }; Parser(); ~Parser(); ParserEvent append( String const &data ); Element element(); private: Parser( Parser const &parser ); Parser& operator = ( Parser const &parser ); enum StreamState { STATE_DEFAULT, STATE_ERROR, STATE_COMMENT1, STATE_COMMENT2, STATE_COMMENT3 }; hidden::Reader mReader; Stack <Pair<Element, sizetype> > mStack; Stream };
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/arguments.h
<filename>contrib/su4/cpp2tex/include/wtf/arguments.h /* * tamias/wtf/arguments.h — package for parsing commad-line parameters */ #pragma once // TODO: locale support. WTF? #include "../basic/string.h" #include "../basic/types.h" #include "../data/pair.h" #include "../io/file.h" #include "../io/printer.h" #include "../main/map.h" #include "../main/tree_rbst.h" #include "../main/vector.h" namespace tamias { namespace wtf { class ArgumentOption { public: enum ParameterType { PARAMETER_ERROR, PARAMETER_DISABLE, PARAMETER_ENABLE, PARAMETER_BLINK }; public: ArgumentOption( const tamias::String &longName, tamias::chartype shortName, ParameterType parameter, int result); ArgumentOption( const ArgumentOption &option ); ArgumentOption& operator = ( const ArgumentOption &option ); ~ArgumentOption(); private: String mLongName; chartype mShortName; ParameterType mParameter; int mResult; friend class ArgumentParser; }; class ArgumentParser { public: ArgumentParser( int defaultOption = 0 ); ArgumentParser( const ArgumentParser &parser ); ArgumentParser& operator = ( const ArgumentParser &parser ); ~ArgumentParser(); void addOption( const ArgumentOption &option ); tamias::Vector <tamias::Pair <int, tamias::String> > parse( int argc, char **argv ); bool error(); private: int mDefaultOption; tamias::Vector <ArgumentOption> mOptions; bool mError; tamias::Printer out; // +1 to WTF }; } }
agrishutin/teambook
contrib/su4/cpp2tex/include/main/vector.h
/* * This file [main/vector.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_main_vector_h_ #define _libtamias_main_vector_h_ #include <new> #include "../basic/abstract_data.h" #include "../basic/iterator.h" namespace tamias { template <typename Type> class Vector : private hidden::AbstractData { public: typedef Type* Pointer; typedef Type& Reference; typedef const Type* ConstPointer; typedef const Type& ConstReference; typedef hidden::DefaultIterator <Pointer> Iterator; typedef hidden::DefaultIterator <ConstPointer> ConstIterator; typedef hidden::DefaultReverseIterator <Pointer> ReverseIterator; typedef hidden::DefaultReverseIterator <ConstPointer> ConstReverseIterator; private: sizetype vectorSize; public: Vector(); Vector( sizetype initialSize, const Type &value = Type() ); Vector( const Vector <Type> &vector ); ~Vector(); Vector& operator = ( const Vector &vector ); sizetype size() const; const Type& operator [] ( sizetype index ) const; Type& operator [] ( sizetype index ); Iterator begin(); ConstIterator begin() const; Iterator end(); ConstIterator end() const; ReverseIterator rbegin(); ConstReverseIterator rbegin() const; ReverseIterator rend(); ConstReverseIterator rend() const; void clear(); void resize( sizetype newSize ); void pushBack( const Type& ); }; template <typename Type> class VectorCreator { private: Vector <Type> result; public: VectorCreator(); VectorCreator( const Type &value ); VectorCreator( const VectorCreator &creator ); ~VectorCreator(); VectorCreator& operator = ( const VectorCreator &creator ); VectorCreator& operator () ( const Type &value ); VectorCreator& operator << ( const Type &value ); const Vector <Type>& operator () () const; Vector <Type>& operator () (); operator Vector <Type> () const; }; } template <typename Type> tamias::Vector <Type> ::Vector() : tamias::hidden::AbstractData(0), vectorSize(0) { } template <typename Type> tamias::Vector <Type> ::Vector( sizetype initialSize, const Type &value ) : tamias::hidden::AbstractData(initialSize * sizeof(Type)), vectorSize(initialSize) { for (sizetype i = 0; i < initialSize; i++) new ((Type*)data + i) Type(value); } template <typename Type> tamias::Vector <Type> ::Vector( const Vector <Type> &vector ) : tamias::hidden::AbstractData(vector.vectorSize * sizeof(Type)), vectorSize(vector.vectorSize) { for (sizetype i = 0; i < vectorSize; i++) new ((Type*)data + i) Type(((Type*)vector.data)[i]); } template <typename Type> tamias::Vector <Type> ::~Vector() { for (sizetype i = 0; i < vectorSize; i++) ((Type*)data)[i].~Type(); } template <typename Type> tamias::Vector <Type>& tamias::Vector <Type> ::operator = ( const Vector &vector ) { for (sizetype i = 0; i < vectorSize; i++) ((Type*)data)[i].~Type(); vectorSize = vector.vectorSize; manualReserve(vectorSize * sizeof(Type)); for (sizetype i = 0; i < vectorSize; i++) new ((Type*)data + i) Type(((Type*)vector.data)[i]); return *this; } template <typename Type> tamias::sizetype tamias::Vector<Type>::size() const { return vectorSize; } template <typename Type> const Type& tamias::Vector <Type> ::operator [] ( sizetype index ) const { return ((Type*)data)[index]; } template <typename Type> Type& tamias::Vector <Type> ::operator [] ( const sizetype index ) { return ((Type*)data)[index]; } template <typename Type> typename tamias::Vector <Type> ::Iterator tamias::Vector <Type> ::begin() { return Iterator((Type*)data); } template <typename Type> typename tamias::Vector <Type> ::Iterator tamias::Vector <Type> ::end() { return Iterator((Type*)((Type*)data + vectorSize)); } template <typename Type> void tamias::Vector <Type> ::clear() { for (sizetype i = 0; i < vectorSize; i++) ((Type*)data)[i].~Type(); vectorSize = 0; manualReserve(0); } template <typename Type> void tamias::Vector <Type> ::resize( sizetype newSize ) { for (sizetype i = newSize; i < vectorSize; i++) ((Type*)data)[i].~Type(); sizetype oldSize = vectorSize; vectorSize = newSize; manualReserve(vectorSize * sizeof(Type)); for (sizetype i = oldSize; i < vectorSize; i++) new((Type*)data + i) Type(); } template <typename Type> void tamias::Vector <Type> ::pushBack( const Type& source ) { autoReserveUp((vectorSize + 1) * sizeof(Type)); new ((Type*)data + vectorSize) Type(source); vectorSize++; } template <typename Type> tamias::VectorCreator <Type> ::VectorCreator() : result() { } template <typename Type> tamias::VectorCreator <Type> ::VectorCreator( const Type &value ) : result(1, value) { } template <typename Type> tamias::VectorCreator <Type> ::VectorCreator( const VectorCreator &creator ) : result(creator.result) { } template <typename Type> tamias::VectorCreator<Type>::~VectorCreator() { } template <typename Type> tamias::VectorCreator <Type>& tamias::VectorCreator <Type> ::operator = ( const VectorCreator &creator ) { result = creator.result; return *this; } template <typename Type> tamias::VectorCreator <Type>& tamias::VectorCreator <Type> ::operator () ( const Type &value ) { result.pushBack(value); return *this; } template <typename Type> tamias::VectorCreator <Type>& tamias::VectorCreator <Type> ::operator << ( const Type &value ) { result.pushBack(value); return *this; } template <typename Type> const tamias::Vector <Type>& tamias::VectorCreator <Type> ::operator () () const { return result; } template <typename Type> tamias::Vector <Type>& tamias::VectorCreator <Type> ::operator () () { return result; } template <typename Type> tamias::VectorCreator <Type> ::operator tamias::Vector <Type> () const { return result; } #endif // _libtamias_main_vector_h_
agrishutin/teambook
contrib/su4/cpp2tex/include/main/set.h
/* * This file [main/set.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_main_set_h_ #define _libtamias_main_set_h_ #include "../basic/types.h" namespace tamias { template <template <typename Type> class CollectionTemplate, typename Type> class Set { public: typedef typename CollectionTemplate <Type> ::Iterator Iterator; private: CollectionTemplate <Type> collection; public: Set(); Set( const Set <CollectionTemplate, Type> &set ); ~Set(); Set& operator = ( const Set &set ); sizetype size() const; void insert( const Type &value ); void erase( const Type &value ); sizetype count( const Type &value ) const; Iterator begin(); Iterator end(); // TODO: other iterators, methods etc }; } template <template <typename Type> class CollectionTemplate, typename Type> tamias::Set <CollectionTemplate, Type> ::Set() : collection() { } template <template <typename Type> class CollectionTemplate, typename Type> tamias::Set <CollectionTemplate, Type> ::Set( const Set &set ) : collection(set.collection) { } template <template <typename Type> class CollectionTemplate, typename Type> tamias::Set <CollectionTemplate, Type> ::~Set() { } template <template <typename Type> class CollectionTemplate, typename Type> tamias::Set <CollectionTemplate, Type>& tamias::Set <CollectionTemplate, Type> ::operator = ( const Set &set ) { collection = set.collection; return *this; } template <template <typename Type> class CollectionTemplate, typename Type> tamias::sizetype tamias::Set <CollectionTemplate, Type> ::size() const { return collection.size(); } template <template <typename Type> class CollectionTemplate, typename Type> void tamias::Set <CollectionTemplate, Type> ::insert( const Type &value ) { collection.add(value); } template <template <typename Type> class CollectionTemplate, typename Type> void tamias::Set <CollectionTemplate, Type> ::erase( const Type &value ) { collection.erase(value); } template <template <typename Type> class CollectionTemplate, typename Type> tamias::sizetype tamias::Set <CollectionTemplate, Type> ::count( const Type &value ) const { return collection.count(value); } template <template <typename Type> class CollectionTemplate, typename Type> typename tamias::Set <CollectionTemplate, Type> ::Iterator tamias::Set <CollectionTemplate, Type> ::begin() { return collection.begin(); } template <template <typename Type> class CollectionTemplate, typename Type> typename tamias::Set <CollectionTemplate, Type> ::Iterator tamias::Set <CollectionTemplate, Type> ::end() { return collection.end(); } #endif /* _libtamias_main_set_h_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/exception.h
/* * This file [basic/exception.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once #include "../basic/generic_exception.h" #include "../basic/string.h" namespace tamias { /* */ class Exception : public GenericException { public: Exception(); Exception( const Exception &exception ); Exception& operator = ( const Exception &exception ); virtual ~Exception(); const char* message() const; virtual const char* type() const = 0; virtual const String& report() const = 0; }; class CommonException : public Exception { public: CommonException( const String &report ); CommonException( const CommonException &exception ); CommonException& operator = ( const CommonException &exception ); virtual ~CommonException(); virtual const char* type() const; virtual const String& report() const; private: String mReport; }; };
agrishutin/teambook
contrib/su4/cpp2tex/include/basic/date.h
/* * This file [basic/date.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once #include <time.h> #include "../basic/time.h" #include "../basic/types.h" #include "../basic/string.h" namespace tamias { // TODO: leap seconds support, timezone support, etc class Date : public Time { public: Date(); Date( const Date &date ); Date& operator = ( const Date &date ); ~Date(); static Date fromTimestamp( inttype64 timestamp ); static Date now(); static bool isLeapYear( inttype64 year ); // remember: year is calculated from 1970 Time operator - ( const Date &date ) const; Date operator + ( const Time &time ) const; // TODO: operator +=, -, -= with Time Date operator - ( const Time &time ) const; // TODO: format shoud accept all variants that accepts php's data() function — see http://www.php.net/date String format( const String &pattern ) const; private: Date( const Time &time ); }; }
agrishutin/teambook
contrib/su4/cpp2tex/include/main/random_lcg.h
<reponame>agrishutin/teambook<filename>contrib/su4/cpp2tex/include/main/random_lcg.h /* * This file [main/random_lcg.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { class LCGRandom; } #include "../basic/string.h" #include "../basic/types.h" class tamias::LCGRandom { public: LCGRandom( uinttype64 seed = 0 ); ~LCGRandom(); void setSeed( uinttype64 seed ); uinttype32 next(); String nextToken( sizetype length ); // TODO: setup character set private: uinttype64 lcg; LCGRandom( LCGRandom const &random ); LCGRandom& operator = ( LCGRandom const &random ); };
agrishutin/teambook
contrib/su4/cpp2tex/include/data/pair_implementation.h
/* * This file [data/pair_implementation.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ template <typename TypeA, typename TypeB> tamias::Pair<TypeA, TypeB>::Pair() : first(), second() { } template <typename TypeA, typename TypeB> tamias::Pair<TypeA, TypeB>::Pair( TypeA const &newFirst, TypeB const &newSecond ) : first(newFirst), second(newSecond) { } template <typename TypeA, typename TypeB> template <typename newTypeA, typename newTypeB> tamias::Pair<TypeA, TypeB>::Pair( Pair <newTypeA, newTypeB> const &pair ) : first(pair.first), second(pair.second) { } template <typename TypeA, typename TypeB> tamias::Pair <TypeA, TypeB>& tamias::Pair<TypeA, TypeB>::operator = ( Pair <TypeA, TypeB> const &pair ) { first = pair.first; second = pair.second; return *this; } template <typename TypeA, typename TypeB> tamias::Pair<TypeA, TypeB>::~Pair() { } template <typename TypeA, typename TypeB> bool tamias::Pair<TypeA, TypeB>::operator < ( Pair const &pair ) const { if (first < pair.first) return true; if (pair.first < first) return false; return second < pair.second; } template <typename TypeA, typename TypeB> bool tamias::Pair<TypeA, TypeB>::operator <= ( Pair const &pair ) const { if (first < pair.first) return true; if (pair.first < first) return false; return !(pair.second < second); } template <typename TypeA, typename TypeB> bool tamias::Pair<TypeA, TypeB>::operator > ( Pair const &pair ) const { if (first < pair.first) return false; if (pair.first < first) return true; return pair.second < second; } template <typename TypeA, typename TypeB> bool tamias::Pair<TypeA, TypeB>::operator >= ( Pair const &pair ) const { if (first < pair.first) return false; if (pair.first < first) return true; return !(second < pair.second); } template <typename TypeA, typename TypeB> bool tamias::Pair<TypeA, TypeB>::operator == ( Pair const &pair ) const { if (first < pair.first || pair.first < first) return false; if (second < pair.second || pair.second < second) return false; return true; } template <typename TypeA, typename TypeB> bool tamias::Pair<TypeA, TypeB>::operator != ( Pair const &pair ) const { if (first < pair.first || pair.first < first) return true; if (second < pair.second || pair.second < second) return true; return false; } template <typename TypeA, typename TypeB> tamias::Pair <TypeA, TypeB> tamias::makePair( TypeA const &first, TypeB const &second ) { return Pair<TypeA, TypeB>(first, second); }
agrishutin/teambook
contrib/su4/cpp2tex/include/io/iodevice.h
/* * This file [io/iodevice.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_io_iodevice_h_ #define _libtamias_io_iodevice_h_ #include "../basic/byte_array.h" #include "../basic/types.h" namespace tamias { /* abstract class for something that can input and/or output - fs files, sockets, pipes... */ class IODevice { public: IODevice(); IODevice( const IODevice &device ); virtual ~IODevice(); IODevice& operator = ( const IODevice &device ); virtual IODevice* clone() const = 0; virtual bool canRead() const = 0; virtual bool canWrite() const = 0; virtual bool canSeek() const = 0; virtual void close() = 0; virtual bool eof() = 0; virtual bool waitForRead() = 0; virtual ByteArray read( sizetype maxSize = (sizetype)-1 ) = 0; virtual sizetype write( const ByteArray &data ) = 0; virtual void seek( sizetype index ) = 0; // void writeAll( const ByteData &data ); }; } #endif /* _libtamias_io_iodevice_h_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/web_captcha.h
#pragma once #include <cstdlib> #include "../basic/byte_array.h" #include "../basic/exception.h" #include "../basic/string.h" #include "../basic/types.h" #include "../data/pair.h" #include "../main/vector.h" namespace tamias { namespace wtf { namespace web { class Captcha { public: Captcha( const ByteArray &binaryName, const ByteArray &path ); Captcha( const Captcha &captcha ); Captcha& operator = ( const Captcha &captcha ); ~Captcha(); String generate( const String &key ); const String& key() const; const String& value() const; private: ByteArray mBinaryName; ByteArray mPath; String mKey; String mValue; }; } } }
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/terve_entity.h
<reponame>agrishutin/teambook #pragma once #include "../basic/types.h" namespace tamias { namespace wtf { namespace terve { class Entity { public: enum Type { ENTITY_EMPTY, ENTITY_TEXT, ENTITY_I18N, ENTITY_LINE, ENTITY_GROUP }; Entity( Type type = ENTITY_EMPTY, sizetype value = (sizetype)-1 ); Entity( const Entity &entity ); Entity& operator = ( const Entity &entity ); ~Entity(); Type type() const; Entity& setType( Type type ); sizetype value() const; Entity& setValue( sizetype value ); private: Type mType; sizetype mValue; }; } } }
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/web_cookies.h
<reponame>agrishutin/teambook<gh_stars>10-100 #pragma once #include "../basic/date.h" #include "../basic/string.h" #include "../basic/time.h" #include "../basic/types.h" #include "../basic/utilities.h" #include "../io/printer.h" #include "../wtf/web_utilities.h" namespace tamias { namespace wtf { namespace web { /* see rfc2109 for information about cookies */ class Cookie { public: Cookie(); /* I wonder what should do next constructor */ // Cookie( const tamias::String cookie ); Cookie( const String name, const String value ); Cookie( const Cookie &cookie ); Cookie& operator = ( const Cookie &cookie ); ~Cookie(); String name() const; String value() const; void setExpires( const Date &expires ); void setMaxAge( const Time &maxAge ); String output() const; private: String mName, mValue; enum TimeoutType { TIMEOUT_NONE, TIMEOUT_EXPIRES, TIMEOUT_MAXAGE } mTimeoutType; Date mTimeoutExpires; Time mTimeoutMaxAge; }; } } }
agrishutin/teambook
contrib/su4/cpp2tex/include/wtf/utilities.h
/* * libtamias/wtf/utilities.h — some useful functions */ #pragma once #include "../basic/byte_array.h" #include "../basic/string.h" #include "../basic/types.h" #include "../main/vector.h" namespace tamias { namespace wtf { namespace utilities { Vector <String> splitString( const String &source, chartype splitter ); Vector <String> splitString( const String &source, const String &splitter ); String randomString( sizetype length ) __attribute((deprecated)); // use Random.nextToken() instead. LCGRandom is now awailible ByteArray md5Sum( const ByteArray &source ); inttype64 stringToInt( const String &source ); bool isValidInt( String const &source ); String intToString( inttype64 value, sizetype zeros = 0 ) __attribute((deprecated)); // use tamias::Printer::intToString() instead bool isAlphaNum( const String &source ); bool testString( const String &source, const String &pattern ); } } }
agrishutin/teambook
contrib/su4/cpp2tex/include/data/vector.h
/* * This file [data/vector.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { template <typename Type> class Vector; template <typename Type> class VectorCreator; } #include <new> // for constructor invoking #include "../basic/abstract_data.h" #include "../basic/generic_exception.h" #include "../basic/iterator.h" template <typename Type> class tamias::Vector : private hidden::AbstractData { public: typedef Type* Pointer; typedef Type& Reference; typedef Type const* ConstPointer; typedef Type const& ConstReference; typedef hidden::DefaultIterator <Pointer> Iterator; typedef hidden::DefaultConstIterator <Pointer> ConstIterator; typedef hidden::DefaultReverseIterator <Pointer> ReverseIterator; typedef hidden::DefaultConstReverseIterator <Pointer> ConstReverseIterator; public: Vector(); Vector( sizetype initialSize, Type const &value = Type() ); Vector( Vector <Type> const &vector ); Vector& operator = ( Vector const &vector ); ~Vector(); sizetype size() const; Reference operator [] ( sizetype index ); ConstReference operator [] ( sizetype index ) const; Iterator begin(); Iterator end(); ConstIterator begin() const; ConstIterator end() const; ReverseIterator rbegin(); ReverseIterator rend(); ConstReverseIterator rbegin() const; ConstReverseIterator rend() const; void clear(); void resize( sizetype newSize ); void pushBack( Type const &item ); private: sizetype mSize; }; template <typename Type> class tamias::VectorCreator { public: VectorCreator(); VectorCreator( Type const &value ); VectorCreator( VectorCreator const &creator ); VectorCreator& operator = ( VectorCreator const &creator ); ~VectorCreator(); VectorCreator& operator () ( Type const &value ); VectorCreator& operator << ( Type const &value ); operator Vector <Type> () const; private: Vector <Type> result; }; #include "vector_implementation.h"
agrishutin/teambook
contrib/su4/cpp2tex/include/main/algorithm.h
/* * This file [main/algotrithm.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_main_algorithm_h_ #define _libtamias_main_algorithm_h_ #include "../basic/iterator.h" #include "../basic/types.h" namespace tamias { namespace algorithm { /* We are using some modification of qsort algorithm. http://en.wikipedia.org/wiki/Quicksort */ template <typename IteratorType> void sort( IteratorType begin, IteratorType end, int depth = 0 ); } } template <typename IteratorType> void tamias::algorithm::sort( IteratorType begin, IteratorType end, int depth ) { tamias::sizetype size = 0; for (IteratorType it = begin; it != end; it++) size++; if (size <= 1) return; tamias::sizetype middle = size / 2; // TODO: random! IteratorType it = begin; for (sizetype i = 0; i < middle; i++) it++; typename tamias::hidden::IteratorTypes<IteratorType>::ValueType value = *it; IteratorType i = begin, j = begin, k = begin; while (i != end) { if (*i < value) { typename tamias::hidden::IteratorTypes<IteratorType>::ValueType temp = *i; *i = *k, *k = *j; *j = temp; j++, k++; } else if (!(value < *i)) { typename tamias::hidden::IteratorTypes<IteratorType>::ValueType temp = *i; *i = *k; *k = temp; k++; } i++; } sort(begin, j, depth + 1); sort(k, end, depth + 1); } #endif // _libtamias_main_algorithm_h_
agrishutin/teambook
contrib/su4/cpp2tex/include/data/map_implementation.h
/* * This file [data/map_implementation.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ // template MapElement template <typename KeyType, typename ValueType> tamias::hidden::MapElement<KeyType, ValueType>::MapElement() : Pair<KeyType, ValueType>() { } template <typename KeyType, typename ValueType> tamias::hidden::MapElement<KeyType, ValueType>::MapElement( KeyType const &key, ValueType const &value ) : Pair<KeyType, ValueType>(key, value) { } template <typename KeyType, typename ValueType> tamias::hidden::MapElement<KeyType, ValueType>::MapElement( MapElement <KeyType, ValueType> const &element ) : Pair<KeyType, ValueType>(element.first, element.second) { } template <typename KeyType, typename ValueType> tamias::hidden::MapElement<KeyType, ValueType>& tamias::hidden::MapElement<KeyType, ValueType>::operator = ( MapElement <KeyType, ValueType> const &element ) { this->first = element.first; this->second = element.second; return *this; } template <typename KeyType, typename ValueType> tamias::hidden::MapElement<KeyType, ValueType>::~MapElement() { } template <typename KeyType, typename ValueType> bool tamias::hidden::MapElement<KeyType, ValueType>::operator < ( MapElement<KeyType, ValueType> const &element ) const { return this->first < element.first; } // template Map template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::Map<CollectionTemplate, Key, Value>::Map() : collection(), empty() { } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::Map<CollectionTemplate, Key, Value>::Map( Map <CollectionTemplate, Key, Value> const &map ) : collection(map.collection), empty() { } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::Map<CollectionTemplate, Key, Value>& tamias::Map<CollectionTemplate, Key, Value>::operator = ( Map <CollectionTemplate, Key, Value> const &map ) { collection = map.collection; return *this; } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::Map<CollectionTemplate, Key, Value>::~Map() { } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::sizetype tamias::Map<CollectionTemplate, Key, Value>::size() const { return collection.size(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> Value& tamias::Map<CollectionTemplate, Key, Value>::operator [] ( Key const &key ) { tamias::hidden::MapElement<Key, Value> element(key, Value()); if (collection.count(element) == 0) collection.insert(element); tamias::hidden::MapElement<Key, Value> &result = *(collection.find(element)); return result.second; } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> Value const& tamias::Map<CollectionTemplate, Key, Value>::operator [] ( Key const &key ) const { tamias::hidden::MapElement<Key, Value> element(key, Value()); if (collection.count(element) == 0) return empty; tamias::hidden::MapElement<Key, Value> const &result = *(collection.find(element)); return result.second; } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::sizetype tamias::Map<CollectionTemplate, Key, Value>::count( Key const &key ) const { return collection.count(tamias::hidden::MapElement <Key, Value> (key, Value())); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> void tamias::Map<CollectionTemplate, Key, Value>::erase( Key const &key ) { collection.erase(tamias::hidden::MapElement<Key, Value>(key, Value())); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> typename tamias::Map<CollectionTemplate, Key, Value>::Iterator tamias::Map<CollectionTemplate, Key, Value>::begin() { return collection.begin(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> typename tamias::Map<CollectionTemplate, Key, Value>::Iterator tamias::Map<CollectionTemplate, Key, Value>::end() { return collection.end(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> typename tamias::Map<CollectionTemplate, Key, Value>::ConstIterator tamias::Map<CollectionTemplate, Key, Value>::begin() const { return collection.begin(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> typename tamias::Map<CollectionTemplate, Key, Value>::ConstIterator tamias::Map<CollectionTemplate, Key, Value>::end() const { return collection.end(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> void tamias::Map<CollectionTemplate, Key, Value>::clear() { collection.clear(); }
agrishutin/teambook
contrib/su4/cpp2tex/include/data/stack.h
/* * This file [data/stack.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once namespace tamias { template <typename Type> class Stack; } #include <new> #include "../basic/abstract_data.h" #include "../basic/types.h" template <typename Type> class tamias::Stack : private hidden::AbstractData { public: Stack(); Stack( Stack const &stack ); Stack& operator = ( Stack const &stack ); ~Stack(); bool empty() const; sizetype size() const; Type const& top() const; Type& top(); Type const& operator[]( sizetype index ) const; Type& operator[]( sizetype index ); Stack& push( Type const &value ); Type pop(); private: sizetype mSize; }; #include "stack_implementation.h"
agrishutin/teambook
contrib/su4/cpp2tex/include/io/ioexception.h
/* * This file [io/ioexception.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once #include <cstring> // for strerror #include "../basic/exception.h" #include "../basic/string.h" namespace tamias { class IOException : public Exception { public: enum IOExceptionType { ERROR_IO_UNKNOWN, ERROR_IO_ERRNO, ERROR_IO_UNEXPECTED_END_OF_FILE, ERROR_IO_INVALID_OPERATION }; private: IOExceptionType errorType; String errorMessage; public: IOException( const IOExceptionType newType = ERROR_IO_UNKNOWN, const String &message = "" ); IOException( const IOException &exception ); virtual ~IOException(); IOException& operator = ( const IOException &exception ); static IOException fromErrno( int stdErrno ); virtual const char* type() const; virtual const String& report() const; IOExceptionType getType() const; }; }
agrishutin/teambook
contrib/su4/cpp2tex/include/data/stack_implementation.h
<filename>contrib/su4/cpp2tex/include/data/stack_implementation.h<gh_stars>10-100 /* * This file [data/stack.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ template <typename Type> tamias::Stack<Type>::Stack() : AbstractData(), mSize(0) { } template <typename Type> tamias::Stack<Type>::Stack( Stack const &stack ) : AbstractData(stack.mSize * sizeof(Type)), mSize(stack.mSize) { for (sizetype i = 0; i < mSize; i++) new ((Type*)data() + i) Type(*((Type*)stack.data() + i)); } template <typename Type> tamias::Stack<Type>& tamias::Stack<Type>::operator = ( Stack const &stack ) { for (sizetype i = 0; i < mSize; i++) ((Type*)data() + i)->~Type(); mSize = stack.mSize; manualReserve(mSize * sizeof(Type)); for (sizetype i = 0; i < mSize; i++) new ((Type*)data() + i) Type(*((Type*)stack.data() + i)); return *this; } template <typename Type> tamias::Stack<Type>::~Stack() { for (sizetype i = 0; i < mSize; i++) ((Type*)data() + i)->~Type(); mSize = 0; } template <typename Type> bool tamias::Stack<Type>::empty() const { return mSize == 0; } template <typename Type> tamias::sizetype tamias::Stack<Type>::size() const { return mSize; } template <typename Type> Type const& tamias::Stack<Type>::top() const { return (*this)[0]; } template <typename Type> Type& tamias::Stack<Type>::top() { return (*this)[0]; } template <typename Type> Type const& tamias::Stack<Type>::operator[]( sizetype index ) const { utilities::assert<OutOfBoundsException>(index < mSize); return *((Type*)data() + (mSize - 1 - index)); } template <typename Type> Type& tamias::Stack<Type>::operator[]( sizetype index ) { utilities::assert<OutOfBoundsException>(index < mSize); return *((Type*)data() + (mSize - 1 - index)); } template <typename Type> tamias::Stack<Type>& tamias::Stack<Type>::push( Type const &value ) { autoReserveUp((mSize + 1) * sizeof(Type)); new ((Type*)data() + mSize++) Type(value); return *this; } template <typename Type> Type tamias::Stack<Type>::pop() { Type result = top(); ((Type*)data() + --mSize)->~Type(); autoReserve(mSize * sizeof(Type)); return result; }
agrishutin/teambook
contrib/su4/cpp2tex/include/data/tree_rbst_implementation.h
<gh_stars>10-100 /* * This file [data/tree_rbst_implementation.h] is part of the “libtamias” library * Copyright (c) 2007-2010 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ // template RBSTreeNode template <typename KeyType> tamias::hidden::RBSTreeNode<KeyType>::RBSTreeNode( KeyType const &newKey ) : key(newKey), left(NULL), right(NULL), parent(NULL), size(1) { } template <typename KeyType> tamias::hidden::RBSTreeNode<KeyType>::RBSTreeNode( RBSTreeNode const &node ) : key(node.key), left(node.left), right(node.right), parent(node.parent), size(node.size) { } template <typename KeyType> tamias::hidden::RBSTreeNode<KeyType>& tamias::hidden::RBSTreeNode<KeyType>::operator = ( RBSTreeNode<KeyType> const &node ) { key = node.key; left = node.left; right = node.rigth; parent = node.parent; size = node.size; return *this; } template <typename KeyType> tamias::hidden::RBSTreeNode<KeyType>::~RBSTreeNode() { } // template RBSTree template <typename KeyType> tamias::RBSTree<KeyType>::RBSTree() : root(NULL), random() { } template <typename KeyType> tamias::RBSTree<KeyType>::RBSTree( RBSTree <KeyType> const &tree ) : root(NULL), random() { for (ConstIterator it = tree.begin(); it != tree.end(); it++) insert(*it); } template <typename KeyType> tamias::RBSTree<KeyType>& tamias::RBSTree<KeyType>::operator = ( RBSTree <KeyType> const &tree ) { clear(); for (ConstIterator it = tree.begin(); it != tree.end(); it++) insert(*it); return *this; } template <typename KeyType> tamias::RBSTree<KeyType>::~RBSTree() { clear(); } template <typename KeyType> tamias::sizetype tamias::RBSTree<KeyType>::size() const { return root == NULL ? 0 : root->size; } template <typename KeyType> bool tamias::RBSTree<KeyType>::insert( KeyType const &key ) { return addKey(root, key); } template <typename KeyType> bool tamias::RBSTree<KeyType>::erase( KeyType const &key ) { TreeReference index = findKey(root, key); if (index == NULL) return false; TreeReference result = merge(index->left, index->right); if (index->parent != NULL) { (index->parent->left == index ? index->parent->left : index->parent->right) = result; result = result->parent = index->parent; while (result != NULL) recalc(result), result = result->parent; } else if (index == root) { root = result; if (result != NULL) result->parent = NULL; } else throw CommonException("RBSTree: internal error"); delete index; return true; } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::find( KeyType const &key ) { return findIterator(root, key); } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::find( KeyType const &key ) const { return findIterator(root, key); } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::findKth( sizetype k ) { if (root->size <= k) return Iterator(NULL); // TODO: end-iterator is NOT null-iterator. it-- should work TreeReference vertex = root; while (true) { sizetype cntLeft = vertex->left == NULL ? 0 : vertex->left->size; if (k < cntLeft) vertex = vertex->left; else if (k > cntLeft) vertex = vertex->right, k -= cntLeft + 1; else return Iterator(vertex); } } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::findKth( sizetype k ) const { if (root->size >= k) return ConstIterator(NULL); // TODO: end-iterator is NOT null-iterator TreeReference vertex = root; while (true) { sizetype cntLeft = vertex->left == NULL ? 0 : vertex->left->size; if (k < cntLeft) vertex = vertex->left; else if (k > cntLeft) vertex = vertex->right, k -= cntLeft + 1; else return ConstIterator(vertex); } } template <typename KeyType> tamias::sizetype tamias::RBSTree<KeyType>::count( KeyType const &key ) const { return findIterator(root, key) == ConstIterator(NULL) ? 0 : 1; } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::begin() { return beginIterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::end() { return Iterator(NULL); // TODO ^^ This is wrong. } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::begin() const { return beginIterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::end() const { return ConstIterator(NULL); } template <typename KeyType> void tamias::RBSTree<KeyType>::clear() { TreeReference vertex = root, next; while (vertex != NULL) { if (vertex->left != NULL) next = vertex->left, vertex->left = NULL; else if (vertex->right != NULL) next = vertex->right, vertex->right = NULL; else { next = vertex->parent; delete vertex; } vertex = next; } root = NULL; } template <typename KeyType> void tamias::RBSTree<KeyType>::recalc( TreeReference vertex ) { if (vertex == NULL) return; sizetype size = 1; if (vertex->left != NULL) { size += vertex->left->size; vertex->left->parent = vertex; } if (vertex->right != NULL) { size += vertex->right->size; vertex->right->parent = vertex; } vertex->size = size; } template <typename KeyType> typename tamias::RBSTree<KeyType>::TreeReference tamias::RBSTree<KeyType>::merge( TreeReference left, TreeReference right ) { if (left == NULL || right == NULL) return left != NULL ? left : right; if (random.next() % (left->size + right->size) < left->size) { left->right = merge(left->right, right); recalc(left); return left; } else { right->left = merge(left, right->left); recalc(right); return right; } } template <typename KeyType> bool tamias::RBSTree<KeyType>::split( TreeReference vertex, TreeReference &left, TreeReference &right, KeyType const &value ) { if (vertex == NULL) { left = right = NULL; return true; } if (value < vertex->key) { TreeReference tmpLeft, tmpRight; if (!split(vertex->left, tmpLeft, tmpRight, value)) return false; left = tmpLeft; right = vertex; right->left = tmpRight; right->parent = NULL; recalc(right); } else if (vertex->key < value) { TreeReference tmpLeft, tmpRight; if (!split(vertex->right, tmpLeft, tmpRight, value)) return false; left = vertex; right = tmpRight; left->right = tmpLeft; left->parent = NULL; recalc(left); } else return false; return true; } template <typename KeyType> bool tamias::RBSTree<KeyType>::addKey( TreeReference &vertex, KeyType const &key ) { bool result; if (vertex == NULL || random.next() % (vertex->size + 1) == 0u) { TreeReference tmpLeft, tmpRight; if (!split(vertex, tmpLeft, tmpRight, key)) return false; vertex = new hidden::RBSTreeNode<KeyType>(key); vertex->left = tmpLeft; vertex->right = tmpRight; recalc(vertex); result = true; } else { if (key < vertex->key) result = addKey(vertex->left, key); else if (vertex->key < key) result = addKey(vertex->right, key); else result = false; if (result) recalc(vertex); } return result; } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::findIterator( TreeReference root, KeyType const &key ) { while (root != NULL) { if (key < root->key) root = root->left; else if (root->key < key) root = root->right; else break; } return Iterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::Iterator tamias::RBSTree<KeyType>::beginIterator( TreeReference root ) { while (root != NULL && root->left != NULL) root = root->left; return Iterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::findIterator( TreeReference root, KeyType const &key ) const { while (root != NULL) { if (key < root->key) root = root->left; else if (root->key < key) root = root->right; else break; } return ConstIterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::ConstIterator tamias::RBSTree<KeyType>::beginIterator( TreeReference root ) const { while (root != NULL && root->left != NULL) root = root->left; return ConstIterator(root); } template <typename KeyType> typename tamias::RBSTree<KeyType>::TreeReference tamias::RBSTree<KeyType>::findKey( TreeReference vertex, KeyType const &key ) { while (vertex != NULL) { if (key < vertex->key) vertex = vertex->left; else if (vertex->key < key) vertex = vertex->right; else break; } return vertex; } // template RBSTreeIterator template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>::RBSTreeIterator() : mNode(NULL) { } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>::RBSTreeIterator( RBSTreeNode <KeyType> *node ) : mNode(node) { } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>::RBSTreeIterator( RBSTreeIterator const &iterator ) : mNode(iterator.mNode) { } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>& tamias::hidden::RBSTreeIterator<KeyType>::operator = ( RBSTreeIterator const &iterator ) { mNode = iterator.mNode; return *this; } template <typename KeyType> tamias::hidden::RBSTreeIterator<KeyType>::~RBSTreeIterator() { } template <typename KeyType> typename tamias::hidden::RBSTreeIterator<KeyType>::Reference tamias::hidden::RBSTreeIterator<KeyType>::operator * () { // TODO: ? if (node == NULL) throw Exception ? return mNode->key; } template <typename KeyType> typename tamias::hidden::RBSTreeIterator<KeyType>::Pointer tamias::hidden::RBSTreeIterator<KeyType>::operator -> () { return mNode == NULL ? NULL : &(mNode->key); } template <typename KeyType> typename tamias::hidden::RBSTreeIterator<KeyType> tamias::hidden::RBSTreeIterator<KeyType>::operator ++ ( int ) { RBSTreeIterator result(*this); if (mNode == NULL) return result; if (mNode->right != NULL) { mNode = mNode->right; while (mNode->left != NULL) mNode = mNode->left; } else while (mNode != NULL) { RBSTreeNode<KeyType> *oldNode = mNode; mNode = mNode->parent; if (mNode == NULL || mNode->right != oldNode) break; } return result; } template <typename KeyType> bool tamias::hidden::RBSTreeIterator<KeyType>::operator == ( RBSTreeIterator const &iterator ) const { return mNode == iterator.mNode; } template <typename KeyType> bool tamias::hidden::RBSTreeIterator<KeyType>::operator != ( RBSTreeIterator const &iterator ) const { return mNode != iterator.mNode; } // template RBSTreeConstIterator template <typename KeyType> tamias::hidden::RBSTreeConstIterator<KeyType>::RBSTreeConstIterator() : mNode(NULL) { } template <typename KeyType> tamias::hidden::RBSTreeConstIterator<KeyType>::RBSTreeConstIterator ( RBSTreeNode <KeyType> const *node ) : mNode(node) { } template <typename KeyType> tamias::hidden::RBSTreeConstIterator<KeyType>::RBSTreeConstIterator( RBSTreeConstIterator const &iterator ) : mNode(iterator.mNode) { } template <typename KeyType> tamias::hidden::RBSTreeConstIterator<KeyType>& tamias::hidden::RBSTreeConstIterator<KeyType>::operator = ( RBSTreeConstIterator const &iterator ) { mNode = iterator.mNode; return *this; } template <typename KeyType> tamias::hidden::RBSTreeConstIterator<KeyType>::~RBSTreeConstIterator() { } template <typename KeyType> typename tamias::hidden::RBSTreeConstIterator<KeyType>::Reference tamias::hidden::RBSTreeConstIterator<KeyType>::operator * () { // TODO: ? if (node == NULL) throw Exception ? return mNode->key; } template <typename KeyType> typename tamias::hidden::RBSTreeConstIterator<KeyType>::Pointer tamias::hidden::RBSTreeConstIterator<KeyType>::operator -> () { return mNode == NULL ? NULL : &(mNode->key); } template <typename KeyType> typename tamias::hidden::RBSTreeConstIterator<KeyType> tamias::hidden::RBSTreeConstIterator<KeyType>::operator ++ ( int ) { RBSTreeConstIterator result(*this); if (mNode == NULL) return result; if (mNode->right != NULL) { mNode = mNode->right; while (mNode->left != NULL) mNode = mNode->left; } else while (mNode != NULL) { const RBSTreeNode<KeyType> *oldNode = mNode; mNode = mNode->parent; if (mNode == NULL || mNode->right != oldNode) break; } return result; } template <typename KeyType> bool tamias::hidden::RBSTreeConstIterator<KeyType>::operator == ( RBSTreeConstIterator const &iterator ) const { return mNode == iterator.mNode; } template <typename KeyType> bool tamias::hidden::RBSTreeConstIterator<KeyType>::operator != ( RBSTreeConstIterator const &iterator ) const { return mNode != iterator.mNode; }
agrishutin/teambook
contrib/su4/cpp2tex/include/main/map.h
/* * This file [main/map.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #pragma once #include "../basic/types.h" #include "../data/pair.h" namespace tamias { namespace hidden { template <typename KeyType, typename ValueType> class MapElement : public Pair <KeyType, ValueType> { public: MapElement(); MapElement( const KeyType &key, const ValueType &value ); MapElement( const MapElement <KeyType, ValueType> &element ); ~MapElement(); MapElement& operator = ( const MapElement <KeyType, ValueType> &element ); bool operator < ( const MapElement<KeyType, ValueType> &element ) const; }; } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> class Map { public: typedef typename CollectionTemplate <hidden::MapElement <Key, Value> > ::Iterator Iterator; typedef typename CollectionTemplate <hidden::MapElement <Key, Value> > ::ConstIterator ConstIterator; private: CollectionTemplate <hidden::MapElement <Key, Value> > collection; Value empty; public: Map(); Map( const Map <CollectionTemplate, Key, Value> &map ); ~Map(); Map& operator = ( const Map <CollectionTemplate, Key, Value> &map ); const Value& operator [] ( const Key &key ) const; Value& operator [] ( const Key &key ); sizetype count( const Key &key ) const; void erase( const Key &key ); Iterator begin(); Iterator end(); ConstIterator begin() const; ConstIterator end() const; void clear(); }; } template <typename KeyType, typename ValueType> tamias::hidden::MapElement <KeyType, ValueType> ::MapElement() : Pair <KeyType, ValueType> () { } template <typename KeyType, typename ValueType> tamias::hidden::MapElement <KeyType, ValueType> ::MapElement( const KeyType &key, const ValueType &value ) : Pair <KeyType, ValueType> (key, value) { } template <typename KeyType, typename ValueType> tamias::hidden::MapElement <KeyType, ValueType> ::MapElement( const MapElement <KeyType, ValueType> &element ) : Pair <KeyType, ValueType> (element.first, element.second) { } template <typename KeyType, typename ValueType> tamias::hidden::MapElement <KeyType, ValueType> ::~MapElement() { } template <typename KeyType, typename ValueType> tamias::hidden::MapElement <KeyType, ValueType>& tamias::hidden::MapElement <KeyType, ValueType> ::operator = ( const MapElement <KeyType, ValueType> &element ) { this->first = element.first; this->second = element.second; return *this; } template <typename KeyType, typename ValueType> bool tamias::hidden::MapElement<KeyType, ValueType>::operator < ( const MapElement<KeyType, ValueType> &element ) const { return this->first < element.first; } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::Map <CollectionTemplate, Key, Value> ::Map() : collection() { } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::Map <CollectionTemplate, Key, Value> ::Map( const Map <CollectionTemplate, Key, Value> &map ) : collection(map.collection) { } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::Map <CollectionTemplate, Key, Value> ::~Map() { } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::Map <CollectionTemplate, Key, Value>& tamias::Map <CollectionTemplate, Key, Value> ::operator = ( const Map <CollectionTemplate, Key, Value> &map ) { collection = map.collection; return *this; } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> const Value& tamias::Map <CollectionTemplate, Key, Value>::operator [] ( const Key &key ) const { tamias::hidden::MapElement<Key, Value> element(key, Value()); if (collection.count(element) == 0) return empty; const tamias::hidden::MapElement<Key, Value> &result = *(collection.find(element)); return result.second; } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> Value& tamias::Map <CollectionTemplate, Key, Value>::operator [] ( const Key &key ) { tamias::hidden::MapElement<Key, Value> element(key, Value()); if (collection.count(element) == 0) collection.add(element); tamias::hidden::MapElement<Key, Value> &result = *(collection.find(element)); return result.second; } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> tamias::sizetype tamias::Map <CollectionTemplate, Key, Value> ::count( const Key &key ) const { return collection.count(tamias::hidden::MapElement <Key, Value> (key, Value())); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> void tamias::Map <CollectionTemplate, Key, Value> ::erase( const Key &key ) { collection.erase(tamias::hidden::MapElement <Key, Value> (key, Value())); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> typename tamias::Map <CollectionTemplate, Key, Value> ::Iterator tamias::Map <CollectionTemplate, Key, Value> ::begin() { return collection.begin(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> typename tamias::Map <CollectionTemplate, Key, Value> ::Iterator tamias::Map <CollectionTemplate, Key, Value> ::end() { return collection.end(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> typename tamias::Map <CollectionTemplate, Key, Value> ::ConstIterator tamias::Map <CollectionTemplate, Key, Value> ::begin() const { return collection.begin(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> typename tamias::Map <CollectionTemplate, Key, Value> ::ConstIterator tamias::Map <CollectionTemplate, Key, Value> ::end() const { return collection.end(); } template <template <typename Type> class CollectionTemplate, typename Key, typename Value> void tamias::Map <CollectionTemplate, Key, Value> ::clear() { collection.clear(); }
agrishutin/teambook
contrib/su4/cpp2tex/include/main/xml.h
<filename>contrib/su4/cpp2tex/include/main/xml.h /* * This file [main/xml.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_main_xml_h_ #define _libtamias_main_xml_h_ #include "../basic/exception.h" #include "../basic/string.h" #include "../basic/types.h" #include "../io/iodevice.h" #include "../io/printer.h" #include "../io/scanner.h" #include "../main/map.h" #include "../main/tree_rbst.h" #include "../main/vector.h" namespace tamias { class XMLData; class XMLEntity; class XMLParseException : public Exception { public: XMLParseException(); XMLParseException( const XMLParseException &exception ); ~XMLParseException(); XMLParseException& operator=( const XMLParseException &exception ); const char* type() const; const String& report() const; }; class XMLTag // nya? { public: enum TagType { TAG_ERROR, TAG_OPEN, TAG_CLOSE, TAG_EMPTY, TAG_PI, TAG_SPECIAL }; private: String tagName; TagType tagType; Map <RBSTree, String, String> tagParameters; public: XMLTag(); XMLTag( const XMLTag &tag ); ~XMLTag(); XMLTag& operator = ( const XMLTag &tag ); const String& name() const; String& name(); void setName( const String &name ); TagType type() const; TagType& type(); void setType( TagType type ); const Map <RBSTree, String, String>& parameters() const; Map <RBSTree, String, String>& parameters(); void setParameter( const String &parameterName, const String &parameterValue ); void setParameters( const Map <RBSTree, String, String> &parameters ); }; class XMLParser { private: Scanner *scanner; int nextByte; void readByte(); void skipSpace(); bool isNameChar( chartype ch ); String readToken(); public: XMLParser( Scanner &scanner ); XMLParser( const XMLParser &parser ); // [TODO] const? ~XMLParser(); XMLParser& operator = ( const XMLParser &parser ); String getText(); XMLTag nextTag(); }; class XMLEntity { private: String xmlName; Map <RBSTree, String, String> xmlParameters; String xmlText; Vector <XMLEntity> xmlEntities; void entityOutput( Printer &printer, int indentation ); void entityRead( XMLParser &parser, const XMLTag &tag ); public: XMLEntity(); XMLEntity( const XMLEntity &entity ); XMLEntity( const String &newName ); ~XMLEntity(); XMLEntity& operator = ( const XMLEntity &entity ); const String& name() const; const String& getParameter( const String &parameterName ) const; String& getParameter( const String &parameterName ); const Map <RBSTree, String, String>& parameters() const; const String& text() const; const XMLEntity getEntity( sizetype index ) const; const Vector <XMLEntity>& entities() const; String& name(); Map <RBSTree, String, String>& parameters(); String& text(); Vector <XMLEntity>& entities(); void setName( const String &newName ); void setParameter( const String &parameterName, const String &parameterValue ); void setParameters( const Map <RBSTree, String, String> &parameters ); void setText( const String &newText ); void setEntity( sizetype index, const XMLEntity &newEntity ); void addEntity( const XMLEntity &newEntity ); void setEntities( const Vector <XMLEntity> newEntities ); friend class XMLData; }; class XMLData { private: String xmlVersion; String xmlEncoding; XMLEntity xmlRootEntity; public: XMLData(); XMLData( const XMLData &data ); ~XMLData(); XMLData& operator = ( const XMLData &data ); static XMLData read( IODevice &file ); void write( IODevice &file ); const String& version() const; const String& encoding() const; const XMLEntity& rootEntity() const; String& version(); String& encoding(); XMLEntity& rootEntity(); void setVersion( const String &newVersion ); void setEncoding( const String &newEncoding ); void setRootEntity( const XMLEntity &newRootEntity ); }; } #endif /* _libtamias_main_xml_h_ */
agrishutin/teambook
contrib/su4/cpp2tex/include/io/scanner.h
<reponame>agrishutin/teambook<gh_stars>10-100 /* * This file [io/scanner.h] is part of the “libtamias” library * Copyright (c) 2007-2009 <NAME>, <NAME> * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Our contacts: * mailto: <EMAIL> (<NAME>) * mailto: <EMAIL> (<NAME>) */ #ifndef _libtamias_io_scanner_h_ #define _libtamias_io_scanner_h_ #include "../basic/byte_array.h" #include "../io/iodevice.h" namespace tamias { class Scanner { private: IODevice *device; bool bufferUsed; int buffer; void readBuffer(); public: Scanner( const IODevice &device ); Scanner( const Scanner &scanner ); Scanner& operator = ( const Scanner &scanner ); ~Scanner(); void close(); bool eof(); int scanByte(); int nextByte(); void skipSpace(); ByteArray nextToken(); ByteArray nextLine(); }; } #endif /* _libtamias_io_scanner_h_ */